Skip to content

Commit e31a10c

Browse files
authored
Speed up windows packaging (#347)
Speed up windows packaging
2 parents 6b5e0e2 + a018f5d commit e31a10c

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ custom:
174174
strip: false
175175
```
176176

177-
### Lamba Layer
177+
### Lambda Layer
178178
Another method for dealing with large dependencies is to put them into a
179179
[Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html).
180180
Simply add the `layer` option to the configuration.
@@ -439,6 +439,35 @@ zipinfo .serverless/xxx.zip
439439
```
440440
(If you can't see the library, you might need to adjust your package include/exclude configuration in `serverless.yml`.)
441441

442+
## Optimising packaging time
443+
444+
If you wish to exclude most of the files in your project, and only include the source files of your lambdas and their dependencies you may well use an approach like this:
445+
446+
```yaml
447+
package:
448+
individually: false
449+
include:
450+
- "./src/lambda_one/**"
451+
- "./src/lambda_two/**"
452+
exclude:
453+
- "**"
454+
```
455+
456+
This will be very slow. Serverless adds a default `"**"` include. If you are using the `cacheLocation` parameter to this plugin, this will result in all of the cached files' names being loaded and then subsequently discarded because of the exclude pattern. To avoid this happening you can add a negated include pattern, as is observed in https://github.com/serverless/serverless/pull/5825.
457+
458+
Use this approach instead:
459+
460+
```yaml
461+
package:
462+
individually: false
463+
include:
464+
- "!./**"
465+
- "./src/lambda_one/**"
466+
- "./src/lambda_two/**"
467+
exclude:
468+
- "**"
469+
```
470+
442471
## Contributors
443472
* [@dschep](https://github.com/dschep) - Lead developer & maintainer
444473
* [@azurelogic](https://github.com/azurelogic) - logging & documentation fixes

lib/pip.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,9 @@ function installAllRequirements() {
610610
!fse.existsSync(symlinkPath) &&
611611
reqsInstalledAt != symlinkPath
612612
) {
613-
// Windows can't symlink so we have to copy on Windows,
614-
// it's not as fast, but at least it works
613+
// Windows can't symlink so we have to use junction on Windows
615614
if (process.platform == 'win32') {
616-
fse.copySync(reqsInstalledAt, symlinkPath);
615+
fse.symlink(reqsInstalledAt, symlinkPath, 'junction');
617616
} else {
618617
fse.symlink(reqsInstalledAt, symlinkPath);
619618
}

0 commit comments

Comments
 (0)