Skip to content

Instantly share code, notes, and snippets.

@stevemu
Last active May 5, 2022 14:39
Show Gist options
  • Save stevemu/53c5006c5e66fc277dea1454eb6acdb4 to your computer and use it in GitHub Desktop.
Save stevemu/53c5006c5e66fc277dea1454eb6acdb4 to your computer and use it in GitHub Desktop.
react-app-rewired config-overrides.js for referencing folders in adjacent folder https://github.com/facebook/create-react-app/issues/9127
const { override, addWebpackAlias } = require('customize-cra');
const path = require('path');
const overridePath = (webpackConfig) => {
const oneOfRule = webpackConfig.module.rules.find((rule) => rule.oneOf);
if (oneOfRule) {
const tsxRule = oneOfRule.oneOf.find(
(rule) => rule.test && rule.test.toString().includes('tsx')
);
const newIncludePaths = [
// relative path to my yarn workspace library
path.resolve(__dirname, '../common'),
];
if (tsxRule) {
if (Array.isArray(tsxRule.include)) {
tsxRule.include = [...tsxRule.include, ...newIncludePaths];
} else {
tsxRule.include = [tsxRule.include, ...newIncludePaths];
}
}
}
return webpackConfig;
};
module.exports = override(
// this is for path alais
addWebpackAlias({
api: path.resolve(__dirname, 'src/api'),
utils: path.resolve(__dirname, 'src/utils'),
}),
overridePath
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment