@@ -2,6 +2,13 @@ const path = require('path')
22const upath = require ( 'upath' )
33const relative = require ( 'relative' )
44
5+ const getRelativePath = ( filePath ) => {
6+ if ( ! / ^ \. ( \. ) ? \/ / . test ( filePath ) ) {
7+ filePath = `./${ filePath } `
8+ }
9+ return filePath
10+ }
11+
512const emitHandle = ( compilation , callback ) => {
613 Object . keys ( compilation . entrypoints ) . forEach ( key => {
714 const { chunks } = compilation . entrypoints [ key ]
@@ -16,13 +23,15 @@ const emitHandle = (compilation, callback) => {
1623 chunk . files . forEach ( subFile => {
1724 if ( path . extname ( subFile ) === extname && assetFile ) {
1825 let relativePath = upath . normalize ( relative ( filePath , subFile ) )
26+
1927 // 百度小程序 js 引用不支持绝对路径,改为相对路径
20- if ( extname === '.js' && ! / ^ \. ( \. ) ? \/ / . test ( relativePath ) ) {
21- relativePath = `./ ${ relativePath } `
28+ if ( extname === '.js' ) {
29+ relativePath = getRelativePath ( relativePath )
2230 }
2331
2432 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 } `
2635 } else {
2736 content = `require("${ relativePath } ")\n${ content } `
2837 }
0 commit comments