最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

My plete 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.

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

My plete 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.

Share Improve this question asked Apr 20, 2016 at 15:54 Jamie HutberJamie Hutber 28.1k54 gold badges194 silver badges312 bronze badges 2
  • Are you using webpack 1 or webpack 2? – debatanu Commented Feb 5, 2017 at 10:42
  • sorry, yes at the time of writing 2 wasn't a thing :) 1.13.1 – Jamie Hutber Commented Feb 5, 2017 at 11:14
Add a ment  | 

2 Answers 2

Reset to default 4 +25

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.

you should run the server with this mand:

webpack-dev-server --progress --hot

发布评论

评论列表(0)

  1. 暂无评论