johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building
MIT License
1.96k stars 136 forks source link

delete files when webpack build failed #179

Open liangyuqi opened 4 years ago

liangyuqi commented 4 years ago

Issue description or question

i`d like to remove build output files when webpack build failed ,

like ForkTsCheckerWebpackPlugin throw some eslint error, but i`d like to contiune delete output files

Webpack Config

const SpeedMeasurePlugin = require('speed-measure-webpack-plugin'); // loader/plugins耗时分析
const { resolve } = require('path');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); //remove output
const WebpackBuildNotifierPlugin = require('webpack-build-notifier'); // build 
const WebpackShellPlugin = require('webpack-shell-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const smp = new SpeedMeasurePlugin();

const plugins = [
  new CleanWebpackPlugin({}),
  new WebpackShellPlugin({
    onBuildStart: ['echo "Starting build ... "'],
    onBuildEnd: ['echo "Webpack End"'],
  }),
  new WebpackBuildNotifierPlugin({
    title: 'xxx!',
    suppressSuccess: false,
    suppressCompileStart: false,
    suppressWarning: false,
    activateTerminalOnError: true,
  }),
  new ForkTsCheckerWebpackPlugin({
    typescript: false,
    async: true,
    eslint: {
      files: './src/**/*.ts',
      options: {
        fix: true,
      },
    },
  }),
];

if (process.env.npm_config_report) {
  plugins.push(new BundleAnalyzerPlugin());
}

/**
 * main
 */
module.exports = smp.wrap({
  mode: 'production',
  entry: {
    bdcharts: './src/index.ts',
  },
  devtool: 'source-map',
  output: {
    filename: 'bytecharts.js',
    path: resolve(__dirname, 'build'),
    library: 'Bytecharts',
    libraryTarget: 'umd',
    libraryExport: 'default',
    globalObject: 'this',
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          {
            loader: 'ts-loader',
            options: {
              compiler: 'ttypescript',
            },
          },
        ],
        include: [resolve(__dirname, 'src')],
      },
      {
        test: /\.node$/,
        use: 'node-loader',
      },
    ],
  },
  plugins: plugins,
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    alias: {
      '@src': resolve(__dirname, './src/'),
      '@map': resolve(__dirname, './map/'),
    },
  },
  optimization: {
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          compress: {
            drop_console: true,
          },
        },
      }),
    ],
  },
  performance: {
    maxAssetSize: 500000,
  },
});

Environment

Run: npx envinfo --system --binaries --npmPackages clean-webpack-plugin,webpack

System:
    OS: macOS 10.15.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.21 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.8.0 - ~/.nvm/versions/node/v13.8.0/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.13.6 - ~/.nvm/versions/node/v13.8.0/bin/npm
  npmPackages:
    clean-webpack-plugin: ^3.0.0 => 3.0.0 
    webpack: 4.42.0 => 4.42.0 
jneuendorf commented 4 years ago

+1

I would also welcome an option for not pausing the plugin here

https://github.com/johnagan/clean-webpack-plugin/blob/021d2b68efd18fbd99e02c169d9e32300f15b4f4/src/clean-webpack-plugin.ts#L223-L225

and here

https://github.com/johnagan/clean-webpack-plugin/blob/021d2b68efd18fbd99e02c169d9e32300f15b4f4/src/clean-webpack-plugin.ts#L246-L255

I think 1 option for both places should be enough but what do you think @johnagan ?

I'd be willing to send a PR, if you agree on the new option. 🙂

johnagan commented 4 years ago

I'm open to reviewing a PR on this