This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
html-template: Adjust minification settings to match upstream (#1121)
The next release of `html-webpack-plugin` will enable minification by default when `mode` is production, using `minify` options that are based on those used by popular projects: jantimon/html-webpack-plugin#1048 Those changes haven't yet been released, so in the meantime we can emulate them via preset options, so that we can test out the new defaults sooner (ie: in the upcoming alpha/beta), rather than making the breaking change just before Neutrino 9 final. Once a new version of `html-webpack-plugin` is released, we can stop overriding `minify` entirely.
- Loading branch information
Showing
4 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
const { resolve } = require('path'); | ||
|
||
const merge = require('deepmerge'); | ||
|
||
module.exports = (neutrino, { pluginId = 'html', ...options } = {}) => { | ||
neutrino.config | ||
.plugin(pluginId) | ||
.use(require.resolve('html-webpack-plugin'), [ | ||
merge({ | ||
{ | ||
// Use a custom template that has more features (appMountId, lang) than the default: | ||
// https://github.com/jantimon/html-webpack-plugin/blob/master/default_index.ejs | ||
template: resolve(__dirname, 'template.ejs'), | ||
appMountId: 'root', | ||
lang: 'en', | ||
meta: { | ||
viewport: 'width=device-width, initial-scale=1' | ||
viewport: 'width=device-width, initial-scale=1', | ||
...options.meta | ||
}, | ||
minify: { | ||
useShortDoctype: true, | ||
keepClosingSlash: true, | ||
// These are copied from the new html-webpack-plugin defaults: | ||
// https://github.com/jantimon/html-webpack-plugin/pull/1048 | ||
// Passing options.minify will overwrite these defaults entirely | ||
// (intentional for parity with the html-webpack-plugin implementation). | ||
// Remove this once we're using a new release containing that change. | ||
minify: process.env.NODE_ENV === 'production' && { | ||
collapseWhitespace: true, | ||
preserveLineBreaks: true | ||
} | ||
}, options) | ||
removeComments: true, | ||
removeRedundantAttributes: true, | ||
removeScriptTypeAttributes: true, | ||
removeStyleLinkTypeAttributes: true, | ||
useShortDoctype: true | ||
}, | ||
...options | ||
} | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters