webpack run build but not exit命令

zmeyuzjn  于 2023-08-06  发布在  Webpack
关注(0)|答案(2)|浏览(119)

Webpack成功运行构建,但无法在之后自动退出命令。如何退出?
remove --progress和webpack-dashboard,仍然不能
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",


链接运行此

npm run build


我希望在成功生成not like this image后执行退出命令

lbsnaicq

lbsnaicq1#

将其添加到webpack.base.conf.js

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

字符串
这个使用webpack的编译器钩子,https://webpack.js.org/api/compiler-hooks/#done

ie3xauqp

ie3xauqp2#

在我的例子中,我设置了一个节点进程来显示webpack Bundle Analyzer,这就是为什么我的命令不会退出(一个节点服务总是在运行,除非我手动关闭它)

相关问题