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

Commit 0e8e005

Browse files
authored
fix: Resolve src values on style blocks with require.resolve (#70)
1 parent 26bda04 commit 0e8e005

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/compiler.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ export class SFCCompiler {
6464
script: ScriptOptions
6565
style: StyleOptions
6666
template: TemplateOptions
67+
resolve: RequireResolve
6768

6869
constructor(
6970
script: ScriptOptions,
7071
style: StyleOptions,
71-
template: TemplateOptions
72+
template: TemplateOptions,
73+
resolve: RequireResolve = require.resolve
7274
) {
7375
this.template = template
7476
this.style = style
7577
this.script = script
78+
this.resolve = resolve
7679
}
7780

7881
compileToDescriptor(
@@ -193,8 +196,20 @@ export class SFCCompiler {
193196
}
194197

195198
private read(filename: string, context: string): string {
196-
return fs
197-
.readFileSync(path.resolve(path.dirname(context), filename))
198-
.toString()
199+
try {
200+
return fs
201+
.readFileSync(
202+
filename.startsWith('.')
203+
? path.resolve(path.dirname(context), filename)
204+
: this.resolve(filename, { paths: [path.dirname(context)] })
205+
)
206+
.toString()
207+
} catch (e) {
208+
if (/cannot find module/i.test(e.message)) {
209+
throw Error(`Cannot find '${filename}' in '${context}'`)
210+
}
211+
212+
throw e
213+
}
199214
}
200215
}

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