@@ -13,49 +13,48 @@ The Idea is to create two bundles, one modern es6+ bundle and one legacy es5 bun
13
13
The Solution is to provide two script tags, one with type=module (es6+ code) and one with "nomodule" (es5 code).
14
14
Modern Browser will now only load the script tag with type=module while legacy browser only load the script tag with "nomodule".
15
15
16
+ ### Why do i need this addon?
17
+ This plugin for html-webpack-plugin generates script tags for module and nomodule for a webpack multi build configuration.
18
+
16
19
### Will some Browser still download both bundles?
17
20
18
- Yeah some Browser like Safari, IE11, Edge are downloading both bundles, but only executing one.
21
+ Yeah some browser like Safari, IE11, Edge are downloading both bundles, but only executing one.
19
22
20
23
We have integrated a clever fix for this.
21
24
22
25
We creating a script tag with module / nomodule and in this script tags we are dynamically adding the script tags for the actual javascript resources.
23
26
24
27
```
25
- <script type="module">
26
- var script = document.createElement('script');
27
- script.type = 'text/javascript';
28
- script.src = 'vendors~app_60d33517957366ff05a8.js';
29
- document.body.appendChild(script);
30
- </script>
28
+ <script type="module">
29
+ var script = document.createElement('script');
30
+ script.type = 'text/javascript';
31
+ script.src = 'vendors~app_60d33517957366ff05a8.js';
32
+ document.body.appendChild(script);
33
+ </script>
31
34
```
32
35
33
- ### Why do i need this addon?
34
- This plugin for html-webpack-plugin (together with its html-template) generates script tags for module and nomodule for a webpack multi build configuration.
35
-
36
- ### Read about webpack Multi Build Configuration
36
+ ### Read about webpack multi build configuration
37
37
https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations
38
38
39
39
### How to use this addon?
40
40
41
- You should only use this addon for multi-builds, not for development. .
41
+ You should only use this addon for multi-builds.
42
42
43
- #### Example Usage:
44
43
```
45
- // package.json
44
+ // PACKAGE.JSON
46
45
"scripts": {
47
46
build:multi": "webpack --env.build=multi"
48
47
}
49
48
50
49
.....
51
-
52
- // legacy webpack config filename need's to include 'legacy'
50
+ // WEBPACK CONFIG
51
+ // Legacy webpack config filename need's to include 'legacy'
53
52
config.output.filename = '[name]_legacy.js';
54
53
55
- // modern webpack config filename
54
+ // Modern webpack config filename should not include 'legacy'
56
55
config.output.filename = '[name].js';
57
56
58
- // both webpack configs (legacy and modern ) should include
57
+ // both webpack configs (Legacy and Modern ) should include htmlWebpackPlugin and htmlWebpackMultiBuildPlugin
59
58
60
59
const htmlWebpackMultiBuildPlugin = require('html-webpack-multi-build-plugin');
61
60
const multiBuildMode = process.env.build === 'multi'
@@ -64,14 +63,9 @@ You should only use this addon for multi-builds, not for development..
64
63
new htmlWebpackPlugin({
65
64
inject: !multiBuildMode,
66
65
template: multiBuildMode ? require.resolve('html-webpack-multi-build-plugin/template.ejs');, // or copy and modify
67
- })
66
+ }),
67
+ new htmlWebpackMultiBuildPlugin()
68
68
]
69
-
70
- if(multiBuildMode) {
71
- base.plugins.push(
72
- new htmlWebpackMultiBuildPlugin()
73
- )
74
- }
75
69
```
76
70
77
71
0 commit comments