-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
86 lines (79 loc) · 3.17 KB
/
config-overrides.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
const path = require('path');
const webpack = require('webpack');
const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const { useBabelRc, override, addWebpackPlugin } = require('customize-cra');
const appPath = path.resolve(__dirname, 'apps/frontend/');
const appTsConfig = path.resolve(appPath, 'tsconfig.app.json');
module.exports = {
// The Webpack config to use when compiling your react app for development or production.
webpack: override(
useBabelRc(),
addWebpackPlugin(
new webpack.DefinePlugin({
process: {},
})
),
(config, env) => {
config.resolve.fallback = {
querystring: require.resolve('querystring-es3'),
url: false,
};
// Remove guard against importing modules outside of `src`.
// Needed for workspace projects.
config.resolve.plugins = config.resolve.plugins.filter((plugin) => !(plugin instanceof ModuleScopePlugin));
// Add support for importing workspace projects.
config.resolve.plugins.push(
new TsConfigPathsPlugin({
configFile: appTsConfig,
extensions: ['.ts', '.tsx', '.js', '.jsx'],
mainFields: ['module', 'main'],
})
);
// Replace include option for babel loader with exclude
// so babel will handle workspace projects as well.
config.module.rules[1].oneOf.forEach((r) => {
if (r.loader && r.loader.indexOf('babel') !== -1) {
r.exclude = /node_modules/;
delete r.include;
}
});
// Change default path of the config file
const forkTsCheckerWebpackPlugin = config.plugins.find(
(plugin) => plugin.constructor.name === 'ForkTsCheckerWebpackPlugin'
);
if (forkTsCheckerWebpackPlugin) {
forkTsCheckerWebpackPlugin.options.typescript.configFile = appTsConfig;
}
return config;
}
),
// The Jest config to use when running your jest tests - note that the normal rewires do not
// work here.
jest: function (config) {
// ...add your jest config customisation...
// Example: enable/disable some tests based on environment variables in the .env file.
if (!config.testPathIgnorePatterns) {
config.testPathIgnorePatterns = [];
}
if (!process.env.RUN_COMPONENT_TESTS) {
config.testPathIgnorePatterns.push('<rootDir>/src/components/**/*.test.js');
}
if (!process.env.RUN_REDUCER_TESTS) {
config.testPathIgnorePatterns.push('<rootDir>/src/reducers/**/*.test.js');
}
return config;
},
// The paths config to use when compiling your react app for development or production.
// https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/config/paths.js#L62-L81
paths: function (paths) {
paths.appPath = appPath;
paths.appBuild = path.resolve(__dirname, 'dist/apps/frontend');
paths.appPublic = path.resolve(appPath, 'public');
paths.appHtml = path.resolve(paths.appPublic, 'index.html');
paths.appSrc = path.resolve(paths.appPath, 'src');
paths.appIndexJs = path.resolve(paths.appSrc, 'index.tsx');
paths.appTsConfig = appTsConfig;
return paths;
},
};