-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
157 lines (153 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
'use strict';
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const os = require('os');
const { cli } = require("webpack-dev-server");
// DEPLOY_PATH is set by the s3-deploy-action its value will be:
// `branch/[branch-name]/` or `version/[tag-name]/`
// See the following documentation for more detail:
// https://github.com/concord-consortium/s3-deploy-action/blob/main/README.md#top-branch-example
const DEPLOY_PATH = process.env.DEPLOY_PATH;
module.exports = (env, argv) => {
const devMode = argv.mode !== 'production';
return {
context: __dirname, // to automatically find tsconfig.json
devServer: {
static: 'dist',
hot: true,
https: {
key: path.resolve(os.homedir(), '.localhost-ssl/localhost.key'),
cert: path.resolve(os.homedir(), '.localhost-ssl/localhost.pem'),
},
client: {
overlay: false
}
},
devtool: devMode ? 'eval-cheap-module-source-map' : 'source-map',
entry: './src/index.tsx',
mode: 'development',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'assets/index.[contenthash].js',
},
performance: { hints: false },
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
},
// This code coverage instrumentation should only be added when needed. It makes
// the code larger and slower
process.env.CODE_COVERAGE ? {
test: /\.[tj]sx?$/,
loader: '@jsdevtools/coverage-istanbul-loader',
options: { esModules: true },
enforce: 'post',
exclude: path.join(__dirname, 'node_modules'),
} : {},
{
test: /\.(sa|sc|le|c)ss$/i,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
esModule: false,
modules: {
// required for :import from scss files
// cf. https://github.com/webpack-contrib/css-loader#separating-interoperable-css-only-and-css-module-features
mode: 'icss',
}
}
},
'postcss-loader',
'sass-loader',
]
},
{
test: /\.(png|jpg|woff|woff2|eot|ttf)$/,
type: 'asset',
},
{ // disable svgo optimization for files ending in .nosvgo.svg
test: /\.nosvgo\.svg$/i,
loader: '@svgr/webpack',
options: {
svgo: false,
}
},
{
test: /\.svg$/i,
exclude: /\.nosvgo\.svg$/i,
oneOf: [
{
// Do not apply SVGR import in CSS files.
issuer: /\.(css|scss|less)$/,
type: 'asset',
},
{
issuer: /\.tsx?$/,
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [
{
// cf. https://github.com/svg/svgo/releases/tag/v2.4.0
name: 'preset-default',
params: {
overrides: {
// don't minify "id"s (i.e. turn randomly-generated unique ids into "a", "b", ...)
// https://github.com/svg/svgo/blob/master/plugins/cleanupIds.js
cleanupIds: { minify: false },
// leave <line>s, <rect>s and <circle>s alone
// https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js
convertShapeToPath: false,
// leave "stroke"s and "fill"s alone
// https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js
removeUnknownsAndDefaults: { defaultAttrs: false },
// leave viewBox alone
removeViewBox: false
}
}
}
]
}
}
}
]
}
]
},
resolve: {
extensions: [ '.ts', '.tsx', '.js' ],
},
stats: {
// suppress "export not found" warnings about re-exported types
warningsFilter: /export .* was not found in/,
},
plugins: [
new ESLintPlugin({
extensions: ['ts', 'tsx', 'js', 'jsx'],
}),
new MiniCssExtractPlugin({
filename: devMode ? 'assets/[name].css' : 'assets/[name].[contenthash].css',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.html',
favicon: 'src/public/favicon.ico',
publicPath: '.',
}),
...(DEPLOY_PATH ? [new HtmlWebpackPlugin({
filename: 'index-top.html',
template: 'src/index.html',
favicon: 'src/public/favicon.ico',
publicPath: DEPLOY_PATH
})] : []),
new CleanWebpackPlugin(),
]
};
};