- webpack概述
- 入口起点(Entry Points)
- 输出(Output)
- 模块(Mode)
- 加载器(Loaders)
- 插件(Plugins)
- 配置(Configuration)
- 模块(Modules)
- 模块解析(Module Resolution)
- 依赖图表(Dependency Graph)
- 文件清单(Manifest)
- 构建目标(Targets)
- 模块热替换(Hot Module Replacement)
- 第二部分:配置
- 使用不同语言进行配置(Configuration Languages)
- 多种配置类型
- 入口和上下文(Entry and Context)
- 输出(Output)
- 模块(Module)
- 解析(Resolve)
- 插件(Plugins)
- 开发中 Server(DevServer)
- 开发工具(Devtool)
- 构建目标(Targets)
- Watch 和 WatchOptions
- 外部扩展(Externals)
- 性能(Performance)
- Node
- 统计(Stats)
- 其它选项(Other Options)
- 第三部分:API
- 命令行接口(CLI)
- 包含统计数据的文件(stats data)
- Node.js API
- 模块热替换(Hot Module Replacement)
- 加载器 API
- 模块方法(module methods)
- 模块变量(module variables)
- Plugin API
- compiler 钩子
- compilation 钩子
- resolver
- parser
- 第四部分:指南
- 安装
- 起步
- 管理资源
- 管理输出
- 开发
- 模块热替换
- Tree shaking
- 生产环境构建
- 代码拆分(Code Splitting)
- 懒加载(Lazy Loading)
- 缓存(Caching)
- 创建库 (Library)
- Shimming
- 渐进式网络应用程序
- TypeScript
- 迁移到新版本
- 使用环境变量
- 构建性能
- 内容安全策略
- 开发 - Vagrant
- 管理依赖
- Public Path(公共路径)
- 集成(Integrations)
- 第五部分:加载器
- babel-loader
- yaml-frontmatter-loader
- cache-loader
- coffee-loader
- coffee-redux-loader
- coverjs-loader
- css-loader
- exports-loader
- expose-loader
- extract-loader
- file-loader
- gzip-loader
- html-loader
- i18n-loader
- imports-loader
- istanbul-instrumenter-loader
- jshint-loader
- json-loader
- json5-loader
- less-loader
- bundle-loader
- multi-loader
- node-loader
- null-loader
- polymer-webpack-loader
- postcss-loader
- raw-loader
- react-proxy-loader
- restyle-loader
- sass-loader
- script-loader
- source-map-loader
- style-loader
- svg-inline-loader
- thread-loader
- transform-loader
- url-loader
- val-loader
- worker-loader
- mocha-loader
- 第六部分:插件
- AggressiveSplittingPlugin
- ZopfliWebpackPlugin
- BannerPlugin
- ClosureWebpackPlugin
- CommonsChunkPlugin
- ComponentWebpackPlugin
- CompressionWebpackPlugin
- ContextReplacementPlugin
- CopyWebpackPlugin
- DefinePlugin
- DllPlugin
- EnvironmentPlugin
- EvalSourceMapDevToolPlugin
- ExtractTextWebpackPlugin
- HashedModuleIdsPlugin
- HotModuleReplacementPlugin
- HtmlWebpackPlugin
- BabelMinifyWebpackPlugin
- IgnorePlugin
- LoaderOptionsPlugin
- MinChunkSizePlugin
- ModuleConcatenationPlugin
- NamedModulesPlugin
- NormalModuleReplacementPlugin
- NpmInstallWebpackPlugin
- PrefetchPlugin
- ProfilingPlugin
- ProvidePlugin
- SourceMapDevToolPlugin
- SplitChunksPlugin
- UglifyjsWebpackPlugin
- WatchIgnorePlugin
- I18nWebpackPlugin
UglifyjsWebpackPlugin
This plugin uses UglifyJS v3 (uglify-es
) to minify your JavaScript
ℹ️
webpack =< v3.0.0
currently containsv0.4.6
of this plugin underwebpack.optimize.UglifyJsPlugin
as an alias. For usage of the latest version (v1.0.0
), please follow the instructions below. Aliasingv1.0.0
aswebpack.optimize.UglifyJsPlugin
is scheduled forwebpack v4.0.0
安装
npm i -D uglifyjs-webpack-plugin
用法
webpack.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
plugins: [
new UglifyJsPlugin()
]
}
选项
属性名称 | 类型 | 默认值 | 描述 | |||
---|---|---|---|---|---|---|
test | `{RegExp\ | Array}` | /.js($|\?)/i | 测试匹配的文件 | ||
include | `{RegExp\ | Array}` | undefined | 包含 的文件 | ||
exclude | `{RegExp\ | Array}` | undefined | 排除 的文件。 | ||
cache | `{Boolean\ | String}` | false | 启用文件缓存 | ||
parallel | `{Boolean\ | Object}` | false | 使用多进程并行运行和文件缓存来提高构建速度 | ||
sourceMap | {Boolean} | false | 使用 source map 将错误信息的位置映射到模块(这会减慢编译的速度) ⚠️ cheap-source-map 选项不适用于此插件 | |||
uglifyOptions | {Object} | {...defaults} | uglify 选项 | |||
extractComments | `{Boolean\ | RegExp\ | Function<(node, comment) -> {Boolean\ | Object}>}` | false | 是否将注释提取到单独的文件,(查看= 2.3.0`" target="_blank">详细 |
warningsFilter | {Function(source) -> {Boolean}} | () => true | 允许过滤 uglify 警告 |
webpack.config.js
[
new UglifyJsPlugin({
test: /\.js($|\?)/i
})
]
include
webpack.config.js
[
new UglifyJsPlugin({
include: /\/includes/
})
]
exclude
webpack.config.js
[
new UglifyJsPlugin({
exclude: /\/excludes/
})
]
cache
{Boolean}
webpack.config.js
[
new UglifyJsPlugin({
cache: true
})
]
Enable file caching. Default path to cache directory: node_modules/.cache/uglifyjs-webpack-plugin
.
{String}
webpack.config.js
[
new UglifyJsPlugin({
cache: 'path/to/cache'
})
]
Path to cache directory.
parallel
{Boolean}
webpack.config.js
[
new UglifyJsPlugin({
parallel: true
})
]
Enable parallelization. Default number of concurrent runs: os.cpus().length - 1
.
{Number}
webpack.config.js
[
new UglifyJsPlugin({
parallel: 4
})
]
Number of concurrent runs.
ℹ️ Parallelization can speedup your build significantly and is therefore highly recommended
sourceMap
webpack.config.js
[
new UglifyJsPlugin({
sourceMap: true
})
]
⚠️
cheap-source-map
options don't work with this plugin
uglifyOptions
Name | Type | Default | Description | |
---|---|---|---|---|
ie8 | {Boolean} | false | Enable IE8 Support | |
ecma | {Number} | undefined | Supported ECMAScript Version (5 , 6 , 7 or 8 ). Affects parse , compress && output options | |
parse | {Object} | {} | Additional Parse Options | |
mangle | `{Boolean\ | Object}` | true | Enable Name Mangling (See Mangle Properties for advanced setups, use with ⚠️) |
output | {Object} | {} | Additional Output Options (The defaults are optimized for best compression) | |
compress | `{Boolean\ | Object}` | true | Additional Compress Options |
warnings | {Boolean} | false | Display Warnings |
webpack.config.js
[
new UglifyJsPlugin({
uglifyOptions: {
ie8: false,
ecma: 8,
parse: {...options},
mangle: {
...options,
properties: {
// mangle property options
}
},
output: {
comments: false,
beautify: false,
...options
},
compress: {...options},
warnings: false
}
})
]
extractComments
{Boolean}
All comments that normally would be preserved by the comments
option will be moved to a separate file. If the original file is named foo.js
, then the comments will be stored to foo.js.LICENSE
.
{RegExp|String}
or {Function<(node, comment) -> {Boolean}>}
All comments that match the given expression (resp. are evaluated to true
by the function) will be extracted to the separate file. The comments
option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.
{Object}
Name | Type | Default | Description | ||
---|---|---|---|---|---|
condition | `{Regex\ | Function}` | `` | 通常表达式或者相应函数(见上文) | |
filename | `{String\ | Function}` | ${file}.LICENSE | 提取注释的文件会被存储。可以使一个 {String} 字符串或者是一个 {Function<(string) -> {String}>} 返回字符串的函数,作为原文件名。默认加上文件后缀名 .LICENSE | |
banner | `{Boolean\ | String\ | Function}` | /*! For license information please see ${filename}.js.LICENSE */ | banner 文本会在原文件的头部指出被提取的文件,会在源文件加入该信息。可以是 false (表示没有 banner),一个 {String} ,或者一个 {Function<(string) -> {String} 返回字符串的函数,会在提取已经被存储注释的时候被调用。注释会被覆盖。 |
warningsFilter
webpack.config.js
[
new UglifyJsPlugin({
warningsFilter: (src) => true
})
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论