Skip to content

Commit

Permalink
fix: Resolve src attr value with require.resolve (vuejs#205)
Browse files Browse the repository at this point in the history
* fix: Add *.vue to include patterns

* fix: Resolve src attr values on custom block
  • Loading branch information
znck authored May 25, 2018
1 parent b8db23a commit ecb2d87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit ecb2d87

Please sign in to comment.