Skip to content

Commit

Permalink
feat(server): add outputPath option in ChunkExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Nov 10, 2018
1 parent 18a719d commit aac26b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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,
}
Expand Down

0 comments on commit aac26b3

Please sign in to comment.