我有一个C#/ TypeScript项目,该项目使用webpack将TypeScript代码捆绑到目录bundles
中。
目录bundles
由webpack创建,它作为项目的构建后事件触发。
我希望在清理项目或解决方案时删除bundles
目录(或其所有子目录)。我怎么能这样做?
答案 0 :(得分:0)
用于webpack的用户CleanPlugin。这是我在节点中的服务器端代码的配置(请参阅插件部分使用clean-webpack-plugin
):
plugins: [
new CleanPlugin([ buildPath ], { root: projectRootPath }),
// rest of plugins
],
整个配置
var webpack = require("webpack");
var path = require("path");
var CleanPlugin = require('clean-webpack-plugin');
var projectRootPath = path.resolve(__dirname, '../');
var buildPath = path.join(projectRootPath, './build');
module.exports = {
target: "node",
cache: false,
context: projectRootPath,
devtool: "source-map",
entry: [ "./server/server.prod.js" ],
output: {
path: path.join(__dirname, "../build"),
filename: "server.prod.js"
},
plugins: [
new CleanPlugin([ buildPath ], { root: projectRootPath }),
],
module: {
rules: [
{ test: /\.js$/, enforce: "pre", loader: 'eslint-loader', exclude: /node_modules/ },
{
test: /\.js$/,
enforce: "post",
exclude: /node_modules/,
use: [ { loader: 'babel-loader' } ]
}
]
},
externals: nodeModules, // nodeModules is an array variable
resolve: {
modules: [
path.resolve('./server'),
path.resolve('./client'),
path.resolve('./node_modules')
],
extensions: [ ".json", ".js" ]
}
};