forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
176 lines (159 loc) · 5.19 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const path = require('path');
const webpack = require('webpack');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const pluginArray = [];
const sourceMapType = 'source-map';
const TerserPlugin = require('terser-webpack-plugin');
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
/*
if (process.env.NODE_ENV === 'development') {
console.log('Development environment detected, enabling Bundle Analyzer');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
pluginArray.push(new BundleAnalyzerPlugin({
// Can be `server`, `static` or `disabled`.
// In `server` mode analyzer will start HTTP server to show bundle report.
// In `static` mode single HTML file with bundle report will be generated.
// In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting
// `generateStatsFile` to `true`.
analyzerMode: 'static',
// Host that will be used in `server` mode to start HTTP server.
analyzerHost: '127.0.0.1',
// Port that will be used in `server` mode to start HTTP server.
analyzerPort: 8888,
// Path to bundle report file that will be generated in `static` mode.
// Relative to bundles output directory.
reportFilename: 'bundle_report.html',
// Module sizes to show in report by default.
// Should be one of `stat`, `parsed` or `gzip`.
// See "Definitions" section for more information.
defaultSizes: 'parsed',
// Automatically open report in default browser
openAnalyzer: true,
// If `true`, Webpack Stats JSON file will be generated in bundles output directory
generateStatsFile: false,
// Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
// Relative to bundles output directory.
statsFilename: 'stats.json',
// Options for `stats.toJson()` method.
// For example you can exclude sources of your modules from stats file with `source: false` option.
// See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
statsOptions: null,
// Log level. Can be 'info', 'warn', 'error' or 'silent'.
logLevel: 'info'
}));
}
*/
pluginArray.push(new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery'
}));
// limit Timezone data from Moment
pluginArray.push(new MomentTimezoneDataPlugin({
startYear: 2010,
endYear: new Date().getFullYear() + 10,
}));
// Strip all locales except the ones defined in lib/language.js
// (“en” is built into Moment and can’t be removed, 'dk' is not defined in moment)
pluginArray.push(new MomentLocalesPlugin({
localesToKeep: ['bg', 'cs', 'de', 'el', 'es', 'fi', 'fr', 'he', 'hr', 'it', 'ko', 'nb', 'nl', 'pl', 'pt', 'ro', 'ru',
'sk', 'sv', 'zh_cn', 'zh_tw'
],
}));
const rules = [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(jpe?g|png|gif)$/i,
loader: 'file-loader',
query: {
name: '[name].[ext]',
outputPath: 'images/'
//the images will be emmited to public/assets/images/ folder
//the images will be put in the DOM <style> tag as eg. background: url(assets/images/image.png);
},
exclude: /node_modules/
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader'],
exclude: /node_modules/
},
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: '$'
}]
}
];
const appEntry = ['./bundle/bundle.source.js'];
const clockEntry = ['./bundle/bundle.clocks.source.js'];
const reportEntry = ['./bundle/bundle.reports.source.js'];
let mode = 'production';
let publicPath = '/bundle/';
if (process.env.NODE_ENV == 'development') {
mode = 'development';
publicPath = '/devbundle/';
pluginArray.push(new webpack.HotModuleReplacementPlugin());
pluginArray.push(new webpack.NoEmitOnErrorsPlugin());
const hot = 'webpack-hot-middleware/client?port=1337';
appEntry.unshift(hot);
clockEntry.unshift(hot);
reportEntry.unshift(hot);
rules.unshift({
enforce: "pre",
test: /\.js$/,
exclude: [/node_modules/, /bundle/],
loader: "eslint-loader",
options: {
emitWarning: true,
failOnError: false,
failOnWarning: false,
formatter: require('eslint/lib/cli-engine/formatters/stylish')
}
});
}
const optimization = {};
if (process.env.NODE_ENV !== 'development') {
optimization.minimizer = [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true, // Must be set to true if using source-maps in production
terserOptions: {
ie8: false,
safari10: false
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
}),
];
};
module.exports = {
mode,
context: __dirname,
context: path.resolve(__dirname, '.'),
entry: {
app: appEntry,
clock: clockEntry,
report: reportEntry
},
output: {
path: path.resolve(__dirname, './tmp'),
publicPath,
filename: 'js/bundle.[name].js',
sourceMapFilename: 'js/bundle.[name].js.map',
},
devtool: sourceMapType,
optimization,
plugins: pluginArray,
module: {
rules
}
};