kkemple/primus-webpack-plugin

publicPath is ignored when using with html-webpack-plugin

Opened this issue · 0 comments

Thank you for this project!

The problem

When using a output.publicPath in your webpack configurations, it is not used when inserting the primus generated file into the generated HTML file from html-webpack-plugin. See demo here.

// webpack.config.js
module.exports = {
  entry: "./app.js",

  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
    publicPath: "static/"
  },

  plugins: [
    new PrimusWebpackPlugin(),
    new HTMLPlugin()
  ]
};

And the HTML file looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
  <script type="text/javascript" src="/primus-client.js"></script><script type="text/javascript" src="static/bundle.js"></script></body>
</html>

Notice how static is not prepended to the path for primus-client.js.

The fix

A possible fix is to get the public path from compilation.outputOptions.publicPath, and prepend it to the filename that we are declaring here.

Let me know if this makes sense; I can create a Pull Request for this.