diff --git a/packages/server/README.md b/packages/server/README.md index 97421b53d..d8aa2fa87 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 291c21fac..7165f34ef 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, }