mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Node.js standalone mode + support for astro preview (#5056)
* wip * Deprecate buildConfig and move to config.build * Implement the standalone server * Stay backwards compat * Add changesets * correctly merge URLs * Get config earlier * update node tests * Return the preview server * update remaining tests * swap usage and config ordering * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/metal-pumas-walk.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/stupid-points-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Link to build.server config Co-authored-by: Fred K. Schott <fkschott@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
parent
3de985344a
commit
8debb790e0
2 changed files with 42 additions and 14 deletions
|
@ -17,16 +17,35 @@ export default function vercelEdge(): AstroIntegration {
|
|||
let _config: AstroConfig;
|
||||
let functionFolder: URL;
|
||||
let serverEntry: string;
|
||||
let needsBuildConfig = false;
|
||||
|
||||
return {
|
||||
name: PACKAGE_NAME,
|
||||
hooks: {
|
||||
'astro:config:setup': ({ config }) => {
|
||||
config.outDir = getVercelOutput(config.root);
|
||||
'astro:config:setup': ({ config, updateConfig }) => {
|
||||
needsBuildConfig = !config.build.client;
|
||||
const outDir = getVercelOutput(config.root);
|
||||
updateConfig({
|
||||
outDir,
|
||||
build: {
|
||||
serverEntry: 'entry.mjs',
|
||||
client: new URL('./static/', outDir),
|
||||
server: new URL('./functions/render.func/', config.outDir),
|
||||
}
|
||||
});
|
||||
},
|
||||
'astro:config:done': ({ setAdapter, config }) => {
|
||||
setAdapter(getAdapter());
|
||||
_config = config;
|
||||
serverEntry = config.build.serverEntry;
|
||||
functionFolder = config.build.server;
|
||||
},
|
||||
'astro:build:start': ({ buildConfig }) => {
|
||||
if(needsBuildConfig) {
|
||||
buildConfig.client = new URL('./static/', _config.outDir);
|
||||
serverEntry = buildConfig.serverEntry = 'entry.mjs';
|
||||
functionFolder = buildConfig.server = new URL('./functions/render.func/', _config.outDir);
|
||||
}
|
||||
},
|
||||
'astro:build:setup': ({ vite, target }) => {
|
||||
if (target === 'server') {
|
||||
|
@ -49,11 +68,6 @@ export default function vercelEdge(): AstroIntegration {
|
|||
};
|
||||
}
|
||||
},
|
||||
'astro:build:start': async ({ buildConfig }) => {
|
||||
buildConfig.serverEntry = serverEntry = 'entry.mjs';
|
||||
buildConfig.client = new URL('./static/', _config.outDir);
|
||||
buildConfig.server = functionFolder = new URL('./functions/render.func/', _config.outDir);
|
||||
},
|
||||
'astro:build:done': async ({ routes }) => {
|
||||
// Edge function config
|
||||
// https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions/configuration
|
||||
|
|
|
@ -19,16 +19,29 @@ export default function vercelEdge(): AstroIntegration {
|
|||
let buildTempFolder: URL;
|
||||
let functionFolder: URL;
|
||||
let serverEntry: string;
|
||||
let needsBuildConfig = false;
|
||||
|
||||
return {
|
||||
name: PACKAGE_NAME,
|
||||
hooks: {
|
||||
'astro:config:setup': ({ config }) => {
|
||||
config.outDir = getVercelOutput(config.root);
|
||||
'astro:config:setup': ({ config, updateConfig }) => {
|
||||
needsBuildConfig = !config.build.client;
|
||||
const outDir = getVercelOutput(config.root);
|
||||
updateConfig({
|
||||
outDir,
|
||||
build: {
|
||||
serverEntry: 'entry.js',
|
||||
client: new URL('./static/', outDir),
|
||||
server: new URL('./dist/', config.root),
|
||||
}
|
||||
});
|
||||
},
|
||||
'astro:config:done': ({ setAdapter, config }) => {
|
||||
setAdapter(getAdapter());
|
||||
_config = config;
|
||||
buildTempFolder = config.build.server;
|
||||
functionFolder = new URL('./functions/render.func/', config.outDir);
|
||||
serverEntry = config.build.serverEntry;
|
||||
|
||||
if (config.output === 'static') {
|
||||
throw new Error(`
|
||||
|
@ -37,11 +50,12 @@ export default function vercelEdge(): AstroIntegration {
|
|||
`);
|
||||
}
|
||||
},
|
||||
'astro:build:start': async ({ buildConfig }) => {
|
||||
buildConfig.serverEntry = serverEntry = 'entry.js';
|
||||
buildConfig.client = new URL('./static/', _config.outDir);
|
||||
buildConfig.server = buildTempFolder = new URL('./dist/', _config.root);
|
||||
functionFolder = new URL('./functions/render.func/', _config.outDir);
|
||||
'astro:build:start': ({ buildConfig }) => {
|
||||
if(needsBuildConfig) {
|
||||
buildConfig.client = new URL('./static/', _config.outDir);
|
||||
buildTempFolder = buildConfig.server = new URL('./dist/', _config.root);
|
||||
serverEntry = buildConfig.serverEntry = 'entry.js';
|
||||
}
|
||||
},
|
||||
'astro:build:done': async ({ routes }) => {
|
||||
// Copy necessary files (e.g. node_modules/)
|
||||
|
|
Loading…
Add table
Reference in a new issue