Skip to content

Instantly share code, notes, and snippets.

@swallentin
Created May 9, 2018 12:03
Show Gist options
  • Save swallentin/9103e94630e2dfd0d8379af88f6f1a05 to your computer and use it in GitHub Desktop.
Save swallentin/9103e94630e2dfd0d8379af88f6f1a05 to your computer and use it in GitHub Desktop.
module.exports = function override(config, env) {
// NOTE: The current version of react-scripts-ts does not support yarn/lerna workspaces.
// As we're using TypeScript source code from a different module the TypeScript compilation can't locate source files outside of the current module,
// due to the fact that webpack is responsible for compiling TypeScript. The webpack config is "protected" as it's a part of the react-scripts-ts package.
// In short this hack find the ts-loader from the webpack config and removes the "include" property from the webpack ts-loader config.
// We do this hack to avoid having to eject the project from create-react-app or having to fork the react-script-ts repository and remove one line of code.
config.module.rules = config.module.rules.map(rule => {
var isOneOf = Object.keys(rule).findIndex(key => key === "oneOf") === 0;
if (isOneOf) {
var oneOf = rule.oneOf;
var indexOfTs = oneOf.findIndex(function(r) {
return String(r.test) === String(/\.(ts|tsx)$/);
});
var oldTsRule = oneOf[indexOfTs];
var tsRule = Object.assign(
{},
{
test: oldTsRule.test,
use: oldTsRule.use
}
);
var newOneOf = [].concat(
oneOf.slice(0, indexOfTs),
tsRule,
oneOf.slice(indexOfTs + 1, oneOf.length)
);
rule.oneOf = newOneOf;
}
return rule;
});
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment