-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
109 lines (105 loc) · 3.51 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
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
const webpack = require('webpack');
const moment = require('moment');
const path = require('path');
const yaml = require('js-yaml');
const fs = require('fs');
const CleanWebpackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const CONF_FOLDER = './src/main/resources/';
const RFOLDER = './static';
const TEMP = yaml.load(
fs.readFileSync(`${CONF_FOLDER}application.yml`, 'utf8')
.replace('@profileActive@', ''))
module.exports = (env) => {
const mode = env.production ? 'production' : 'development';
const MODECONF = yaml.load(fs.readFileSync(`${CONF_FOLDER}application-${mode}.yml`, 'utf8'));
const APPLICATION = {
...TEMP,
...MODECONF,
api: {
...TEMP.api,
...MODECONF.api
},
redis: {
...TEMP.redis,
...MODECONF.redis
}
}
return {
mode,
output: {
path: path.resolve(__dirname, 'public'),
},
devServer: {
port: 9000
},
plugins: [
new webpack.DefinePlugin({
PRODUCTION: env.production ? true : false,
DEV_SERVER: JSON.stringify(`http://localhost:${APPLICATION.server.port}`),
API_VERSION: JSON.stringify(APPLICATION.api.version),
EC2_API: JSON.stringify(APPLICATION.api.ec2)
}),
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: `${RFOLDER}/index.html`,
title: 'Example Application',
inject: 'body'
}),
new HtmlReplaceWebpackPlugin([
{
pattern: 'JQUERY_VERSION',
replacement: APPLICATION.webjars.jquery
},
{
pattern: 'BOOTSTRAP_VERSION',
replacement: APPLICATION.webjars.bootstrap
},
{
pattern: 'REDIS_TTL_MAX',
replacement: moment.duration(APPLICATION.redis.ttlMax).asHours()
},
{
pattern: 'REDIS_TTL_MIN',
replacement: moment.duration(APPLICATION.redis.ttlMin).asHours()
}
])
],
module: {
rules: [{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
]
}]
},
optimization: {
removeEmptyChunks: true,
minimize: true,
minimizer: [
new UglifyJsPlugin(),
new CssMinimizerPlugin()
]
},
entry: {
aes: `${RFOLDER}/js/aes-gcm.js`,
worker: {
dependOn: ['aes'],
import: `${RFOLDER}/js/worker.js`,
},
handlers: {
dependOn: ['worker'],
import: `${RFOLDER}/js/handlers.js`,
},
main: `${RFOLDER}/css/main.css`
}
}
};