Skip to content

Instantly share code, notes, and snippets.

@dotspencer
Last active December 24, 2018 23:03
Show Gist options
  • Save dotspencer/280545a8b9380d887d863d381fc41b29 to your computer and use it in GitHub Desktop.
Save dotspencer/280545a8b9380d887d863d381fc41b29 to your computer and use it in GitHub Desktop.
Setting up a private npm module using Gitlab

.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment