Skip to content

Commit

Permalink
Merge pull request #264 from erikt9/no_chunk_assets
Browse files Browse the repository at this point in the history
Issue #204 Add support for including assets not in any chunk
  • Loading branch information
ztoben committed Sep 22, 2020
2 parents 644f8cb + 3b30aa1 commit 403c3b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -19,6 +19,7 @@ function AssetsWebpackPlugin (options) {
useCompilerPath: false,
fileTypes: ['js', 'css'],
includeAllFileTypes: true,
includeFilesWithoutChunk: false,
keepInMemory: false,
integrity: false
}, options)
Expand Down Expand Up @@ -66,16 +67,19 @@ AssetsWebpackPlugin.prototype = {

if (self.options.entrypoints) {
chunks = Object.keys(stats.entrypoints)
if (self.options.includeFilesWithoutChunk) {
chunks.push('') // push "unnamed" chunk
}
} else {
chunks = Object.keys(stats.assetsByChunkName)
chunks.push('') // push "unamed" chunk
chunks.push('') // push "unnamed" chunk
}

const output = chunks.reduce(function (chunkMap, chunkName) {
let assets

if (self.options.entrypoints) {
assets = stats.entrypoints[chunkName].assets
assets = chunkName ? stats.entrypoints[chunkName].assets : stats.assets
} else {
assets = chunkName ? stats.assetsByChunkName[chunkName] : stats.assets
}
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Expand Up @@ -307,6 +307,16 @@ If the 'entrypoints' option is given, the output will be limited to the entrypoi
new AssetsPlugin({entrypoints: true})
```

#### `includeFilesWithoutChunk`

Optional. `false` by default.

When set and `entrypoints` is set true, will output any files that are part of the unnamed chunk to an additional unnamed ("") entry.

```js
new AssetsPlugin({includeFilesWithoutChunk: true})
```

### Using in multi-compiler mode

If you use webpack multi-compiler mode and want your assets written to a single file,
Expand Down

0 comments on commit 403c3b2

Please sign in to comment.