Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/content/guides/author-libraries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,15 @@

## Externalize Lodash

Now, if you run `npx webpack`, you will find that a largish bundle is created. If you inspect the file, you'll see that lodash has been bundled along with your code. In this case, we'd prefer to treat `lodash` as a _peer dependency_. Meaning that the consumer should already have `lodash` installed. Hence you would want to give up control of this external library to the consumer of your library.
Now, if you run `npx webpack`, you will find that a largish bundle is created because `lodash` is bundled directly into your code.

Check failure on line 255 in src/content/guides/author-libraries.mdx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, lts/*)

Delete `·`

To prevent duplicate bundles, you can externalize `lodash` in your webpack config. How you classify `lodash` in your `package.json` then depends entirely on your library's architecture:

* **`peerDependencies`**: Use this if your library expects the host application to provide a single, shared instance of `lodash` at runtime (standard for UI components and singletons).

Check failure on line 259 in src/content/guides/author-libraries.mdx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, lts/*)

Replace `*` with `-`
* **`dependencies`**: Use this if you are not pre-bundling the library, and instead rely strictly on the consumer's package manager (npm/yarn) to resolve the dependency tree.

Check failure on line 260 in src/content/guides/author-libraries.mdx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, lts/*)

Replace `*` with `-`
* **`devDependencies`**: Use this if you are intentionally compiling a standalone, fully-bundled artifact where `lodash` is swallowed inside your final output file.

Check failure on line 261 in src/content/guides/author-libraries.mdx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, lts/*)

Replace `*` with `-`

For this guide's scenario, where we want to externalize the utility to prevent consumer bundle bloat, we will classify it as a `peerDependency`.

This can be done using the [`externals`](/configuration/externals/) configuration:

Expand Down
Loading