diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 302d21de..51f1a2ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.node-version b/.node-version index a0037765..db24ab96 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -6.11.5 +10.13.0 diff --git a/index.js b/index.js index 79e1c7b9..62f0fda6 100644 --- a/index.js +++ b/index.js @@ -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] @@ -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 @@ -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 diff --git a/lib/child-compiler.js b/lib/child-compiler.js index 63057062..f9189b93 100644 --- a/lib/child-compiler.js +++ b/lib/child-compiler.js @@ -168,8 +168,6 @@ class HtmlWebpackChildCompiler { * @returns Array */ 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, @@ -177,9 +175,7 @@ function extractHelperFilesFromCompilation (mainCompilation, childCompilation, f name: `HtmlWebpackPlugin_${index}` }; - return webpackMajorVersion === 4 - ? mainCompilation.mainTemplate.getAssetPath(filename, entryConfig) - : mainCompilation.getAssetPath(filename, entryConfig); + return mainCompilation.getAssetPath(filename, entryConfig); }); helperAssetNames.forEach((helperFileName) => { diff --git a/package.json b/package.json index 1ed2a030..3afae247 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -61,7 +61,7 @@ "util.promisify": "1.0.0" }, "peerDependencies": { - "webpack": "^4.0.0 || ^5.0.0" + "webpack": "^5.0.0" }, "keywords": [ "webpack", @@ -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": {