webpack.prod.conf.js
2021-07-08 00:04
标签:tin filename 输出 man hit plugin http options uglifyjs var path = require(‘path‘) // 用于从webpack生成的bundle中提取文本到特定文件中的插件 var ExtractTextPlugin = require(‘extract-text-webpack-plugin‘) var env = process.env.NODE_ENV === ‘testing‘ // 合并基础的webpack配置 devtool: config.build.productionSourceMap ? ‘#source-map‘ : false, // 配置webpack插件 plugins: [ // 丑化压缩代码 // 抽离css文件 // generate dist index.html with correct asset hash for caching. ? ‘index.html‘ // necessary to consistently work with multiple chunks via CommonsChunkPlugin // split vendor js into its own file return ( new webpack.optimize.CommonsChunkPlugin({ // gzip模式下需要引入compression插件进行压缩 threshold: 10240, if (config.build.bundleAnalyzerReport) { module.exports = webpackConfig webpack.prod.conf.js 标签:tin filename 输出 man hit plugin http options uglifyjs 原文地址:http://www.cnblogs.com/moneyss/p/7098648.html
var utils = require(‘./utils‘)
var webpack = require(‘webpack‘)
var config = require(‘../config‘)
var merge = require(‘webpack-merge‘)
var baseWebpackConfig = require(‘./webpack.base.conf‘)
var HtmlWebpackPlugin = require(‘html-webpack-plugin‘)
// 可以抽取出css,js文件将其与webpack输出的bundle分离
? require(‘../config/test.env‘)
: config.build.env
var webpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
},
// 配置webpack的输出
output: {
// 编译输出目录
path: config.build.assetsRoot,
// 编译输出文件名格式
filename: utils.assetsPath(‘js/[name].[chunkhash].js‘),
// 没有指定输出名的文件输出的文件名格式
chunkFilename: utils.assetsPath(‘js/[id].[chunkhash].js‘)
},
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
‘process.env‘: env
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
sourceMap: true
}),
new ExtractTextPlugin({
filename: utils.assetsPath(‘css/[name].[contenthash].css‘)
}),
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === ‘testing‘
: config.build.index,
template: ‘index.html‘,
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
chunksSortMode: ‘dependency‘
}),
new webpack.optimize.CommonsChunkPlugin({
name: ‘vendor‘,
minChunks: function (module, count) {
// any required modules inside node_modules are extracted to vendor
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, ‘../node_modules‘)
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
name: ‘manifest‘,
chunks: [‘vendor‘]
})
]
})
if (config.build.productionGzip) {
var CompressionWebpackPlugin = require(‘compression-webpack-plugin‘)
webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: ‘[path].gz[query]‘,
algorithm: ‘gzip‘,
test: new RegExp(
‘\\.(‘ +
config.build.productionGzipExtensions.join(‘|‘) +
‘)$‘
),
minRatio: 0.8
})
)
}
var BundleAnalyzerPlugin = require(‘webpack-bundle-analyzer‘).BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
文章标题:webpack.prod.conf.js
文章链接:http://soscw.com/index.php/essay/102231.html