Skip to content

Commit ecb2d87

Browse files
authored
fix: Resolve src attr value with require.resolve (vuejs#205)
* fix: Add *.vue to include patterns * fix: Resolve src attr values on custom block
1 parent b8db23a commit ecb2d87

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '@vue/component-compiler'
1616
import {Plugin} from 'rollup'
1717
import * as path from 'path'
18-
import {parse, SFCDescriptor} from '@vue/component-compiler-utils'
18+
import {parse, SFCDescriptor, SFCBlock} from '@vue/component-compiler-utils'
1919

2020
const hash = require('hash-sum')
2121

@@ -133,8 +133,13 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
133133
const ref = parseVuePartRequest(id)
134134
if (ref) {
135135
const element = resolveVuePart(descriptors, ref)
136-
if ('src' in element && ref.meta.type !== 'styles') {
137-
return path.resolve(path.dirname(ref.filename), (element as any).src as string)
136+
const src = (element as SFCBlock).src
137+
if (ref.meta.type !== 'styles' && typeof src === 'string') {
138+
if (src.startsWith('.')) {
139+
return path.resolve(path.dirname(ref.filename), src as string)
140+
} else {
141+
return require.resolve(src, { paths: [path.dirname(ref.filename)] })
142+
}
138143
}
139144

140145
return id

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export interface VuePartRequestCreator {
3030
}
3131

3232
export function createVueFilter(
33-
include: string | undefined,
34-
exclude: string | undefined
33+
include: string | string[] = ['*.vue', '**/*.vue'],
34+
exclude: string | string[] = []
3535
): (file: string) => boolean {
36-
const filter = createFilter(include || '**/*.vue', exclude)
36+
const filter = createFilter(include, exclude)
3737

3838
return id => filter(id)
3939
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy