@@ -9,44 +9,44 @@ const getRelativePath = (filePath) => {
99 return filePath
1010}
1111
12- const emitHandle = ( compilation , callback ) => {
13- function chunksHandle ( chunks ) {
14- const entryChunk = chunks . pop ( )
15-
16- entryChunk . files . forEach ( filePath => {
17- const assetFile = compilation . assets [ filePath ]
18- const extname = path . extname ( filePath )
19- let content = assetFile . source ( )
20-
21- chunks . reverse ( ) . forEach ( chunk => {
22- chunk . files . forEach ( subFile => {
23- if ( path . extname ( subFile ) === extname && assetFile ) {
24- let relativePath = upath . normalize ( relative ( filePath , subFile ) )
25-
26- // 百度小程序 js 引用不支持绝对路径,改为相对路径
27- if ( extname === '.js' ) {
28- relativePath = getRelativePath ( relativePath )
29- }
30-
31- if ( / ^ ( \. w x s s ) | ( \. t t s s ) | ( \. a c s s ) | ( \. c s s ) $ / . test ( extname ) ) {
32- relativePath = getRelativePath ( relativePath )
33- content = `@import "${ relativePath } ";\n${ content } `
34- } else if ( ! ( / ^ \. m a p $ / . test ( extname ) ) ) {
35- content = `require("${ relativePath } ")\n${ content } `
36- }
12+ const chunksHandle = ( chunks , compilation ) => {
13+ const entryChunk = chunks . pop ( )
14+
15+ entryChunk . files . forEach ( filePath => {
16+ const assetFile = compilation . assets [ filePath ]
17+ const extname = path . extname ( filePath )
18+ let content = assetFile . source ( )
19+
20+ chunks . reverse ( ) . forEach ( chunk => {
21+ chunk . files . forEach ( subFile => {
22+ if ( path . extname ( subFile ) === extname && assetFile ) {
23+ let relativePath = upath . normalize ( relative ( filePath , subFile ) )
24+
25+ // 百度小程序 js 引用不支持绝对路径,改为相对路径
26+ if ( extname === '.js' ) {
27+ relativePath = getRelativePath ( relativePath )
28+ }
29+
30+ if ( / ^ ( \. w x s s ) | ( \. t t s s ) | ( \. a c s s ) | ( \. c s s ) $ / . test ( extname ) ) {
31+ relativePath = getRelativePath ( relativePath )
32+ content = `@import "${ relativePath } ";\n${ content } `
33+ } else if ( ! ( / ^ \. m a p $ / . test ( extname ) ) ) {
34+ content = `require("${ relativePath } ")\n${ content } `
3735 }
38- } )
39- assetFile . source = ( ) => content
36+ }
4037 } )
38+ assetFile . source = ( ) => content
4139 } )
42- }
40+ } )
41+ }
4342
43+ const emitHandle = ( compilation , callback ) => {
4444 if ( compilation . entrypoints instanceof Map ) {
45- compilation . entrypoints . forEach ( ( { chunks} ) => chunksHandle ( chunks ) )
45+ compilation . entrypoints . forEach ( ( { chunks} ) => chunksHandle ( chunks , compilation ) )
4646 } else {
4747 Object . keys ( compilation . entrypoints ) . forEach ( key => {
4848 const { chunks } = compilation . entrypoints [ key ]
49- chunksHandle ( chunks )
49+ chunksHandle ( chunks , compilation )
5050 } )
5151 }
5252
0 commit comments