-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathbase.config.js
More file actions
185 lines (170 loc) · 3.84 KB
/
base.config.js
File metadata and controls
185 lines (170 loc) · 3.84 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { join } = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const outputConfig = {
destPath: './dist',
};
// Entry points
// https://webpack.js.org/concepts/entry-points/
const entryConfig = ['./src/index.tsx', './src/assets/stylesheets/app.scss'];
// Copy files from src to dist
// https://webpack.js.org/plugins/copy-webpack-plugin/
const copyPluginPatterns = {
patterns: [
{ from: './src/assets/images', to: 'images' },
{ from: './src/assets/fonts', to: 'fonts' },
{ from: './src/assets/vendor', to: 'js' },
],
};
// Dev server setup
// https://webpack.js.org/configuration/dev-server/
const devServer = {
static: {
directory: path.join(__dirname, outputConfig.destPath),
},
historyApiFallback: true,
};
// SCSS compile
const scssConfig = {
destFileName: 'css/app.min.css',
};
// Production terser config options
// https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions
const terserPluginConfig = {
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
},
},
};
const aliasItems = {
'@src': join(__dirname, '../src'),
'@images': join(__dirname, '../src/images'),
'@styles': join(__dirname, '../src/styles'),
'@components': join(__dirname, '../src/components'),
};
const experiments = {
backCompat: false,
};
const rules = [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|svg)$/i,
type: 'javascript/auto',
loader: 'file-loader',
options: {
publicPath: '../',
name: '[path][name].[ext]',
context: path.resolve(__dirname, 'src/assets'),
emitFile: false,
},
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: 'javascript/auto',
exclude: /images/,
loader: 'file-loader',
options: {
publicPath: '../',
context: path.resolve(__dirname, 'src/assets'),
name: '[path][name].[ext]',
emitFile: false,
},
},
{
test: /miniscript.*\.wasm$/,
type: 'webassembly/sync',
},
];
const devRules = [
...rules,
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: [
// We're in dev and want HMR, SCSS is handled in JS
// In production, we want our css as files
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['postcss-preset-env']],
},
},
},
'sass-loader',
],
},
];
const prodRules = [
...rules,
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['postcss-preset-env']],
},
},
},
'sass-loader',
],
},
];
const devPlugins = [
new HtmlWebpackPlugin({
template: './src/index.html',
inject: true,
minify: false,
}),
new CopyPlugin(copyPluginPatterns),
];
const prodPlugins = [
new CleanWebpackPlugin(),
new CopyPlugin(copyPluginPatterns),
new MiniCssExtractPlugin({ filename: scssConfig.destFileName }),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: true,
minify: false,
}),
];
const resolveFallback = {
'process/browser': require.resolve('process/browser'),
};
module.exports = {
aliasItems,
copyPluginPatterns,
devServer,
entryConfig,
experiments,
outputConfig,
scssConfig,
terserPluginConfig,
devRules,
prodRules,
devPlugins,
prodPlugins,
resolveFallback,
};