Commit 3356743 1 parent 1555c98 commit 3356743 Copy full SHA for 3356743
File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,17 @@ class Esbuild {
34
34
config . plugins = [ NodeModulesPolyfillPlugin ( ) , ...config . plugins ] ;
35
35
}
36
36
37
+ // inject content in worker initial code.
38
+ if ( this . builderConfig . contentToInject ) {
39
+ const workerInitContent = this . builderConfig . contentToInject ;
40
+
41
+ if ( config . banner ?. js ) {
42
+ config . banner . js = `${ config . banner . js } ${ workerInitContent } ` ;
43
+ } else {
44
+ config . banner = { js : workerInitContent } ;
45
+ }
46
+ }
47
+
37
48
try {
38
49
await esbuild . build ( config ) ;
39
50
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -30,6 +30,36 @@ class Webpack {
30
30
config = merge ( this . customConfig , config ) ;
31
31
}
32
32
33
+ // inject content in worker initial code.
34
+ if ( this . builderConfig . contentToInject ) {
35
+ const workerInitContent = this . builderConfig . contentToInject ;
36
+
37
+ const bannerPluginIndex = config . plugins . findIndex (
38
+ ( plugin ) => plugin instanceof webpack . BannerPlugin ,
39
+ ) ;
40
+
41
+ if ( bannerPluginIndex !== - 1 ) {
42
+ const oldContent = config . plugins [ bannerPluginIndex ] . options . banner ;
43
+ const pluginToRemove = config . plugins [ bannerPluginIndex ] ;
44
+ config . plugins = config . plugins . filter (
45
+ ( plugin ) => plugin !== pluginToRemove ,
46
+ ) ;
47
+ config . plugins . push (
48
+ new webpack . BannerPlugin ( {
49
+ banner : `${ oldContent } ${ workerInitContent } ` ,
50
+ raw : true ,
51
+ } ) ,
52
+ ) ;
53
+ } else {
54
+ config . plugins . push (
55
+ new webpack . BannerPlugin ( {
56
+ banner : workerInitContent ,
57
+ raw : true ,
58
+ } ) ,
59
+ ) ;
60
+ }
61
+ }
62
+
33
63
try {
34
64
const stats = await runWebpack ( config ) ;
35
65
You can’t perform that action at this time.
0 commit comments