-
Notifications
You must be signed in to change notification settings - Fork 213
/
webpack.config.build.js
105 lines (95 loc) · 2.88 KB
/
webpack.config.build.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
const mode = process.env.NODE_ENV !== 'production' ? 'development' : 'production';
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const WatchLiveReloadPlugin = require('webpack-watch-livereload-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const config = {
entry: ['./src/ami.ts'],
devtool: 'source-map',
output: {
path: path.resolve(__dirname, 'build'),
filename: mode === 'development' ? 'ami.js' : 'ami.min.js',
library: 'AMI',
libraryTarget: 'umd',
umdNamedDefine: true,
},
mode,
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.ts', '.js', '.css', '.html'],
alias: {
base: path.resolve(__dirname, 'src'),
pako: path.resolve(__dirname, 'node_modules', 'pako'),
},
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.resolve(__dirname, 'src')],
exclude: [/node_modules/, /external/],
},
{
test: /\.ts$/,
loader: 'ts-loader',
include: [path.resolve(__dirname, 'src')],
exclude: [/external/],
},
],
},
node: {
fs: 'empty',
},
plugins: [],
optimization: {
minimizer: [
new UglifyJsPlugin({
parallel: true,
}),
],
concatenateModules: false,
},
};
if (process.env.NODE_WEBPACK_TARGET) {
config.entry = [
path.resolve(__dirname, process.env.NODE_WEBPACK_TARGET, process.env.NODE_WEBPACK_NAME + '.js'),
];
config.resolve.modules.push(path.resolve(__dirname, process.env.NODE_WEBPACK_TARGET));
config.output.path = path.resolve(__dirname, process.env.NODE_WEBPACK_TARGET);
config.output.filename = process.env.NODE_WEBPACK_NAME + '.js';
config.output.library = undefined;
config.output.libraryTarget = undefined;
config.output.umdNamedDefine = undefined;
config.module.rules
.find(r => r.loader === 'babel-loader')
.include.push(path.resolve(__dirname, process.env.NODE_WEBPACK_TARGET));
const workPath = path.resolve(__dirname, process.env.NODE_WEBPACK_TARGET);
if (mode === 'development' && workPath.indexOf('/dist/') === -1) {
config.plugins.push(
new WatchLiveReloadPlugin({
files: [
path.resolve(__dirname, 'build') + '/*.js',
workPath + '/**/*.html',
workPath + '/**/*.css',
],
})
);
}
const dataPath = path.resolve(__dirname, 'data');
config.devServer = {
contentBase: [dataPath, workPath, path.resolve(__dirname, 'build')],
historyApiFallback: true,
};
} else if (mode === 'production') {
config.plugins.push(
new CompressionPlugin({
algorithm: 'gzip',
})
);
}
if (process.env.NODE_WEBPACK_ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = config;