Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server does not watch on the new files created

I would like webpack to detect new changes for freshly created files.

My complete webpack.config.js file

module.exports = {
  entry: './src/client/js/index.js',

  output: {
    path: 'public',
    filename: 'bundle.js',
    publicPath: '/'
  },

  resolve: {
    extensions: ['', '.js', '.jsx']
  },

  plugins: process.env.NODE_ENV === 'production' ? [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin()
  ] : [],

  module: {
    loaders: [
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' },
      { test: /\.scss$/, loaders: ['style', 'css', 'sass']}
    ]
  },

}

I have googled and searched but can't find anything that will automatically add new files to my watcher.

like image 502
Jamie Hutber Avatar asked Apr 20 '16 15:04

Jamie Hutber


Video Answer


2 Answers

There's couple of ways really.

  1. if you are using cli, then you can write $ webpack-dev-server --content-base src/. More from webpack.
  2. if you want the code to be included in you webconfig,

    devServer: {
        contentBase: "./src",
    }
    

    More from weback.

Here contentBase is the directory where you want webpack-dev-server to listen and read the files from.

like image 178
debatanu Avatar answered Oct 06 '22 07:10

debatanu


you should run the server with this command:

webpack-dev-server --progress --hot

like image 22
gianlucatursi Avatar answered Oct 06 '22 08:10

gianlucatursi