kkemple / kkemple/primus-webpack-plugin

publicPath is ignored when using with html-webpack-plugin

Open
#6 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
6
Forks
9
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/newyork-anthonyng/primus-webpack-plugin-bug-demo).

```js
// 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:
```html



Webpack App


```

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](https://github.com/kkemple/primus-webpack-plugin/blob/master/index.js#L59-L61).

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in index.js at lines 59-61, where the Primus client filename is declared, and inspect the webpack compilation output options used there. Use the provided webpack.config.js and demo to verify the generated HTML, and consider the issue's suggested publicPath behavior done when primus-client.js is emitted with the configured static/ prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.