Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server.watchContentBase doesn't watch all files inside content base

I would appreciate if someone could explain to me why webpack-dev-server doesn't reload browser page on home.html code change, yet reload gets triggered on home.js or index.html code change.

Simplified version of project structure -

/app
  -app.js
  -index.html
  /core
    -home.html
    -home.js (imported in app.js)
  /dist
    -app.bundle.js

webpack.config.js

const path = require('path');

module.exports = {
    entry: './app/app.js',
    output: {
        path: path.resolve(__dirname, './app/dist'),
        filename: 'app.bundle.js'
    },
    devServer: {
        contentBase: path.resolve(__dirname, './app'),
        publicPath: '/dist/',
        watchContentBase: true
    }
}

I'm using [email protected] and [email protected]

like image 385
m aksem Avatar asked May 03 '26 14:05

m aksem


1 Answers

You was pretty close, just add to contentBase every folder that contains .html files:

devServer: {
  contentBase: [
    path.join(__dirname, 'app'),
    path.join(__dirname, 'app/core'),
    // and so on...
  ],
}
like image 68
pldg Avatar answered May 06 '26 03:05

pldg