2016-06-13 57 views
0

尝试使用gulp设置webpack-dev-server。发生更改时,webpack-dev-server似乎会重新构建bundle.js文件,但如果刷新页面,它仍然是一样的。我必须使用webpack手动编译bundle.js,并且每次都重新启动服务器。gulp webpack-dev-server更改不适用

gulpfile.js

gulp.task('webpack-dev-server', function() { 
    var compiler = webpack(require('./webpack.config')); 
    new WebpackDevServer(compiler, { 
     contentBase: 'public', 
     historyApiFallback: true, 
     progress: true, 
     inline: true 
    }).listen(8000, 'localhost', (err) => { 
       if(err) throw new $.util.PluginError('webpack-dev-server', err); 
       $.util.log('[webpack-dev-server]', 'http://localhost:8000'); 
    }); 
}); 

webpack.config.js

module.exports = { 
    entry: [ 
     './src/index.js' 
    ], 
    output: { 
     path: __dirname + '/public/js', 
     filename: 'bundle.js' 
    }, 
    module: { 
     loaders: [ 
      { 
       test: /\.(jsx|js)$/, 
       loader: "babel-loader", 
       exclude: /node_modules/, 
       query: { 
        presets: ["es2015", "react"] 
       } 
      } 
     ] 
    }, 
    resolve: { 
     extensions: ['', '.js', '.jsx'] 
    }, 
    devServer: { 
     contentBase: 'public', 
     inline: true, 
     progress: true 
    } 
}; 

回答

0

发现了问题:contentBase使用磁盘的根目录作为项目的根,而不是项目文件夹本身。所以路径变成了“F:\ public”。我将其更改为contentBase: __dirname + 'public',它工作。