-
Notifications
You must be signed in to change notification settings - Fork 35
/
webpack.build.config.js
111 lines (104 loc) · 3.08 KB
/
webpack.build.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const path = require('path'),
UglifyJsPlugin = require('uglifyjs-webpack-plugin'),
BOOLEAN_OBJ = {
'true': true,
'false': false
},
WrapperPlugin = require('wrapper-webpack-plugin'),
header = (module.exports = `
(function (factory) {
if (typeof module === 'object' && typeof module.exports !== "undefined") {
module.exports = factory;
} else {
factory(FusionCharts);
}
}(function (FusionCharts) {
`),
footer = `}));
`;
function getPlugins() {
return [
new WrapperPlugin({
test: /^fusioncharts\.jqueryplugin\.js/,
header: header,
footer: footer
})
];
}
function getBabelPlugins (isIE8) {
if (isIE8) {
return [
['transform-es3-member-expression-literals'],
['transform-es3-property-literals']
];
}
}
function getWebpackOptimizations(isIE8, isMinified) {
let optimization = {
splitChunks: {
name: 'fusioncharts.common'
}
};
if (isMinified && isIE8) {
optimization.minimize = true;
optimization.minimizer = [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: {
ecma: 5,
ie8: true,
mangle: true,
compress: true,
keep_classnames: true,
keep_fnames: false
}
})
];
}
return optimization;
}
function getArgumentForWebpack(value, def) {
return BOOLEAN_OBJ[value] === undefined ? def : BOOLEAN_OBJ[value];
}
module.exports = env => {
const IS_IE8 = getArgumentForWebpack(env.ie8, false);
const IS_MINIFIED = getArgumentForWebpack(env.minify, false);
return [
({
entry: './src/jquery-fusioncharts.js',
mode: 'production',
output: {
filename: 'fusioncharts.jqueryplugin.min.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: /^(jquery|\$|fusioncharts)$/i,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
cacheDirectory: true,
plugins: getBabelPlugins(IS_IE8),
presets: [['env', {
targets: { browsers: ['> 0.1%'] },
modules: IS_IE8 ? 'commonjs' : false,
loose: true
}]]
}
}
}
]
},
// devtool: 'source-map',
optimization: getWebpackOptimizations(IS_IE8, IS_MINIFIED),
plugins: getPlugins()
})];
};