-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebpack.config.js
140 lines (133 loc) · 3.66 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
/*eslint-disable */
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import path, {
dirname
} from 'path';
import {
CleanWebpackPlugin
} from 'clean-webpack-plugin';
import {
fileURLToPath
} from 'url';
import env from './utils/env.js';
const __filename = fileURLToPath(
import.meta.url);
const __dirname = dirname(__filename);
// [FS] IRAD-1005 2020-07-07
// Upgrade outdated packages.
var isDev = env.NODE_ENV === 'development' || 0;
// isDev = false;
var options = {
mode: env.NODE_ENV,
entry: {
licit: path.join(__dirname, 'licit', 'client', 'index.js'),
},
output: {
path: path.join(__dirname, 'bin'),
filename: '[name].bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
// https://stackoverflow.com/questions/51860043/javascript-es6-typeerror-class-constructor-client-cannot-be-invoked-without-ne
// ES6 classes are supported in any recent Node version, they shouldn't be transpiled. es2015 should be excluded from Babel configuration, it's preferable to use env preset set to node target.
presets: [
['@babel/preset-env', { targets: { node: true } }],
'@babel/preset-react',
'@babel/preset-flow',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
[
'@babel/plugin-transform-runtime',
{
helpers: true,
regenerator: true,
},
],
'flow-react-proptypes',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-syntax-dynamic-import',
],
},
},
{
test: /\.(woff(2)?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader',
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: /node_modules/,
},
{
test: /\.(js|mjs|jsx)$/,
include: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
}
],
},
resolve: {
alias: {},
},
plugins: [
new webpack.ProvidePlugin({
// jQuery (for Mathquill)
'window.jQuery': 'jquery',
}),
// type checker
// ... (isDev ? [new FlowWebpackPlugin({flowArgs: ['--show-all-errors']})] : []),
// clean the web folder
new CleanWebpackPlugin(),
// expose and write the allowed env vars on the compiled bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV),
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'licit', 'index.html'),
filename: 'index.html',
chunks: ['licit'],
inlineSource: isDev ? '$^' : '.(js|css)$',
}),
],
performance: {
assetFilter: function (assetFilename) {
return (
!assetFilename.endsWith('.eot') &&
!assetFilename.endsWith('.ttf') &&
!assetFilename.endsWith('.svg') &&
!assetFilename.endsWith('licit.bundle.js')
);
},
},
};
if (isDev) {
options.devtool = 'source-map';
} else {
// [FS] IRAD-1005 2020-07-10
// Upgrade outdated packages.
options.optimization = {
minimize: true,
minimizer: [new TerserPlugin()],
};
}
export default options;