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

1 Answer 1

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"
  },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.