-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move renderers to their own plugin (#7166)
- Loading branch information
Showing
7 changed files
with
90 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Move generation of renderers code into their own file |
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,66 @@ | ||
import type { Plugin as VitePlugin } from 'vite'; | ||
import { addRollupInput } from '../add-rollup-input.js'; | ||
import type { BuildInternals } from '../internal.js'; | ||
import type { AstroBuildPlugin } from '../plugin'; | ||
import type { StaticBuildOptions } from '../types'; | ||
|
||
export const RENDERERS_MODULE_ID = '@astro-renderers'; | ||
export const RESOLVED_RENDERERS_MODULE_ID = `\0${RENDERERS_MODULE_ID}`; | ||
|
||
let inputs: Set<string> = new Set(); | ||
export function vitePluginRenderers( | ||
opts: StaticBuildOptions, | ||
_internals: BuildInternals | ||
): VitePlugin { | ||
return { | ||
name: '@astro/plugin-renderers', | ||
|
||
options(options) { | ||
return addRollupInput(options, [RENDERERS_MODULE_ID]); | ||
}, | ||
|
||
resolveId(id) { | ||
if (id === RENDERERS_MODULE_ID) { | ||
return RESOLVED_RENDERERS_MODULE_ID; | ||
} | ||
}, | ||
|
||
async load(id) { | ||
if (id === RESOLVED_RENDERERS_MODULE_ID) { | ||
if (opts.settings.renderers.length > 0) { | ||
const imports: string[] = []; | ||
const exports: string[] = []; | ||
let i = 0; | ||
let rendererItems = ''; | ||
|
||
for (const renderer of opts.settings.renderers) { | ||
const variable = `_renderer${i}`; | ||
imports.push(`import ${variable} from '${renderer.serverEntrypoint}';`); | ||
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`; | ||
i++; | ||
} | ||
|
||
exports.push(`export const renderers = [${rendererItems}];`); | ||
|
||
return `${imports.join('\n')}\n${exports.join('\n')}`; | ||
} | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
export function pluginRenderers( | ||
opts: StaticBuildOptions, | ||
internals: BuildInternals | ||
): AstroBuildPlugin { | ||
return { | ||
build: 'ssr', | ||
hooks: { | ||
'build:before': () => { | ||
return { | ||
vitePlugin: vitePluginRenderers(opts, internals), | ||
}; | ||
}, | ||
}, | ||
}; | ||
} |
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