Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 3163aad

Browse files
committed
Update dependencies
Update inlineRuntimePlugin to use the new html-webpack-plugin v4 hooks API
1 parent 33f0eab commit 3163aad

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

CHANGES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Unreleased (in `master`)
2+
3+
## Changed
4+
5+
- [html-webpack-plugin got a major version bump to v4](https://dev.to/jantimon/html-webpack-plugin-4-has-been-released-125d)
6+
- Output HTML is now minified by default - you can disable this by configuring `html.minification = false`.
7+
- Chunk sorting was removed, but it seems to work as before for the ordering of the JavaScript files generated by nwb's build.
8+
- The plugin nwb uses to inline the webpack runtime chunk was rewritten to use v4's new hooks.
9+
10+
## Dependencies
11+
12+
- @babel/plugin-transform-react-jsx: v7.9.1 → [v7.9.4](https://github.com/babel/babel/releases/tag/v7.9.4)
13+
- @babel/preset-react: v7.9.1 → [v7.9.4](https://github.com/babel/babel/releases/tag/v7.9.4)
14+
- @babel/runtime: v7.9.0 → v7.9.2
15+
- autoprefixer: v9.7.4 → [v9.7.5](https://github.com/postcss/autoprefixer/blob/master/CHANGELOG.md#975)
16+
- html-webpack-plugin: v3.2.0 → [v4.0.1](https://github.com/jantimon/html-webpack-plugin/blob/master/CHANGELOG.md#401-2020-03-23)
17+
- webpack: v4.42.0 → [v4.42.1](https://github.com/webpack/webpack/releases/tag/v4.42.1)
18+
119
# 0.24.4 / 2020-03-21
220

321
## Added

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
"@babel/plugin-syntax-dynamic-import": "7.8.3",
5252
"@babel/plugin-syntax-jsx": "7.8.3",
5353
"@babel/plugin-transform-react-constant-elements": "7.9.0",
54-
"@babel/plugin-transform-react-jsx": "7.9.1",
54+
"@babel/plugin-transform-react-jsx": "7.9.4",
5555
"@babel/plugin-transform-runtime": "7.9.0",
5656
"@babel/polyfill": "7.8.7",
5757
"@babel/preset-env": "7.9.0",
58-
"@babel/preset-react": "7.9.1",
59-
"@babel/runtime": "7.9.0",
58+
"@babel/preset-react": "7.9.4",
59+
"@babel/runtime": "7.9.2",
6060
"@pmmmwh/react-refresh-webpack-plugin": "0.2.0",
6161
"babel-plugin-add-module-exports": "1.0.2",
6262
"babel-plugin-inferno": "6.1.0",
@@ -84,15 +84,15 @@
8484
"promise": "8.1.0",
8585
"whatwg-fetch": "3.0.0",
8686

87-
"webpack": "4.42.0",
88-
"autoprefixer": "9.7.4",
87+
"webpack": "4.42.1",
88+
"autoprefixer": "9.7.5",
8989
"babel-loader": "8.1.0",
9090
"case-sensitive-paths-webpack-plugin": "2.3.0",
9191
"copy-webpack-plugin": "5.1.1",
9292
"css-loader": "3.4.2",
9393
"eventsource-polyfill": "0.9.6",
9494
"file-loader": "4.3.0",
95-
"html-webpack-plugin": "3.2.0",
95+
"html-webpack-plugin": "4.0.1",
9696
"mini-css-extract-plugin": "0.9.0",
9797
"@insin/npm-install-webpack-plugin": "5.0.0",
9898
"optimize-css-assets-webpack-plugin": "5.0.3",

src/createWebpackConfig.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -409,25 +409,18 @@ export function createExtraRules(
409409

410410
/**
411411
* Plugin for HtmlPlugin which inlines the Webpack runtime code and chunk
412-
* manifest into the HTML in a <script> tag before other emitted asssets are
413-
* injected by HtmlPlugin itself.
412+
* manifest into its <script> tag.
414413
*/
415414
function inlineRuntimePlugin() {
416415
this.hooks.compilation.tap('inlineRuntimePlugin', compilation => {
417-
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync('inlineRuntimePlugin', (data, cb) => {
418-
Object.keys(compilation.assets).forEach(key => {
419-
if (!/^runtime\.[a-z\d]+\.js$/.test(key)) return
420-
let {children} = compilation.assets[key]
416+
HtmlPlugin.getHooks(compilation).alterAssetTags.tapAsync('inlineRuntimePlugin', (data, cb) => {
417+
Object.keys(compilation.assets).forEach(assetName => {
418+
if (!/^runtime\.[a-z\d]+\.js$/.test(assetName)) return
419+
let {children} = compilation.assets[assetName]
421420
if (children && children[0]) {
422-
data.html = data.html.replace(
423-
/^(\s*)<\/body>/m,
424-
`$1<script>${children[0]._value}</script>\n$1</body>`
425-
)
426-
// Remove the runtime from HtmlPlugin's assets to prevent a <script>
427-
// tag being created for it.
428-
var runtimeIndex = data.assets.js.indexOf(data.assets.publicPath + key)
429-
data.assets.js.splice(runtimeIndex, 1)
430-
delete data.assets.chunks.runtime
421+
let tag = data.assetTags.scripts.find(tag => tag.attributes.src.endsWith(assetName))
422+
delete tag.attributes.src
423+
tag.innerHTML = children[0]._value
431424
}
432425
})
433426
cb(null, data)
@@ -557,7 +550,6 @@ export function createPlugins(
557550
// Generate an HTML file for web apps which pulls in generated resources
558551
if (buildConfig.html) {
559552
plugins.push(new HtmlPlugin({
560-
chunksSortMode: 'dependency',
561553
template: path.join(__dirname, '../templates/webpack-template.html'),
562554
...buildConfig.html,
563555
...userConfig.html,

0 commit comments

Comments
 (0)