删除未使用的webpack chunked文件 [英] Delete unused webpack chunked files

查看:95
本文介绍了删除未使用的webpack chunked文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关如何删除旧的webpack chunked文件的信息。这是我当前的webpack配置:

I'm looking for information on how to delete old webpack chunked files. Here is my current webpack configuration:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  debug: false,
  outputPathinfo: true,
  displayErrorDetails: true,
  context: __dirname,
  entry: {
    common: ['./src/common.coffee'],
    a: './src/a.cjsx',
    b: './src/b.cjsx'
  },
  output: {
    filename: '[name]-[chunkhash].js',
    chunkFileName: '[name].[chunkhash].js',
    path: path.join(__dirname, 'js')
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin('common', 'common-[chunkhash].js'),
    new webpack.optimize.UglifyJsPlugin({
      compress: { warnings: false }
    })
  ],
  module: {
    preLoaders: [
      {
        test: /\.coffee$/,
        exclude: /node_modules/,
        loader: 'coffeelint-loader'
      }
    ],
    loaders: [
      { test: /\.coffee/, loader: 'coffee' },
      { test: /\.cjsx$/, loaders: ['coffee', 'cjsx'] },
      { test: /\.js$/, loader: 'jsx-loader?harmony' }
    ]
  }
}

如果我正在运行 $(npm bin)/ webpack --config webpack。 js --watch 并对 a.cjsx 进行更改,它使用新的chunkedhash编译该文件的较新版本。但是,旧版本仍然存在,我希望它立即删除。

If I am running $(npm bin)/webpack --config webpack.js --watch and make changes to a.cjsx, it compiles a newer version of that file with a new chunkedhash. However, the old one remains and I'd like it to be deleted right away.


  1. 如何删除旧版本的chunked文件?

  2. 一旦手表完成编译,我有办法挂钩回调吗?


推荐答案

有一个 clean-webpack-plugin 出于这些目的,或者你可以为 npm 写一个简单的 bash 脚本:

There is a clean-webpack-plugin for those purposes, or you can write a simple bash script for npm:

 "scripts": {
    "build": "rm -r dist/* && webpack -p",
    "clean": "rm -r dist/*"
  }

这篇关于删除未使用的webpack chunked文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆