HtmlWebpackPlugin injects relative path files which breaks when loading non-root website paths

后端 未结 3 1994
無奈伤痛
無奈伤痛 2020-12-02 12:31

I am using webpack and the HtmlWebpackPlugin to inject bundled js and css into an html template file.

new HtmlWebpackPlugin({
   template: \'client/index.tpl         


        
相关标签:
3条回答
  • 2020-12-02 13:07

    In fact, I had to put :

    output.publicPath: './';
    

    in order to have it working in a non-ROOT path. At the same time I was injecting :

       baseUrl: './'
    

    into

    <base href="<%= htmlWebpackPlugin.options.metadata.baseUrl %>">
    

    With both parameter set, it worked like a charm.

    0 讨论(0)
  • 2020-12-02 13:07

    in webpack config

    config.output.publicPath = ''
    

    in your index.html

    <base href="/someurl/" />
    

    this should do it.

    0 讨论(0)
  • 2020-12-02 13:17

    Try setting the publicPath in your webpack config:

    output.publicPath = '/'
    

    HtmlWebpackPlugin use the publicPath to prepend the urls of the injects.

    Another option is to set the base href in the <head> of your html template, to specify the base url of all relative urls in your document.

    <base href="http://localhost:3000/">
    
    0 讨论(0)
提交回复
热议问题