From aac26b36788793f94910d7f7e35ea812b6d6eed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Sat, 10 Nov 2018 18:57:24 +0100 Subject: [PATCH] feat(server): add outputPath option in ChunkExtractor --- packages/server/README.md | 1 + packages/server/src/ChunkExtractor.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/server/README.md b/packages/server/README.md index 97421b53..d8aa2fa8 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -193,6 +193,7 @@ Used to collect chunks server-side and get them as script tags or script element | `options.statsFile` | Stats file path generated using `@loadable/webpack-plugin`. | | `options.stats` | Stats generated using `@loadable/webpack-plugin`. | | `options.entrypoints` | Webpack entrypoints to load (default to `["main"]`). | +| `options.outputPath` | Optional output path (only for `requireEntrypoint`). | You must specify either `statsFile` or `stats` to be able to use `ChunkExtractor`. diff --git a/packages/server/src/ChunkExtractor.js b/packages/server/src/ChunkExtractor.js index 291c21fa..7165f34e 100644 --- a/packages/server/src/ChunkExtractor.js +++ b/packages/server/src/ChunkExtractor.js @@ -77,8 +77,9 @@ function joinTags(tags) { } class ChunkExtractor { - constructor({ statsFile, stats, entrypoints = ['main'] } = []) { + constructor({ statsFile, stats, entrypoints = ['main'], outputPath } = []) { this.stats = stats || smartRequire(statsFile) + this.outputPath = outputPath || this.stats.outputPath this.statsFile = statsFile this.entrypoints = Array.isArray(entrypoints) ? entrypoints : [entrypoints] this.chunks = [] @@ -101,7 +102,7 @@ class ChunkExtractor { scriptType: extensionToScriptType(path.extname(filename).toLowerCase()), chunk, url: this.resolvePublicUrl(filename), - path: path.join(this.stats.outputPath, filename), + path: path.join(this.outputPath, filename), type, linkType, }