Created
January 3, 2019 19:19
-
-
Save HamidOsouli-zz/c4303b966d8665b9fe8633544bece068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const path = require('path') | |
const utils = require('./utils') | |
const webpack = require('webpack') | |
const config = require('../config') | |
const merge = require('webpack-merge') | |
const baseWebpackConfig = require('./webpack.base.conf') | |
const CopyWebpackPlugin = require('copy-webpack-plugin') | |
const HtmlWebpackPlugin = require('html-webpack-plugin') | |
const ExtractTextPlugin = require('extract-text-webpack-plugin') | |
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | |
const multiHelper = require('./multi-helper') | |
const env = require('../config/prod.env') | |
const webpackConfig = merge(baseWebpackConfig, { | |
entry: multiHelper.getEntry(), | |
module: { | |
rules: utils.styleLoaders({ | |
sourceMap: config.build.productionSourceMap, | |
usePostCSS: true, | |
extract: false | |
}) | |
}, | |
devtool: config.build.productionSourceMap ? config.build.devtool : false, | |
output: { | |
path: config.build.assetsRoot, | |
filename: '[name].js', | |
publicPath: process.env.NODE_ENV === 'production' | |
? config.build.assetsPublicPath | |
: config.dev.assetsPublicPath | |
}, | |
plugins: multiHelper.generateTemplate(), | |
}) | |
webpackConfig.plugins.push(// http://vuejs.github.io/vue-loader/en/workflow/production.html | |
new webpack.DefinePlugin({ | |
'process.env': env | |
}), | |
new UglifyJsPlugin({ | |
uglifyOptions: { | |
compress: { | |
warnings: false, | |
drop_console: true | |
} | |
}, | |
sourceMap: config.build.productionSourceMap, | |
parallel: true | |
}), | |
// extract css into its own file | |
new ExtractTextPlugin({ | |
filename: utils.assetsPath('css/[name].[contenthash].css'), | |
// Setting the following option to `false` will not extract CSS from codesplit chunks. | |
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. | |
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, | |
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 | |
allChunks: true, | |
}), | |
// Compress extracted CSS. We are using this plugin so that possible | |
// duplicated CSS from different components can be deduped. | |
new OptimizeCSSPlugin({ | |
cssProcessorOptions: config.build.productionSourceMap | |
? { safe: true, map: { inline: false } } | |
: { safe: true } | |
}), | |
// keep module.id stable when vendor modules does not change | |
new webpack.HashedModuleIdsPlugin(), | |
// enable scope hoisting | |
new webpack.optimize.ModuleConcatenationPlugin(), | |
new CopyWebpackPlugin([ | |
{ | |
from: path.resolve(__dirname, "../.htaccess"), | |
to: path.resolve(__dirname, '../dist/.htaccess'), | |
toType: 'file' | |
} | |
]) | |
); | |
if (config.build.productionGzip) { | |
const CompressionWebpackPlugin = require('compression-webpack-plugin') | |
webpackConfig.plugins.push( | |
new CompressionWebpackPlugin({ | |
asset: '[path].gz[query]', | |
algorithm: 'gzip', | |
test: new RegExp( | |
'\\.(' + | |
config.build.productionGzipExtensions.join('|') + | |
')$' | |
), | |
threshold: 10240, | |
minRatio: 0.8 | |
}) | |
) | |
} | |
if (config.build.bundleAnalyzerReport) { | |
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin | |
webpackConfig.plugins.push(new BundleAnalyzerPlugin()) | |
} | |
module.exports = webpackConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment