【问题标题】:Delete directory on clean清理时删除目录
【发布时间】:2017-03-30 10:29:39
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

    用户 CleanPlugin 用于 webpack。这是我在节点中的服务器端代码的配置(请参阅插件部分使用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" ]
      }
    };
    

    【讨论】:

    • 如何将它与 Visual Studio 中的“清洁解决方案”选项联系起来?
    • 抱歉,我不喜欢 .net。
    • @JamesMonger 查看我发布的 webppack 配置,清理是构建过程的一部分。每次调用构建过程时,都会调用CleanPlugin 作为步骤之一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多