-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
98 lines (91 loc) · 3.45 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
/* eslint-disable @typescript-eslint/no-var-requires */
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ForkTSCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CracoEsbuildPlugin = require('craco-esbuild');
const webpack = require('webpack');
module.exports = {
plugins: [
{
plugin: CracoEsbuildPlugin,
options: {
esbuildLoaderOptions: {
// Optional. Defaults to auto-detect loader.
loader: 'tsx',
target: 'es2020',
},
esbuildMinimizerOptions: {
// Optional. Defaults to:
target: 'es2020',
css: true, // if true, OptimizeCssAssetsWebpackPlugin will also be replaced by esbuild.
},
skipEsbuildJest: true, // Optional. Set to true if you want to use babel for jest tests,
},
},
],
eslint: { enable: false },
webpack: {
configure: (config) => {
// Remove ModuleScopePlugin which throws when we try to import something
// outside of src/.
config.resolve.plugins.pop();
// Resolve the path aliases.
config.resolve.plugins.push(new TsconfigPathsPlugin());
config.resolve.fallback = {
fs: false,
tty: false,
constants: false,
path: false,
child_process: false,
http: false,
https: false,
os: false,
url: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
};
// Let Babel compile outside of src/.
const oneOfRule = config.module.rules.find((rule) => rule.oneOf);
const tsRule = oneOfRule.oneOf.find((rule) => rule.test.toString().includes('ts|tsx'));
tsRule.include = undefined;
tsRule.exclude = /node_modules/;
config.module.rules.push({
test: /\.wasm$/,
type: 'javascript/auto',
});
// Use raw loader when importing ".md" files
config.module.rules.push({
test: /\.md$/,
type: 'asset/source',
});
return config;
},
plugins: {
remove: [
// This plugin is too old and causes problems in monorepos.
'ForkTsCheckerWebpackPlugin',
],
add: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
// Use newer version of ForkTSCheckerWebpackPlugin to type check files across the monorepo.
new ForkTSCheckerWebpackPlugin({
issue: {
// The exclude rules are copied from CRA.
exclude: [
{
file: '**/src/**/__tests__/**',
},
{
file: '**/src/**/?(*.)(spec|test).*',
},
{
file: '**/src/setupTests.*',
},
],
},
}),
],
},
},
};