-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.prod.js
131 lines (126 loc) · 3.89 KB
/
webpack.prod.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const os = require('os')
const path = require('path')
const merge = require('webpack-merge')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const { DefinePlugin } = require('webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const common = require('./webpack.common.js')
const extractSass = new ExtractTextPlugin({
// filename: "mdl.[contenthash].min.css",
filename: "mdl.min.css",
disable: process.env.NODE_ENV === "development"
})
module.exports = merge(common, {
output: {
path: path.join(__dirname, 'dist'),
// publicPath: httpDirAbsolutePath,
filename: `mdl.min.js`, // Webpack 3.x emits CSS wrapped in a JS file (cssExtractorPlugin unwraps it)
library: `mdl`,
libraryTarget: 'umd',
umdNamedDefine: true,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
// {
// loader: 'file-loader',
// options: {
// name: 'mdl.min.css',
// },
// },
// { loader: 'extract-loader' },
{
loader: 'css-loader',
options: {
minimize: true,
}
},
{ loader: 'postcss-loader', options: {
plugins: [
require('autoprefixer')
]}
},
{
loader: 'sass-loader',
options: {
importer: function(url, prev) {
if(url.indexOf('@material') === 0) {
const filePath = url.split('@material')[1]
const nodeModulePath = `./node_modules/@material/${filePath}`
return { file: require('path').resolve(nodeModulePath) }
}
return { file: url }
}
}
},
],
// use style-loader in development
fallback: "style-loader"
})
}
]
},
plugins: [
extractSass,
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: path.join(__dirname, 'report.html'),
}),
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
// https://bitbucket.org/atlassian/atlaskit-mk-2/src/f2856940b3f79482750f3972928b9352ccf1b678/build/webpack-config/config/index.js?at=master&fileviewer=file-view-default
new UglifyJsPlugin({
parallel: Math.max(os.cpus().length - 1, 1),
uglifyOptions: {
compress: {
// Disabling following options speeds up minimization by 20 – 30s
// without any significant impact on a bundle size.
arrows: false,
booleans: false,
collapse_vars: false,
// https://product-fabric.atlassian.net/browse/MSW-436
comparisons: false,
computed_props: false,
hoist_funs: false,
hoist_props: false,
hoist_vars: false,
if_return: false,
inline: false,
join_vars: false,
keep_infinity: true,
loops: false,
negate_iife: false,
properties: false,
reduce_funcs: false,
reduce_vars: false,
sequences: false,
side_effects: false,
switches: false,
top_retain: false,
toplevel: false,
typeofs: false,
unused: false,
// Switch off all types of compression except those needed to convince
// react-devtools that we're using a production build
conditionals: true,
dead_code: true,
evaluate: true,
},
mangle: true,
},
})
]
})