This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
craco.config.js
97 lines (91 loc) · 3.29 KB
/
craco.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
const path = require("path")
// eslint-disable-next-line import/no-extraneous-dependencies
const HtmlWebpackPlugin = require("html-webpack-plugin")
const { APP_NAME, HTML_FILE_NAME } = process.env
const appFileName = APP_NAME || "App.tsx"
module.exports = {
babel: {
plugins: ["babel-plugin-styled-components"],
},
webpack: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
configure: (webpackConfig, { env, paths }) => {
const [parser, tsLoader, loadersObject, ...rules] = webpackConfig.module.rules
const { oneOf } = loadersObject
return {
...webpackConfig,
module: {
...webpackConfig.module,
rules: [
parser,
tsLoader,
{
oneOf: [
{
test: /\.svg$/,
use: [
{
loader: "svg-sprite-loader",
},
"svgo-loader",
],
},
...oneOf,
],
},
...rules,
],
},
plugins: HTML_FILE_NAME
? webpackConfig.plugins.map(plugin => {
if (plugin.constructor.name === "HtmlWebpackPlugin") {
if (env === "development") {
return new HtmlWebpackPlugin({
template: `./public/${HTML_FILE_NAME}`,
})
}
// non-development environments generally don't use HTML_FILE_NAME
// but i'm leaving the proper syntax in case we'll need it
return new HtmlWebpackPlugin({
inject: true,
template: `./public/${HTML_FILE_NAME}`,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
})
}
return plugin
})
: webpackConfig.plugins,
resolve: {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
App: path.resolve(__dirname, `./src/${appFileName}`),
"@/src": path.resolve(__dirname, "./src"),
utils: path.resolve(__dirname, "./src/utils"),
components: path.resolve(__dirname, "./src/components"),
domains: path.resolve(__dirname, "./src/domains"),
store: path.resolve(__dirname, "./src/store"),
types: path.resolve(__dirname, "./src/types"),
fonts: path.resolve(__dirname, "./src/fonts"),
hooks: path.resolve(__dirname, "./src/hooks"),
styles: path.resolve(__dirname, "./src/styles"),
vendor: path.resolve(__dirname, "./src/vendor"),
services: path.resolve(__dirname, "./src/services"),
"dynamic-imports": path.resolve(__dirname, "./src/dynamic-imports"),
},
},
}
},
},
}