-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eca5497
commit f2b956e
Showing
7 changed files
with
53 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { relative } from 'path' | ||
import type { Compiler } from 'webpack' | ||
|
||
interface FileToChunkMap { | ||
[filePath: string]: string | ||
} | ||
|
||
export class FileToChunkRelationPlugin { | ||
apply (compiler: Compiler) { | ||
compiler.hooks.emit.tapAsync( | ||
'FileToChunkRelationPlugin', | ||
(compilation, callback) => { | ||
const fileToChunkMap: FileToChunkMap = {} | ||
|
||
// Iterate through all chunks | ||
for (const chunk of compilation.chunks) { | ||
// Get all modules for this chunk | ||
const chunkName = chunk.name || chunk.id as string | ||
for (const module of chunk.modulesIterable) { | ||
if (module.resource) { | ||
let source = relative(compiler.context, module.resource) | ||
if (!source.startsWith('.')) { | ||
source = `./${source}` | ||
} | ||
fileToChunkMap[source] = chunkName | ||
} | ||
} | ||
} | ||
|
||
// Add the map as a new asset | ||
const content = JSON.stringify(fileToChunkMap, null, 2) | ||
compilation.assets['chunkMap.json'] = { | ||
source: () => content, | ||
size: () => content.length | ||
} | ||
|
||
callback() | ||
} | ||
) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.