-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathwebpack.common.js
More file actions
129 lines (126 loc) · 3.39 KB
/
webpack.common.js
File metadata and controls
129 lines (126 loc) · 3.39 KB
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
const { join, resolve } = require('path');
const {
IgnorePlugin,
ContextReplacementPlugin,
DefinePlugin,
} = require('webpack');
const DotenvPlugin = require('dotenv-webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const packageJSON = require('./package.json');
const cssIncludes = require('./css-includes.json');
const ENV_DIR = process.env.BABEL_ENV === 'e2e-test' ? './.env.test' : './.env';
/**
* @type {import('webpack').Configuration}
*/
module.exports = {
entry: './app/index.tsx',
output: {
path: join(__dirname, 'build'),
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
api: resolve('./app/api'),
assets: resolve('./app/assets'),
lib: resolve('./app/lib'),
theme: resolve('./app/theme'),
types: resolve('./app/types'),
utilities: resolve('./app/utilities'),
bundles: resolve('./app/bundles'),
course: resolve('./app/bundles/course'),
testUtils: resolve('./app/__test__/utils'),
workers: resolve('./app/workers'),
store: resolve('./app/store'),
},
},
optimization: {
splitChunks: {
chunks: 'all',
},
moduleIds: 'deterministic',
},
plugins: [
new DotenvPlugin({ path: ENV_DIR }),
new IgnorePlugin({ resourceRegExp: /__test__/ }),
new HtmlWebpackPlugin({ template: './public/index.html' }),
new FaviconsWebpackPlugin({
logo: './favicon.svg',
inject: true,
mode: 'auto',
}),
// Do not require all locales in moment
new ContextReplacementPlugin(/moment\/locale$/, /^\.\/(en-.*|zh-.*)$/),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: 'write-references',
},
}),
new DefinePlugin({
FIRST_BUILD_YEAR: JSON.stringify(packageJSON.firstBuildYear),
LATEST_BUILD_YEAR: JSON.stringify(new Date().getFullYear()),
}),
],
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: false } },
'postcss-loader',
],
include: cssIncludes.map((path) => resolve(__dirname, path)),
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: false,
modules: {
localIdentName: '[path]___[name]__[local]___[hash:base64:5]',
},
},
},
'postcss-loader',
'sass-loader',
],
exclude: [/node_modules/],
},
{
test: /\.(csv|png|svg)$/i,
type: 'asset',
resourceQuery: /url/, // *.(csv|png|svg)?url
exclude: /node_modules/,
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url
use: [
{
loader: '@svgr/webpack',
options: {
typescript: true,
ext: 'tsx',
},
},
],
exclude: /node_modules/,
},
{
test: /\.md$/,
type: 'asset/source',
},
],
},
};