-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't error out when using Vite with RW v5 (#8040)
* Don't error out when using Vite * WIP vite prerendering * Generate globalThis exports * name space pages on globalThis * Update a couple of comments * Both auto-imported and manually imported pages now work with Vite * runPrerender: Clean up and restructure handling of vite/webpack dependant code * Cleanup * Make things more webpack friendly again * webpack: Generate chunk-references.json * ChunkReferencesPlugin: Fix spelling * Use data from new webpack plugin when prerendering * Fix path issue when prerendering nested pages with Vite * fix: change staticImports to prerender * fix substring matches for prerender tests --------- Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
- Loading branch information
Showing
11 changed files
with
260 additions
and
69 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
44 changes: 44 additions & 0 deletions
44
packages/internal/src/webpackPlugins/ChunkReferencesPlugin.ts
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,44 @@ | ||
import { Compiler, Chunk } from 'webpack' | ||
|
||
export class ChunkReferencesPlugin { | ||
static defaultOptions = { | ||
outputFile: 'chunk-references.json', | ||
} | ||
|
||
options: typeof ChunkReferencesPlugin.defaultOptions | ||
|
||
constructor(options = {}) { | ||
this.options = { ...ChunkReferencesPlugin.defaultOptions, ...options } | ||
} | ||
|
||
apply(compiler: Compiler) { | ||
compiler.hooks.emit.tap('ChunkReferencesPlugin', (compilation) => { | ||
const output: Array<{ | ||
name: string | ||
id: string | number | ||
files: Array<string> | ||
referencedChunks: Array<string | number> | ||
}> = [] | ||
|
||
compilation.chunks.forEach((chunk) => { | ||
if (chunk.id) { | ||
output.push({ | ||
name: chunk.name, | ||
id: chunk.id, | ||
files: Array.from(chunk.files).map((f) => '/' + f), | ||
referencedChunks: Array.from(chunk.getAllReferencedChunks()) | ||
.filter((c): c is Chunk & { id: string | number } => { | ||
return !!c.id && c.id !== chunk.id | ||
}) | ||
.map((referencedChunk) => referencedChunk.id), | ||
}) | ||
} | ||
}) | ||
|
||
compilation.emitAsset( | ||
this.options.outputFile, | ||
new compiler.webpack.sources.RawSource(JSON.stringify(output, null, 2)) | ||
) | ||
}) | ||
} | ||
} |
Oops, something went wrong.