简体   繁体   English

uglifyjs不缩小文件(Webpack)

[英]uglifyjs not minifying the files (Webpack)

I have been trying to use uglify option using webpack, but my resultant page's size remains the same without minification.I tried the following things, 我一直在尝试通过webpack使用uglify选项,但是结果页面的大小却保持不变,没有缩小。我尝试了以下操作,

webpack.config webpack.config

 var webpack = require('webpack'); const Uglify = require("uglifyjs-webpack-plugin"); module.exports = { entry: __dirname + '/app/index.js', module: { rules: [ { test: /\\.js$/, exclude: /node_modules/, loader: 'babel-loader' } ] }, output: { filename: 'whattoname.js', path: __dirname + '/build' }, plugins: [ new Uglify() ] }; 

  1. I tried to set the mode to production 我试图将模式设置为生产
  2. Ran the build using webpack -p command 使用webpack -p命令运行构建
  3. Also with --optimize-minimizer command 同样使用--optimize-minimizer命令

The end file's size remains the same. 最终文件的大小保持不变。 Am I missing something here? 我在这里想念什么吗?

I had a similar issue, to resolve the problem I would suggest moving across to the inbuilt webpack uglifier as seen in the following example (no uglifier dependancy required): 我有一个类似的问题,要解决该问题,我建议移至内置的webpack丑陋者,如以下示例所示(不需要丑陋者依赖):

var webpack = require('webpack');

module.exports = {
    entry: __dirname + '/app/index.js',
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            }
        ]
    },
    output: {
        filename: 'whattoname.js',
        path: __dirname + '/build'
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            minimize: true
         })
    ]
};

If this does not resolve your issue I suggest several actions: 如果这样做不能解决您的问题,建议采取以下几种措施:

  • clean out your dist and recompile to insure the file is actually writing to dist 清理您的dist并重新编译以确保文件实际上正在写入dist

  • Inspect the dist code, to check if it appears uglified. 检查dist代码,检查其是否丑陋。 It is possible your project was already uglifying the file somewhere else, which would mean the file size after uglification does not change 您的项目可能已经在其他地方对文件进行了丑化处理,这意味着经过丑化处理后的文件大小不会更改

  • Adding the include: /\\.js$/ field to your webpack.optimize.UglifyJsPlugin to specify precisely the targeted files include: /\\.js$/字段添加到webpack.optimize.UglifyJsPlugin以精确指定目标文件

As for what caused this issue. 至于是什么原因造成了这个问题。 I would suggest reading this comments posted here 我会建议阅读张贴了这个评论这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM