Created
November 28, 2020 23:09
-
-
Save hypeJunction/1a3b48ba25cda091da8774d2407fa1b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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