@@ -2,6 +2,13 @@ const path = require('path')
2
2
const upath = require ( 'upath' )
3
3
const relative = require ( 'relative' )
4
4
5
+ const getRelativePath = ( filePath ) => {
6
+ if ( ! / ^ \. ( \. ) ? \/ / . test ( filePath ) ) {
7
+ filePath = `./${ filePath } `
8
+ }
9
+ return filePath
10
+ }
11
+
5
12
const emitHandle = ( compilation , callback ) => {
6
13
Object . keys ( compilation . entrypoints ) . forEach ( key => {
7
14
const { chunks } = compilation . entrypoints [ key ]
@@ -16,13 +23,15 @@ const emitHandle = (compilation, callback) => {
16
23
chunk . files . forEach ( subFile => {
17
24
if ( path . extname ( subFile ) === extname && assetFile ) {
18
25
let relativePath = upath . normalize ( relative ( filePath , subFile ) )
26
+
19
27
// 百度小程序 js 引用不支持绝对路径,改为相对路径
20
- if ( extname === '.js' && ! / ^ \. ( \. ) ? \/ / . test ( relativePath ) ) {
21
- relativePath = `./ ${ relativePath } `
28
+ if ( extname === '.js' ) {
29
+ relativePath = getRelativePath ( relativePath )
22
30
}
23
31
24
32
if ( / ^ ( \. w x s s ) | ( \. t t s s ) | ( \. a c s s ) | ( \. c s s ) $ / . test ( extname ) ) {
25
- content = `@import "${ relativePath } "\n${ content } `
33
+ relativePath = getRelativePath ( relativePath )
34
+ content = `@import "${ relativePath } ";\n${ content } `
26
35
} else {
27
36
content = `require("${ relativePath } ")\n${ content } `
28
37
}
0 commit comments