altack / nx-bundlefy

Nx executor to ensure that all the buildable dependencies of a publishable library are part of the final bundle
MIT License
8 stars 7 forks source link

nx-bundlefy

Nx executor to ensure that all the buildable dependencies of a publishable library are part of the final bundle.

Installation

npm install -D @altack/nx-bundlefy

Also make sure to install the required peer dependencies:

npm install -D @nrwl/js @nrwl/devkit @nrwl/workspace validate-npm-package-name

Configuration

To use the executor, make sure to adjust your publishable library's project.json:

{
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/publishable-library/src",
  "targets": {
    "bundlefy": {
      "executor": "@altack/nx-bundlefy:run",
      "configurations": {},
      "dependsOn": ["build"],
      "outputs": ["{options.outputFile}"]
    },
    "build": {
      ...
    }
  }
}

Also make sure that buildable & publishable libraries are created using the --import-path modifier.

nx g lib my-library --buildable --import-path @org/my-library

Run the executor

This will ensure that all the buildable libraries are bundled as part of the library build

nx run publishable-library:bundlefy

Further reading

For a more detailed explanation, see this Stack Overflow question and the open issue in the Nx's repository