HtmlWebpackPlugin.publicPath resolves incorrectly
jlurena opened this issue ยท 3 comments
Current behaviour ๐ฃ
HtmlWebpackPlugin.publicPath
resolves to ${output.path}/${output.publicPath}
instead of output.publicPath
Expected behaviour โ๏ธ
HtmlWebpackPlugin.publicPath
should resolve to output.publicPath
Reproduction Example ๐พ
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
context: __dirname,
entry: path.resolve(__dirname, './src/index.jsx'),
output: {
path: path.resolve(__dirname, 'public'),
publicPath: '/assets',
filename: 'assets/[contenthash:8].js'
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html'
})
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
};
Above configuration would create index.html
at public/
directory and script paths would be loaded as /assets/assets/123abc.js
Environment ๐ฅ
$ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v12.16.1
darwin 20.3.0
$ npm --version
7.8.0
$ npm ls webpack
jlurena.me@1.0 /Users/jean/Projects/jlurena.me
โโโฌ css-loader@5.2.1
โ โโโ webpack@5.30.0 deduped
โโโ webpack@5.30.0
$ npm ls html-webpack-plugin
jlurena.me@1.0 /Users/jean/Projects/jlurena.me
โโโ html-webpack-plugin@5.3.1
Workaround for above so far is to set HtmlWebpackPlugin.publicPath = '/'
/assets/assets/123abc.js
is the correct path as it uses publicPath
+ filename
/assets/assets/123abc.js
is the correct path as it usespublicPath
+filename
abc123.js
lives in /assets
, not /assets/assets
, so it is still incorrect
In addition, filename is abc123.js
not assets/abc123.js
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.