Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created November 28, 2020 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hypeJunction/1a3b48ba25cda091da8774d2407fa1b4 to your computer and use it in GitHub Desktop.
Save hypeJunction/1a3b48ba25cda091da8774d2407fa1b4 to your computer and use it in GitHub Desktop.
// config-overrides.js
const fs = require('fs');
const path = require('path');
const {
override,
removeModuleScopePlugin,
babelInclude,
addWebpackAlias,
} = require('customize-cra');
// We can read package.json of the symlinked package
const symlinkedPackageJson = fs.readFileSync(path.join(__dirname, 'node_modules', '@me/my-local-package', 'package.json')).toString();
const { peerDependencies } = JSON.parse(symlinkedPackageJson);
// We can build aliases for all peer depencies and pointing them to node_modules inside our current app
const aliases = Object.keys(peerDependencies).reduce((acc, cur) => {
acc[cur] = fs.realpathSync(path.join(__dirname, 'node_modules', cur));
return acc;
}, {});
module.exports = override(
removeModuleScopePlugin(),
babelInclude([
path.resolve(path.join(__dirname, 'src')),
fs.realpathSync(path.join(__dirname, 'node_modules/@me/my-local-package/src')),
]),
// Define the aliases
addWebpackAlias({
...aliases,
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment