Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete files when webpack build failed #179

Open
liangyuqi opened this issue Jun 21, 2020 · 2 comments
Open

delete files when webpack build failed #179

liangyuqi opened this issue Jun 21, 2020 · 2 comments

Comments

@liangyuqi
Copy link

liangyuqi commented Jun 21, 2020

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 
@liangyuqi liangyuqi changed the title delete build/* files at once(before build result) delete files when webpack build failed Jun 21, 2020
@jneuendorf
Copy link

jneuendorf commented Jun 23, 2020

+1

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

if (this.initialClean) {
return;
}

and here

if (stats.hasErrors()) {
if (this.verbose) {
// eslint-disable-next-line no-console
console.warn(
'clean-webpack-plugin: pausing due to webpack errors',
);
}
return;
}

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
Copy link
Owner

I'm open to reviewing a PR on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants