删除干净

时间:2017-03-30 10:29:39

标签: visual-studio msbuild visual-studio-2017

我有一个C#/ TypeScript项目,该项目使用webpack将TypeScript代码捆绑到目录bundles中。

目录bundles由webpack创建,它作为项目的构建后事件触发。

我希望在清理项目或解决方案时删除bundles目录(或其所有子目录)。我怎么能这样做?

1 个答案:

答案 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" ]
  }
};