|
@@ -4,67 +4,72 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
|
const TerserJSPlugin = require('terser-webpack-plugin')
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin')
|
|
|
+const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
|
|
const webpack = require('webpack')
|
|
|
const path = require('path')
|
|
|
-const prodConf = {
|
|
|
- mode: 'production',
|
|
|
- devtool: 'cheap-module-source-map',
|
|
|
- output: {
|
|
|
- path: path.resolve(__dirname, '../../../pub/zq2019/t_ydzy_simulator'),//path.resolve(__dirname, '../../../pub/zq2019/ydzy_simulator'),
|
|
|
- publicPath: '//pub.dwstatic.com/zq2019/t_ydzy_simulator/',
|
|
|
- filename: 'js/[name]_[contenthash:5].js',
|
|
|
- },
|
|
|
- module: {
|
|
|
- rules: [
|
|
|
- {
|
|
|
- test: /(?<!\.module)\.(scss|css)$/,
|
|
|
- use: [
|
|
|
- MiniCssExtractPlugin.loader,
|
|
|
- {
|
|
|
- loader: 'css-loader',
|
|
|
- options: {
|
|
|
- importLoaders: 2
|
|
|
- }
|
|
|
- },
|
|
|
- 'sass-loader',
|
|
|
- 'postcss-loader'
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- test: /(?<=\.module)\.(scss|css)$/,
|
|
|
- use: [
|
|
|
- MiniCssExtractPlugin.loader,
|
|
|
- {
|
|
|
- loader: 'css-loader',
|
|
|
- options: {
|
|
|
- importLoaders: 2,
|
|
|
- modules: true
|
|
|
- }
|
|
|
- },
|
|
|
- 'sass-loader',
|
|
|
- 'postcss-loader'
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- plugins: [
|
|
|
- new MiniCssExtractPlugin({
|
|
|
- filename: 'css/[name]_[contenthash:5].css',
|
|
|
- chunkFilename: 'css/[id]_[contenthash:5].css'
|
|
|
- }),
|
|
|
- new CleanWebpackPlugin(),
|
|
|
- new webpack.DefinePlugin({
|
|
|
- DEV: JSON.stringify(false)
|
|
|
- })
|
|
|
- ],
|
|
|
- optimization: {
|
|
|
- minimizer: [
|
|
|
- new TerserJSPlugin({
|
|
|
- sourceMap: true
|
|
|
+
|
|
|
+module.exports = env => {
|
|
|
+ const prodConf = {
|
|
|
+ mode: 'production',
|
|
|
+ devtool: 'cheap-module-source-map',
|
|
|
+ output: {
|
|
|
+ path: env && env.test ? path.resolve(__dirname, '../../../pub/zq2019/t_ydzy_simulator') : path.resolve(__dirname, '../../../pub/zq2019/ydzy_simulator'),
|
|
|
+ publicPath: env && env.test ? '//pub.dwstatic.com/zq2019/t_ydzy_simulator/' : '//pub.dwstatic.com/zq2019/ydzy_simulator/',
|
|
|
+ filename: 'js/[name]_[contenthash:5].js',
|
|
|
+ },
|
|
|
+ module: {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ test: /(?<!\.module)\.(scss|css)$/,
|
|
|
+ use: [
|
|
|
+ MiniCssExtractPlugin.loader,
|
|
|
+ {
|
|
|
+ loader: 'css-loader',
|
|
|
+ options: {
|
|
|
+ importLoaders: 2
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'sass-loader',
|
|
|
+ 'postcss-loader'
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ test: /(?<=\.module)\.(scss|css)$/,
|
|
|
+ use: [
|
|
|
+ MiniCssExtractPlugin.loader,
|
|
|
+ {
|
|
|
+ loader: 'css-loader',
|
|
|
+ options: {
|
|
|
+ importLoaders: 2,
|
|
|
+ modules: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'sass-loader',
|
|
|
+ 'postcss-loader'
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ plugins: [
|
|
|
+ new MiniCssExtractPlugin({
|
|
|
+ filename: 'css/[name]_[contenthash:5].css',
|
|
|
+ chunkFilename: 'css/[id]_[contenthash:5].css'
|
|
|
}),
|
|
|
- new OptimizeCSSAssetsPlugin({})
|
|
|
- ]
|
|
|
+ new CleanWebpackPlugin(),
|
|
|
+ new webpack.DefinePlugin({
|
|
|
+ DEV: JSON.stringify(false)
|
|
|
+ })
|
|
|
+ ].concat(env && env.analyse ? new BundleAnalyzerPlugin() : []),
|
|
|
+ optimization: {
|
|
|
+ minimizer: [
|
|
|
+ new TerserJSPlugin({
|
|
|
+ sourceMap: true
|
|
|
+ }),
|
|
|
+ new OptimizeCSSAssetsPlugin({})
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
+ return merge(commonConf, prodConf)
|
|
|
}
|
|
|
|
|
|
-module.exports = merge(commonConf, prodConf)
|
|
|
+
|