Добавить customize-cra
и react-app-rewired
пакеты
Добавить к ссылке tsconfig.json
:
{
"compilerOptions": {
...
"composite": true,
"declaration": true,
"declarationMap": true
}
Создать
tsconfig.paths.json
в базовом проекте
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@alias/*": ["..relative/to/base/url/path/*"]
}
}
}
В
tsconfig.json
добавить такие строки:
{
"extends": "./tsconfig.paths.json",
"compilerOptions": {
"baseUrl": "<the same value as in paths file>"
},
"references": [
{ "path": "../relative/path/to/referenced/project/tsconfig.json/file" }
]
Создать
config-override.js
файл в проекте root
const { override, removeModuleScopePlugin, getBabelLoader, addWebpackAlias } = require("customize-cra");
const path = require("path");
const fs = require('fs');
const updateAliases = (config) => {
const aliases = {
"@alias": ["absolute/path/to/base/url"]
};
return addWebpackAlias(aliases)(config);
};
const updateIncludes = (config) => {
const loader = getBabelLoader(config, false);
const commonPath = path.normalize(path.join(process.cwd(), "../relative/path/to/referenced/project/tsconfig.json/file")).replace(/\\/g, "\\");
loader.include = [loader.include, commonPath];
return config;
};
module.exports = override(
updateAliases,
updateIncludes,
removeModuleScopePlugin()
);
Используйте
react-app-rewired
вместо
react-scripts
в
package.json
Примечание : это модифицированный код, поэтому могут потребоваться некоторые незначительные изменения.