我使用clean-webpack-plugin在构建之前删除/dist文件夹,只有在编译阶段使用Flow success时才使用。
我遇到的问题是,即使流抛出错误,干净的插件也会运行。

这是否有可能解决这个问题(我的意思是,当有编译错误时,不要删除"dist“文件夹)?
./src/app.js
function init(a: number) {
//...
}
init("2");./webpac.config.json
const path = require("path");
const webpack = require("webpack");
const flowTypeLoaderPlugin = require("flowtype-loader/plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = [{
entry : "./src/app.js",
output : {
filename : "build.js",
path : path.resolve(__dirname, "dist")
},
module : {
loaders : [
/*{
test: /\.js$/,
enforce: "pre",
use: CleanWebpackPlugin(["dist"], {
root: "/dist",
verbose: true,
dry: true,
"watch": true
})
},*/
{
test : /\.js$/,
loader : "flowtype-loader",
enforce : "pre",
exclude : /node_modules/
},
{
test : /\.jsx?$/,
enforce : "pre",
loader : "remove-flow-types-loader",
include : path.join(__dirname, "src")
}
]
},
plugins : [
new flowTypeLoaderPlugin({cwd : path.resolve(__dirname, "src"), failOnError : true}),
//Empty "dist" folder
new CleanWebpackPlugin(["dist"], {
root: "/",
verbose: true,
dry: true,
"watch": true
})
]
}];发布于 2017-05-11 13:21:09
解决这一问题的一种方法是通过添加“应该发出”条件来修改CleanWebpackPlugin的代码。它对我很有效,但我不确定它是否适用于每一种可能的情况:
CleanWebpackPlugin.prototype.apply = function(compiler) {
var _this = this;
if (compiler === undefined) {
return clean.call(_this);
} else {
compiler.plugin("should-emit", compilation => {
if (_this.options.watch) {
compiler.plugin("compile", function(params) {
clean.call(_this);
});
} else {
return clean.call(_this);
}
});
}
};这还要求您在webpack配置文件中使用另一个插件:NoEmitOnErrorsPlugin。
https://stackoverflow.com/questions/43891937
复制相似问题