Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
greenHandOnWeb opened this issue Mar 13, 2021 · 5 comments
Open

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

greenHandOnWeb opened this issue Mar 13, 2021 · 5 comments

Comments

@greenHandOnWeb
Copy link

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?

@gerhat
Copy link

gerhat commented Apr 6, 2021

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

@gerhat
Copy link

gerhat commented Apr 6, 2021

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: '',
})

@lizehongss
Copy link

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.

  • const publicPath =
    typeof compilation.options.output.publicPath !== 'undefined'
    ? compilation.options.output.publicPath
    : path.relative(path.dirname(filename), '.'); // TODO: How to test this? I haven't written this logic, unsure what it does

@FishOrBear
Copy link

FishOrBear commented Apr 20, 2022

or
webpack config =

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

@SimenB
Copy link
Owner

SimenB commented Apr 23, 2022

PR very much welcome that fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants