-
Notifications
You must be signed in to change notification settings - Fork 1
/
craco.config.js
91 lines (69 loc) · 2.76 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
const CSS_MODULE_LOCAL_IDENT_NAME = process.env.REACT_APP_ENV === "production" ? "_[hash:base64:5]" : "[local]_[hash:base64:5]";
const {ESLINT_MODES} = require('@craco/craco');
const path = require("path");
const fs = require("fs");
module.exports = function ({env}) {
return {
eslint: {
mode: ESLINT_MODES.file,
},
webpack: {
configure: (webpackConfig, {env, paths}) => {
const nodePath = `${paths.appNodeModules}${path.sep}`;
webpackConfig.module.rules = webpackConfig.module.rules.map(rule => {
let tsString = "file.ts";
if (rule.include && typeof rule.test === "object" && tsString.search(rule.test)) rule.include = [rule.include, nodePath];
if (rule.oneOf) {
rule.oneOf = rule.oneOf.map(one => {
if (one.include && typeof one.test === "object" && tsString.search(one.test)) one.include = [one.include, nodePath];
return one;
});
}
return rule;
});
return webpackConfig;
}
},
style: {
modules: {
camelCase: true,
localIdentName: CSS_MODULE_LOCAL_IDENT_NAME
},
sass: {
loaderOptions: (sassLoaderOptions, {env, paths}) => {
let prepend = "";
if (fs.existsSync(process.cwd() + "/src/styles/Global.scss")) {
prepend += fs.readFileSync(process.cwd() + "/src/styles/Global.scss");
}
sassLoaderOptions.prependData = prepend;
return sassLoaderOptions;
}
}
},
babel: {
loaderOptions: {
// Without this Babel caches module name resolution,
// e.g. wrongly identifies that CSS module does not exist.
cacheDirectory: false,
},
plugins: [
["babel-plugin-react-css-modules", {
filetypes: {
".scss": {
syntax: "postcss-scss",
// plugins: [
// "postcss-nested"
// ]
}
},
generateScopedName: CSS_MODULE_LOCAL_IDENT_NAME,
handleMissingStyleName: 'warn',
autoResolveMultipleImports: true,
attributeNames: {
activeStyleName: "activeClassName"
}
}]
]
},
};
}