Skip to content

Commit

Permalink
feat: drop webpack 4 and node <= 10 support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop support for webpack 4 and node <= 10
  • Loading branch information
jantimon committed Jan 20, 2021
1 parent 1e970e6 commit b7a9e8f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['6.x', '12.x', '14.x']
os: [ubuntu-latest, windows-latest]
webpack: ['4']
node: ['10.x', '12.x', '14.x']
os: [ubuntu-latest, windows-latest, macOS-latest]
webpack: ['5']

steps:
- name: LF
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.11.5
10.13.0
18 changes: 5 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const { assert } = require('console');
const fsStatAsync = promisify(fs.stat);
const fsReadFileAsync = promisify(fs.readFile);

const webpackMajorVersion = Number(require('webpack/package.json').version.split('.')[0]);

class HtmlWebpackPlugin {
/**
* @param {HtmlWebpackOptions} [options]
Expand Down Expand Up @@ -164,9 +162,7 @@ class HtmlWebpackPlugin {
hash: templateResult.mainCompilationHash
};

const childCompilationOutputName = webpackMajorVersion === 4
? compilation.mainTemplate.getAssetPath(this.options.filename, compiledEntries)
: compilation.getAssetPath(this.options.filename, compiledEntries);
const childCompilationOutputName = compilation.getAssetPath(this.options.filename, compiledEntries);

// If the child compilation was not executed during a previous main compile run
// it is a cached result
Expand Down Expand Up @@ -543,14 +539,10 @@ class HtmlWebpackPlugin {
* if a path publicPath is set in the current webpack config use it otherwise
* fallback to a relative path
*/
const webpackPublicPath = webpackMajorVersion === 4
? compilation.mainTemplate.getPublicPath({ hash: compilationHash })
: compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilationHash });

const isPublicPathDefined = webpackMajorVersion === 4
? webpackPublicPath.trim() !== ''
// Webpack 5 introduced "auto" - however it can not be retrieved at runtime
: webpackPublicPath.trim() !== '' && webpackPublicPath !== 'auto';
const webpackPublicPath = compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilationHash });

// Webpack 5 introduced "auto" - however it can not be retrieved at compile time
const isPublicPathDefined = webpackPublicPath.trim() !== '' && webpackPublicPath !== 'auto';

let publicPath =
// If the html-webpack-plugin options contain a custom public path uset it
Expand Down
6 changes: 1 addition & 5 deletions lib/child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,14 @@ class HtmlWebpackChildCompiler {
* @returns Array<string>
*/
function extractHelperFilesFromCompilation (mainCompilation, childCompilation, filename, childEntryChunks) {
const webpackMajorVersion = Number(require('webpack/package.json').version.split('.')[0]);

const helperAssetNames = childEntryChunks.map((entryChunk, index) => {
const entryConfig = {
hash: childCompilation.hash,
chunk: entryChunk,
name: `HtmlWebpackPlugin_${index}`
};

return webpackMajorVersion === 4
? mainCompilation.mainTemplate.getAssetPath(filename, entryConfig)
: mainCompilation.getAssetPath(filename, entryConfig);
return mainCompilation.getAssetPath(filename, entryConfig);
});

helperAssetNames.forEach((helperFileName) => {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"standard-version": "5.0.2",
"style-loader": "0.23.1",
"typescript": "3.8.3",
"webpack": "4.35.2",
"webpack": "5.0.0",
"webpack-recompilation-simulator": "3.2.0"
},
"dependencies": {
Expand All @@ -61,7 +61,7 @@
"util.promisify": "1.0.0"
},
"peerDependencies": {
"webpack": "^4.0.0 || ^5.0.0"
"webpack": "^5.0.0"
},
"keywords": [
"webpack",
Expand All @@ -73,7 +73,7 @@
"homepage": "https://github.com/jantimon/html-webpack-plugin",
"repository": "https://github.com/jantimon/html-webpack-plugin.git",
"engines": {
"node": ">=6.9"
"node": ">=10.13.0"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit b7a9e8f

Please sign in to comment.