Permalink
Browse files

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

* fix: Add *.vue to include patterns

* fix: Resolve src attr values on custom block
  • Loading branch information...
znck committed May 25, 2018
1 parent b8db23a commit ecb2d874df274e7bb143937a9429723820f50cac
Showing with 11 additions and 6 deletions.
  1. +8 −3 src/index.ts
  2. +3 −3 src/utils.ts
@@ -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')

@@ -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
@@ -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)
}

0 comments on commit ecb2d87

Please sign in to comment.