0

Using the Html-webpack-plugin if I go to the root directory localhost:8080 it injects the javascript as expected If I go localhost:8080/test the html renders but no js gets injected

server.js

app.use('/', express.static(__dirname + '/dist'));

app.get('*', (req, res)=> {
    res.sendFile(__dirname + '/dist/index.html');
});

webpack.config.js

entry: [
        "webpack-hot-middleware/client?reload=true",
        "babel-polyfill",
        path.resolve(__dirname, './config/app/app.js')
    ],
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'app.min.js',
        publicPath: '/'
    },
    plugins: isDeveloping ? [
        new HtmlWebpackPlugin({
            hash: true,
            filename: 'index.html',
            template: __dirname + '/dist/index.html',
            inject: 'body'
        })

I found a similar question to this one and their solution was to configure output.publicPath = '/' which I did but still no luck. I just get the template with no JS injected

Paul Brunache
  • 605
  • 11
  • 21

1 Answers1

0

Turns out I was running webpack-dev-server and that does not inject to the file system. I added this snippet to my webpack and problem solved

"scripts": {
    "start": "npm run build",
    "build": "webpack -p && webpack-dev-server"
  },
Paul Brunache
  • 605
  • 11
  • 21