webpack-dev-server 如何保存本地文件


http://webpack.github.io/docs/webpack-dev-server.html
里说
This modified bundle is served from memory at the relative path specified in publicPath (see API). It will not be written to your configured output directory.

这样 webpack-dev-server 每次build后本地最终的文件没有修改,还要手动执行webpack 一次

有什么方案 让 webpack-dev-server build后,本地文件也修改?

我是这样配置的


 var myConfig = {
  entry: "./js/index",
  output: {
    path: "./dist/js",
    publicPath: 'dist/js/',
    filename: "index.min.js",
    chunkFilename: "[id].chunk.js",
    libraryTarget: "umd"
  }
}

gulp.task('script', function() {
  webpack(myConfig);
})

gulp.task("serve", function() {
  var config = Object.assign(myConfig);
  config.debug = true;
  config.devtool = "source-map";
  config.output.path = '/'; //gulp 里出现报错,,设置path
  new WebpackDevServer(webpack(config), {
    publicPath: '/' + config.output.publicPath,
    stats: {
      colors: true
    },
  }).listen(3001, "localhost", function(err) {
    if (err) throw new gutil.PluginError("webpack-dev-server", err);
  });
});

测试在Serve task的回调或者WebpackDevServer listen的回调里 运行 gulp.start('script') 都会报错

webpack-dev-server webpack

领主灰烬使者 9 years, 7 months ago

你所说的这两项理论上就是被设计成这样的,当debug时,你用到了 webpack-dev-server ,它仅提供内存级别的 serve ,速度更快,而且这个阶段实在没必要输出一次“真正的” bundle

当调试完毕后,再用 webpack 一次性输出 bundle 好了。

现在再来谈,你确实需要调试中每次修改源文件都生成一次真正的 bundle 么?意义是什么?

大概是摸了 answered 9 years, 7 months ago

Your Answer