-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
85 lines (80 loc) · 2.93 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
const craco = require("@craco/craco")
const path = require("path")
const paths = require("react-scripts/config/paths")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const StyleLintPlugin = require("stylelint-webpack-plugin")
const appPackageJson = require(paths.appPackageJson)
module.exports = {
style: {
modules: {
localIdentName: "[local]_[sha256:hash:base64:6]", // Maybe add [folter] for folder name
},
},
webpack: {
alias: {
// Alias ~ to src, e.g ~/components/whatever
"~": path.join(__dirname, "src"),
},
plugins: {
remove: ["HtmlWebpackPlugin"],
add: [
// Use non-blocking script load
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
scriptLoading: "defer",
...craco.whenProd(() => ({
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
})),
}),
// Add stylelint plugin
new StyleLintPlugin({
configBasedir: __dirname,
context: path.resolve(__dirname, "src"),
files: ["**/*.scss", "**/*.sass", "**/*.css"],
}),
],
},
resolve: {
mainFields: ["module", "main", "browser"],
},
configure: (webpackConfig) => {
const chunkLoadingGlobal = appPackageJson.name.replace(/-[A-z]/u, (str) =>
str[1].toUpperCase(),
)
webpackConfig.plugins[webpackConfig.plugins.length - 1].options.baseConfig.extends = []
return {
...webpackConfig,
module: {
...webpackConfig.module,
rules: [
...webpackConfig.module.rules,
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
],
},
output: {
...webpackConfig.output,
chunkLoadingGlobal: `wpJsonp${chunkLoadingGlobal[0].toUpperCase()}${chunkLoadingGlobal.slice(
1,
)}`,
},
}
},
},
}