Skip to content

Commit f77624b

Browse files
committed
docs: correct lodash dependency usage in authoring libraries guide
1 parent 800eb36 commit f77624b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/content/guides/author-libraries.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ The basic project structure would look like this:
3333
+ └── ref.json
3434
```
3535

36-
Initialize the project with npm, then install `webpack`, `webpack-cli` and `lodash`:
36+
Initialize the project with npm, then install `webpack` and `webpack-cli` as development dependencies, and `lodash` as a runtime dependency:
3737

3838
```bash
3939
npm init -y
40-
npm install --save-dev webpack webpack-cli lodash
40+
npm install --save-dev webpack webpack-cli
41+
npm install lodash
4142
```
4243

43-
We install `lodash` as `devDependencies` instead of `dependencies` because we don't want to bundle it into our library, or our library could be easily bloated.
44+
We install `lodash` as a `dependency` because it is required at runtime by our library. However, to prevent our library from becoming bloated, we will configure webpack to treat it as an external module rather than bundling it.
4445

4546
**src/ref.json**
4647

@@ -252,7 +253,7 @@ T> Note that the `library` setup is tied to the `entry` configuration. For most
252253
253254
## Externalize Lodash
254255
255-
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.
256+
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. Since `lodash` is listed as a `dependency` in your `package.json`, package managers will install it automatically for consumers of your library. This means you can rely on the consumer's environment to provide it, rather than bundling it directly.
256257
257258
This can be done using the [`externals`](/configuration/externals/) configuration:
258259

0 commit comments

Comments
 (0)