Skip to content

Commit 01ee8d4

Browse files
committed
refactor: add additionalModuleDirs for the 'all' externals option
1 parent 4be0e8f commit 01ee8d4

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,12 @@ custom:
412412
413413
### Externals
414414
415-
The `externals` option takes a list of packages, `all`, or `all-monorepo`. By default this is set to `["knex", "sharp"]`.
415+
The `externals` option takes a list of packages or `all`. By default this is set to `["knex", "sharp"]`.
416416

417417
Packages listed in `externals` are ignored by Webpack. They are instead added in the `node_modules/` directory of the Lambda .zip file. These usually include npm packages that are not supported by Webpack.
418418

419419
The `all` option allows you to list all the packages in YOUR `node_modules/` directory as externals. This might be useful in cases where they are just too many to list. Or you are using something like [EJS](https://ejs.co) that implicitly requires a long list of packages that are not supported by Webpack.
420420

421-
The `all-monorepo` is useful when using Yarn workspaces (monorepo). It does the same as the `all` option, but also lists all the packages in the root node_modules directory (`../../node_modules/`) as externals.
422-
423421
Note that, adding a package to the `externals` list might make your Lambda .zip file larger. This is because the entire package directory is zipped. Instead of using Webpack to just include the code that is necessary. So it's advisable to avoid using the `all` option.
424422

425423
If you think we should add to the default list of externals, open a PR.

src/config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ module.exports = {
2626
// Set non Webpack compatible packages as externals
2727
// Or if we want to exclude all packages in the node_modules:
2828
// externals: "all"
29-
// Or if we want to exclude all packages in the root node_modules and the cwd node_modules (monorepo):
30-
// externals: "all-monorepo"
3129
externals: ["knex", "sharp"],
3230
// Set default file extensions to use the raw-loader with
3331
rawFileExtensions: ["pem", "txt"],

src/webpack.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ const ENABLE_CACHING = isLocal ? config.options.caching : false;
5454
// And add the forceExclude packages to it because they shouldn't be Webpacked
5555
const computedExternals = (
5656
externals === "all"
57-
? [nodeExternals()]
58-
: externals === "all-monorepo"
59-
? [nodeExternals({ additionalModuleDirs: [path.resolve(process.cwd(), "../../node_modules")] })]
60-
: externals
57+
? [nodeExternals({ additionalModuleDirs: [path.resolve(process.cwd(), "../../node_modules")] })]
58+
: externals
6159
).concat(forceExclude);
6260

6361
const extensions = [

0 commit comments

Comments
 (0)