This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
155 lines (154 loc) · 4.9 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
const HtmlWebPackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const dayjs = require('dayjs');
const getClientEnvironment = require('./env');
module.exports = (env, argv) => {
const debug = (env && env.debug);
// Get environment variables to inject into our app.
const envVars = getClientEnvironment(argv.stage);
const plugins = [
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
staticVersion: dayjs().unix(),
environment: process.env.NODE_ENV,
env: envVars.raw,
inject: false,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
new webpack.DefinePlugin(envVars.stringified),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new CopyWebpackPlugin([{
from: 'node_modules/speech-rule-engine/lib/sre_browser.js',
to: 'libs/speech-rule-engine/lib/sre_browser.js',
}, {
from: 'src/lib/google-signin/style.css',
to: 'libs/google-signin/style.css',
}, {
from: 'static/microsoft-identity-association.json',
to: '.well-known/microsoft-identity-association.json',
}, {
from: 'v2/dist/main.css',
to: 'main.v2.css',
}, {
from: 'v2/dist/main.js',
to: 'main.v2.js',
}]),
];
if (!debug) {
plugins.push(new webpack.IgnorePlugin(/mathlive\/src\/mathlive.js/));
}
return {
resolveLoader: {
modules: [path.join(__dirname, 'node_modules')],
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.s(a|c)ss$/,
exclude: /node_modules/,
loader: [
debug ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
camelCase: true,
sourceMap: debug,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: debug,
},
},
],
},
{
test: /\.css$/,
include: [
/src(\/|\\)components/,
],
use: [{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: '[name]_[local]_[hash:base64]',
sourceMap: true,
minimize: true,
},
},
],
},
{
test: /\.(jpg|png|gif|pdf|ico)$/,
include: /images/,
use: [{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
}],
},
{
test: /\.css$/,
include: [
/node_modules(\/|\\)react-toastify/,
/node_modules(\/|\\)bootstrap/,
/src(\/|\\)lib/,
/src(\/|\\)styles/,
],
use: [{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\S+)?$/,
loader: 'file-loader?publicPath=/&name=fonts/[name].[ext]',
},
{
enforce: 'pre',
test: /\.js$/,
exclude: [/node_modules/, /dist/, /src(\/|\\)lib/],
loaders: ['eslint-loader'],
},
],
},
devServer: {
port: 3000,
},
plugins,
resolve: {
extensions: ['.js', '.css', '.scss'],
},
};
};