-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
78 lines (69 loc) · 2.09 KB
/
webpack.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
const NODE_ENV = process.env.NODE_ENV || 'development';
const webpack = require('webpack');
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const outputFile = '[name].js';
const libraryName = 'conditional-fields';
const PATHS = {
source: path.join(__dirname, 'src'),
build: path.join(__dirname, 'public'),
};
module.exports = {
entry: {
[`${libraryName}.bundle`]: `${PATHS.source}/index.js`,
[`${libraryName}.browser`]: `${PATHS.source}/index.browser.js`,
},
output: {
path: PATHS.build,
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true,
publicPath: '/'
},
mode: NODE_ENV === 'development' ? 'development' : 'production',
devtool: NODE_ENV === 'development' ? 'cheap-inline-module-source-map' : false,
plugins: [
new CleanWebpackPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV)
}),
new webpack.NamedModulesPlugin(),
// new BundleAnalyzerPlugin()
],
module: {
rules: [
{
test: /\.js$/,
include: PATHS.source,
loader: 'babel-loader',
sideEffects: false
}
]
}
};
if (NODE_ENV === 'production') {
module.exports.plugins.push(
new UglifyJsPlugin({
uglifyOptions: {
sourceMap: false,
beautify: false,
comments: false,
mangle: {
keep_fnames: true
},
compress: {
sequences: true,
booleans: true,
loops: true,
unused: true,
warnings: false,
drop_console: true
}
}
})
);
}