-
Notifications
You must be signed in to change notification settings - Fork 19
/
craco.config.js
98 lines (93 loc) · 2.41 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
98
const CracoEsbuildPlugin = require('craco-esbuild');
const path = require('path');
const {
addAfterLoader,
addAfterLoaders,
addBeforeLoader,
addAfterAssetModule,
assetModuleByName,
getLoader,
getLoaders,
removeLoader,
loaderByName,
throwUnexpectedConfigError,
} = require('@craco/craco');
const { ProvidePlugin } = require('webpack');
module.exports = {
webpack: {
alias: {
components: path.resolve(__dirname, 'src/components'),
css: path.resolve(__dirname, 'src/css')
},
configure: (webpackConfig, { env, paths }) => {
const strReplaceLoader = {
// test: /constants\/index\.js$/,
test: /\.js/,
loader: require.resolve('string-replace-loader'),
include: [path.resolve(__dirname, 'src/constants')],
options: {
multiple: [
{
search: '@@API',
replace(match, p1, offset, string) {
const replacement =
'/data-research/consumer-complaints/search/api/v1/';
console.log(
`Replaced "${match}" in file "${this.resource}" with "${replacement}.`,
);
return replacement;
},
flags: 'g',
//strict: true,
},
],
},
};
webpackConfig.ignoreWarnings = [
function ignoreSourcemapsloaderWarnings(warning) {
return (
warning.module &&
warning.module.resource.includes('node_modules') &&
warning.details &&
warning.details.includes('source-map-loader')
);
},
];
addBeforeLoader(
webpackConfig,
loaderByName('babel-loader'),
strReplaceLoader,
);
//
return webpackConfig;
},
plugins: [
new ProvidePlugin({
React: 'react',
}),
],
},
plugins: [
{
plugin: CracoEsbuildPlugin,
options: {
esbuildLoaderOptions: {
// Optional. Defaults to auto-detect loader.
loader: 'jsx', // Set the value to 'tsx' if you use typescript
target: 'es2015',
},
skipEsbuildJest: true, // Optional. Set to true if you want to use babel for jest tests,
},
},
],
style: {
sass: {
loaderOptions: {
api: 'modern',
sassOptions: {
loadPaths: ['node_modules', 'src']
}
}
}
}
};