Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit 615197d

Browse files
feat(Readme): create readme
1 parent a6fcb2c commit 615197d

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

‎README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
11
# html-webpack-multi-build-plugin
22

3-
tbd
3+
This plugin simplifies the creation of HTML files for multi build configuration.
4+
5+
### Why do you want to do this?
6+
7+
Most developers still transpile their code to ES5 and bundle it with polyfills to provide support for older browsers.
8+
But for newer browsers this transpiled code is unnecessary and probably slower then ES6+ code.
9+
The Idea is to create two bundles, one modern es6+ bundle and one legacy es6 bundle.
10+
The Solution is to provide two script tags, one with type=module (es6+ code) and one with "nomodule" (es5 code).
11+
Modern Browser will now only load the script tag with type=module while legacy browser only load the script tag with "nomodule".
12+
13+
### Why do i need this addon?
14+
This plugin for html-webpack-plugin (together with its html-template) generates script tags for module and nomodule for a webpack multi build configuration.
15+
16+
### Read about webpack Multi Build Configuration
17+
https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations
18+
19+
### How to use this addon?
20+
21+
You should only use this addon for multi-builds, not for development..
22+
23+
24+
example usage:
25+
```
26+
"scripts": {
27+
build:multi": "webpack --env.build=multi"
28+
}
29+
30+
.....
31+
32+
const htmlWebpackMultiBuildPlugin = require('html-webpack-multi-build-plugin');
33+
const multiBuildMode = process.env.build === 'multi'
34+
35+
base.plugins: [
36+
new htmlWebpackPlugin({
37+
inject: !multiBuildMode,
38+
template: multiBuildMode ? require.resolve('html-webpack-multi-build-plugin/template.ejs');, // or copy and modify
39+
})
40+
]
41+
42+
if(multiBuildMode) {
43+
base.plugins.push(
44+
new htmlWebpackMultiBuildPlugin()
45+
)
46+
}
47+
```
48+
49+
50+
### Sources
51+
https://github.com/jantimon/html-webpack-plugin/issues/782
52+
https://philipwalton.com/articles/deploying-es2015-code-in-production-today/
53+
https://github.com/philipwalton/webpack-esnext-boilerplate
54+
https://jakearchibald.com/2017/es-modules-in-browsers/

‎template.ejs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,13 @@
77
<meta<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %>>
88
<% } %>
99
<% } %>
10-
<style>
11-
#overlay {
12-
position: fixed;
13-
width: 100%;
14-
height: 100%;
15-
top: 0;
16-
left: 0;
17-
right: 0;
18-
bottom: 0;
19-
z-index: 2;
20-
background-color: white;
21-
}
22-
.loader {
23-
position: absolute;
24-
left: 45%;
25-
top: 35%;
26-
border: 16px solid #f3f3f3;
27-
border-top: 16px solid black;
28-
border-radius: 50%;
29-
width: 120px;
30-
height: 120px;
31-
animation: spin 2s linear infinite;
32-
}
33-
34-
@keyframes spin {
35-
0% { transform: rotate(0deg); }
36-
100% { transform: rotate(360deg); }
37-
}
38-
</style>
3910
<% for (key in htmlWebpackPlugin.files.css) { %>
4011
<link href="<%= htmlWebpackPlugin.files.css[key] %>" rel="stylesheet" media="nope!" onload="this.media='all'">
4112
<% } %>
4213
</head>
4314
<body>
4415

45-
<% if (htmlWebpackPlugin.options.appMountId) { %>
46-
<div id="<%= htmlWebpackPlugin.options.appMountId %>">
47-
<div id="overlay">
48-
<div id="spinner" class="loader"></div>
49-
</div>
50-
</div>
51-
<% } %>
16+
<div id="root"></div>
5217

5318
<script type="module">
5419
<% for (key in htmlWebpackPlugin.options.modernScripts) { %>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /