add-asset-html-webpack-plugin icon indicating copy to clipboard operation
add-asset-html-webpack-plugin copied to clipboard

the src of script is wrong with html-webpack-plugin v5.3.1

Open greenHandOnWeb opened this issue 3 years ago • 5 comments

1.the config: plugins:[ new HtmlWebpackPlugin({ template: './src/index.html' }), new webpack.DllReferencePlugin({ manifest: resolve(__dirname, 'dll/manifest.json') }), new AddAssetHtmlWebpackPlugin({ filepath: require.resolve("./dll/jquery.js") }) ] 2.run 'webpack' success 3.but the inserted script label is wrong

inserted script <script defer="defer" src="auto/jquery.js"></script>

the src should be 'jquery.js' rather than 'auto/jquery.js'

4.It's may a bug, would you mind give some advice?

greenHandOnWeb avatar Mar 13 '21 14:03 greenHandOnWeb

@greenHandOnWeb I have this issue too. Did you find a workaround?

gerhat avatar Apr 06 '21 13:04 gerhat

I found a solution. We need to use the publicPath option with empty string. My config now is:

new AddAssetHtmlPlugin({
  filepath: path.resolve(__dirname, '../public/properties.js'),
  includeRelatedFiles: false,
  publicPath: '',
})

gerhat avatar Apr 06 '21 14:04 gerhat

I think it's because util.js use compilation.options.output.publicPath, if not set it, it will be 'auto', I not sure it's bug or not.

  • https://github.com/SimenB/add-asset-html-webpack-plugin/blob/ca2fb7743ad5e3d4ab8092e19e28a40bad2fe3d4/src/utils.js#L16-L19

lizehongss avatar Apr 07 '21 11:04 lizehongss

or webpack config =

    {
        mode: "development",
        output: {
            publicPath: "", //add this line

FishOrBear avatar Apr 20 '22 14:04 FishOrBear

PR very much welcome that fixes this

SimenB avatar Apr 23 '22 09:04 SimenB