Skip to content

Commit 0de12ac

Browse files
authored
Merge pull request #269 from dror-weiss/feature/generate-stats-files
Add `generageStatsFiles` flag
2 parents be33d11 + 74ccae7 commit 0de12ac

File tree

37 files changed

+991
-21367
lines changed

37 files changed

+991
-21367
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ You can [read more about this over on Serverless Stack](https://serverless-stack
5858
- [Support for pem, txt, and other raw files](#support-for-pem-txt-and-other-raw-files)
5959
- [Externals](#externals)
6060
- [Externals vs forceExclude](#externals-vs-forceexclude)
61+
- [Generating a stats file](#generating-stats-files)
6162
- [Support](#support)
6263
- [Running Locally](#running-locally)
6364

@@ -105,6 +106,7 @@ custom:
105106
concurrency: 5 # Set desired concurrency, defaults to the number of available cores
106107
stats: false # Don't print out any Webpack output
107108
linting: true # Enable linting as a part of the build process
109+
generateStatsFiles: false # Creates stats files that could be used for bundle analyzing, more below
108110
esbuild: false # Use esbuild-loader instead of babel or ts for faster builds
109111
disableForkTsChecker: false # Disable the ForkTsChecker plugin, more below
110112
tsConfig: "tsconfig.json" # Path to your 'tsconfig.json', if it's not in the root
@@ -454,6 +456,12 @@ The three options (`externals`, `forceExclude`, and `excludeFiles`) look similar
454456

455457
These are a glob of files that can be excluded from the function resolution. This happens when you have multiple files that are in the same directory and Serverless Framework tries to use them as a function handler. For example, if you have a `index.js` and a `index.test.js` and your function is pointing to `index`, you'll get a warning saying, `WARNING: More than one matching handlers found for index. Using index.js`. To fix this, use `excludeFiles: **/*.test.js`.
456458

459+
### Generating stats files
460+
461+
Use the `generateStatsFiles` option if you want to analyze your bundle size. This option, if set to `true`, will
462+
enable the generation of a `bundle_stats.json` and a `bundle_stats.html` in the output directory, using the
463+
[webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) plugin.
464+
457465
## Support
458466

459467
- Open a [new issue](https://github.com/AnomalyInnovations/serverless-bundle/issues/new) if you've found a bug or have some suggestions.

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ function applyWebpackOptions(custom, config) {
3232
packagePath: path.relative(
3333
config.servicePath,
3434
pkgUp.sync({ cwd: config.servicePath })
35-
),
35+
)
3636
},
3737
excludeFiles: config.options.excludeFiles,
38+
excludeRegex: /bundle_stats\.(html|json)$/,
39+
keepOutputDirectory: config.options.generateStatsFiles
3840
};
3941
}
4042

0 commit comments

Comments
 (0)