@@ -9,44 +9,44 @@ const getRelativePath = (filePath) => {
9
9
return filePath
10
10
}
11
11
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 } `
37
35
}
38
- } )
39
- assetFile . source = ( ) => content
36
+ }
40
37
} )
38
+ assetFile . source = ( ) => content
41
39
} )
42
- }
40
+ } )
41
+ }
43
42
43
+ const emitHandle = ( compilation , callback ) => {
44
44
if ( compilation . entrypoints instanceof Map ) {
45
- compilation . entrypoints . forEach ( ( { chunks} ) => chunksHandle ( chunks ) )
45
+ compilation . entrypoints . forEach ( ( { chunks} ) => chunksHandle ( chunks , compilation ) )
46
46
} else {
47
47
Object . keys ( compilation . entrypoints ) . forEach ( key => {
48
48
const { chunks } = compilation . entrypoints [ key ]
49
- chunksHandle ( chunks )
49
+ chunksHandle ( chunks , compilation )
50
50
} )
51
51
}
52
52
0 commit comments