Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

fix: Resolve src attr value with require.resolve #205

Merged
merged 2 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vue/component-compiler'
import {Plugin} from 'rollup'
import * as path from 'path'
import {parse, SFCDescriptor} from '@vue/component-compiler-utils'
import {parse, SFCDescriptor, SFCBlock} from '@vue/component-compiler-utils'

const hash = require('hash-sum')

Expand Down Expand Up @@ -133,8 +133,13 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
const ref = parseVuePartRequest(id)
if (ref) {
const element = resolveVuePart(descriptors, ref)
if ('src' in element && ref.meta.type !== 'styles') {
return path.resolve(path.dirname(ref.filename), (element as any).src as string)
const src = (element as SFCBlock).src
if (ref.meta.type !== 'styles' && typeof src === 'string') {
if (src.startsWith('.')) {
return path.resolve(path.dirname(ref.filename), src as string)
} else {
return require.resolve(src, { paths: [path.dirname(ref.filename)] })
}
}

return id
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export interface VuePartRequestCreator {
}

export function createVueFilter(
include: string | undefined,
exclude: string | undefined
include: string | string[] = ['*.vue', '**/*.vue'],
exclude: string | string[] = []
): (file: string) => boolean {
const filter = createFilter(include || '**/*.vue', exclude)
const filter = createFilter(include, exclude)

return id => filter(id)
}
Expand Down