-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.config.js
95 lines (87 loc) · 2.89 KB
/
webpack.production.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const webpack = require('webpack');
const path = require('path');
const rules = require('./webpack.common').rules;
const externals = require('./webpack.common').externals;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackCleanupPlugin = require('webpack-cleanup-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
rules.push({
test: /\.scss$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { modules : {
localIdentName: '[local]___[hash:base64:5]'
}}
},
{
loader: 'sass-loader',
options: {sassOptions: {
outputStyle: 'expanded'
}}
}
],
});
// ExtractTextPlugin.extract({fallback: 'style-loader', use : 'css-loader?sourceMap&localIdentName=[local]___[hash:base64:5]!sass-loader?outputStyle=expanded'}),
module.exports = env => {
const fileName = env.min ? 'static/[name].min.js' : 'static/[name].js';
const outPath = env.min ? 'dist/compressed' : 'dist/uncompressed';
const plugins = [
//new BundleAnalyzerPlugin(),
new WebpackCleanupPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new MiniCssExtractPlugin({
filename: 'static/style.css',
chunkFilename: 'static/[id].css'
}),
new OptimizeCssAssetsPlugin(),
new webpack.LoaderOptionsPlugin({
minimize: true,
context: __dirname
}),
new HtmlWebpackPlugin({
chunks: ['be5-react'],
template: './src/template.html',
files: {
css: ['style.css'],
js: ['bundle.js'],
}
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en|ru/),
new webpack.ProgressPlugin()
];
if(env.min) {
plugins.push(new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}));
}
return {
mode: "production",
optimization: {minimize: env.min},
devtool: env.min ? false : 'inline-source-map',
entry: {
'be5-react': ['babel-polyfill', './src/scripts/be5/main.js']
},
output: {
publicPath: './',
path: path.join(__dirname, outPath),
filename: fileName,
library: '[name]',
chunkFilename: 'static/be5-[name]-[id].js',
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
extensions: ['.js', '.jsx','.css']
},
module: {
rules
},
plugins: plugins,
externals: externals,
}
};