.babelrc
needs to be converted to a babel.config.js
file instead. This will allow webpack and babel to transpile the linked code and fix the "build failed SyntaxError unexpected token" problem. Further explanation: https://babeljs.io/docs/en/config-files#project-wide-configuration
Add the dependency into package.json
as follows (the v1.0
can be whatever tag you'd like):
"dependencies": {
"shared-react": "git+https://gitlab+deploy-token-###:[email protected]/<group-or-user>/<package-name>#v1.0",
...
}
You'll also need to generate a deploy token to fill in the placholders in the url above. Go to the repo in Gitlab and then select Settings > Repository > Deploy Token. Create a new token with the name "npm" and check the "react_repository" checkbox.
Also change webpack.config.js
to allow bundling and babel processing of the repo:
module: {
rules: [
{
test: /.js$/,
use: 'babel-loader',
exclude: /node_modules\/(?!(shared-react)\/).*/, // https://github.com/webpack/webpack/issues/2031#issuecomment-219040479
},
],
}
For development use npm link
in the private repo (shared-react) and then npm link shared-react
in the project that's using it as a dependency.