question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Library multiple entry points

See original GitHub issue

Exactly the same as that issue that was closed by the bot but without any solution.

Description

I want to have the option to publish a library with two endpoints. i.e.

@my-scope/testing/e2e
@my-scope/testing/unit-tests

Where in the e2e I want to include Cypress utils (with Cypress dependency) and in unit-tests I want to include Jasmine utils (with Jasmine dependency)

Motivation

Currently, I can’t do the above as both Cypress & Jasmine have an expect global method, so when I import @my-scope/testing it imports both dependencies.

And tree-shaking in general.

  • worth mentioning - I’m using NX to generate libraries monorepo, and I’m using the libraries in external projects (not inside the monorepo, that’s why I can’t start it as an Angular-monorepo and only use the basic Node approach).

Suggested Implementation

Same as ng-packager: create a package.json (name, dependencies) under the needed library with index.ts as an entry-point.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:15
  • Comments:52 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
EladBezalelcommented, Apr 3, 2022

Managed to workaround it by doing this:

under my lib directory i created a rollup config that extends nx one

const nrwlConfig = require('@nrwl/react/plugins/bundle-rollup');

module.exports = config => {
  const nxConfig = nrwlConfig(config);
  
  if (nxConfig.output.format === 'esm') {
    nxConfig.input = {
      index: nxConfig.input,
      utils: join(__dirname, './src/utils/index.ts'),
    };
  }

  return nxConfig;
};

i do this only for esm as i don’t need it for the umd build

in libs/mylib/package.json i added

"exports": {
  ".": "./index.esm.js",
  "./utils": "./utils/utils.esm.js"
},
"typesVersions": {
  "*": {
    "utils": [
      "utils/index"
    ]
  }
}

and in workspace.json under the lib build script:

"build": {
  "executor": "@nrwl/web:rollup",
  "options": {
    "rollupConfig": "libs/mylib/rollup.config.js",
  }
},

and in order for it to work in the workspace as well, add in tsconfig.base.json

{
  "compilerOptions": {
    "paths": {      
      "@my-scope/mylib/utils": ["libs/mylib/src/utils/index.ts"],
    }
  },
}

Hope it helps 🙏

8reactions
fguittoncommented, Feb 14, 2022

Not stale 🎈

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building an Angular Library with multiple entry points | Articles
An Angular library lets you share code between multiple projects. For a larger library it's recommended to use subentry points. We'll build a ......
Read more >
Build a JavaScript library with multiple entry points using Vite3
In this post, I'll show how you can create a lib with multiple entry points (sub-modules) using Vite 3.
Read more >
Creating Secondary Entry Points for your Angular Library
In this article, we will take a look at how we can utilise ng-packagr secondary entry points to split our Angular Library even...
Read more >
Why and how to use secondary entrypoints in your Angular ...
By adding secondary entrypoints, we basically split our Angular libraries into multiple chunks, just like Angular Material does. A Example:.
Read more >
webpack - Dynamic library option with multi entry points
From webpack 3.1.0, you can export multi configurations from webpack.config.js. So you can try the following: module.exports = [ { entry: ".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found