Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack run build but not exit command

Tags:

webpack

vue.js

Webpack successfully run build, but can't auto exit command after. How to exit?

remove --progress and webpack-dashboard,still can't

webpack.base.conf.js

...// require
module.exports = {
  mode: process.env.NODE_ENV,
  entry: {
    app: './src/main.js',
  },
  output: {
    path: util.resolve('dist'),
    filename: 'js/[name].[hash].js',
    chunkFilename: 'js/[id].[chunkhash].js',
  },
  module: {
    rules: [
      ...util.eslint,
      ...util.cssLoaders,
      // more loaders
  },
  plugins: [
      new CleanWebpackPlugin(),
      new HtmlWebpackPlugin({
        template: path.resolve(__dirname, '../public/index.html'),
        minify: {
          removeComments: true,
          collapseWhitespace: true,
          removeAttributeQuotes: true,
        },
      }),
    new DllLinkPlugin({
      htmlMode: true,
      config: require('./webpack.dll.conf.js'),
    }),
  ],
  stats: {
    children: false, 
    builtAt: true, 
    cached: true,
    cachedAssets: true
  }
};

webpack.prod.conf.js

// requere...
const config = require('./webpack.base.conf');
const env = require('../env.production')

module.exports = merge(config, {
  bail: true,
watch:false,
  devtool: 'cheap-module-source-map',
  plugins: [
    // ... mini css html
    new CompressionWebpackPlugin({
      filename: '[path].gz[query]',
      algorithm: 'gzip',
      test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
      threshold: 10240,
      minRatio: 0.8
    })
  ],
  optimization: {
    ... options
  }
});

package.json

    "build": "cross-env NODE_ENV=production webpack --progress --config build/webpack.prod.conf.js",

link run this

npm run build

i expect exit command after Successfully build ,not like this image

like image 662
袁子文 Avatar asked May 09 '19 06:05

袁子文


1 Answers

add this to your webpack.base.conf.js

plugins: [
    // your plugins...
    {
       apply: (compiler) => {
         compiler.hooks.done.tap('DonePlugin', (stats) => {
           console.log('Compile is done !')
           setTimeout(() => {
             process.exit(0)
           })
         });
       }
    }
]

This use webpack's compiler hooks, https://webpack.js.org/api/compiler-hooks/#done

like image 196
Old_dream Avatar answered Sep 26 '22 07:09

Old_dream