1

I got the webpack-dev-server hot reloading feature working with the following webpack.config.js file.

    mode: 'development',
    watch: true,
    entry: path.join(__dirname, 'src/app.js'),
    devServer: {
        contentBase: path.join(__dirname, 'public'),
        hot: true,
        inline: true,
        historyApiFallback: true,
        watchContentBase: true,
        port: 9001
    },
    output: {
        path: path.join(__dirname, 'public'),
        filename: 'bundle.js',
    },

Index.html serves to

 <script src="./bundle.js"></script>

What i am trying to do right now is refactor the directories so that the bundle.js will fall into public/build and index.html will fall into public/dist. So i changed my webpack.config.js as following

    mode: 'development',
    watch: true,
    entry: path.join(__dirname, 'src/app.js'),
    devServer: {
        contentBase: path.join(__dirname, 'public', 'dist'),
        hot: true,
        inline: true,
        historyApiFallback: true,
        watchContentBase: true,
        port: 9001
    },
    output: {
        path: path.join(__dirname, 'public','build'),
        filename: 'bundle.js',
    },

Index.html serves to

 <script src="../build/bundle.js"></script>

But the above config does not work and i get bundle.js config not found. My express server is serving the static path as follows.

const publicPath=path.join(__dirname,'..','public')
console.log('publicpath',publicPath);
app.use(express.static(publicPath))

Any reason why the directory structure fail to work with HMR?

Attached is my directory structure.

Sandbox directory Structure

ryan
  • 694
  • 9
  • 23
  • 2
    Maybe this might help: https://stackoverflow.com/questions/36039146/webpack-dev-server-compiles-files-but-does-not-refresh-or-make-compiled-javascri – Ishita Singh Jan 27 '20 at 10:09
  • @IshitaSingh Thank you. One of the comment in the link provided by you, resolved my issue. – ryan Jan 27 '20 at 10:39

0 Answers0