-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
webpack.config.js
113 lines (106 loc) · 3 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
/* global __dirname process */
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const plugins = [
new MiniCssExtractPlugin(),
// Ignore moment/locale, see: https://github.com/moment/moment/issues/2416
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
];
let mode = 'development';
if (process.env.NODE_ENV == 'production') {
mode = 'production';
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
);
plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
}
const modulesDirectory = path.join(__dirname, 'node_modules');
const getAppMainFile = app => path.join(
__dirname, 'kanmail', 'client', 'components', app, 'main.js',
);
module.exports = {
mode: mode,
plugins: plugins,
entry: {
emails: getAppMainFile('emails'),
send: getAppMainFile('send'),
settings: getAppMainFile('settings'),
contacts: getAppMainFile('contacts'),
license: getAppMainFile('license'),
meta: getAppMainFile('meta'),
metaFile: getAppMainFile('metaFile'),
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/static/dist/',
filename: '[name].js',
},
devServer: {
port: 4421,
contentBase: path.join(__dirname, 'kanmail', 'client', 'static'),
publicPath: '/static/dist/',
headers: {
'Access-Control-Allow-Origin': '*',
},
},
resolve: {
modules: [
path.join(__dirname, 'kanmail', 'client'),
modulesDirectory,
],
},
resolveLoader: {
modules: [
modulesDirectory,
],
},
optimization: {
minimizer: [
new TerserJSPlugin({
terserOptions: {
mangle: false,
keep_classnames: true,
keep_fnames: true,
},
}),
new OptimizeCSSAssetsPlugin({}),
],
splitChunks: {
cacheGroups: {
shared: {
name: 'shared',
chunks: 'initial',
minChunks: 2,
},
}
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(less|css)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|svg|png)$/,
use: ['file-loader'],
},
],
},
}