@astrojs/cloudflare
Advanced tools
Comparing version 3.0.0 to 3.1.0
# @astrojs/cloudflare | ||
## 3.1.0 | ||
### Minor Changes | ||
- [#5056](https://github.com/withastro/astro/pull/5056) [`e55af8a23`](https://github.com/withastro/astro/commit/e55af8a23233b6335f45b7a04b9d026990fb616c) Thanks [@matthewp](https://github.com/matthewp)! - # New build configuration | ||
The ability to customize SSR build configuration more granularly is now available in Astro. You can now customize the output folder for `server` (the server code for SSR), `client` (your client-side JavaScript and assets), and `serverEntry` (the name of the entrypoint server module). Here are the defaults: | ||
```js | ||
import { defineConfig } from 'astro/config'; | ||
export default defineConfig({ | ||
output: 'server', | ||
build: { | ||
server: './dist/server/', | ||
client: './dist/client/', | ||
serverEntry: 'entry.mjs', | ||
}, | ||
}); | ||
``` | ||
These new configuration options are only supported in SSR mode and are ignored when building to SSG (a static site). | ||
## Integration hook change | ||
The integration hook `astro:build:start` includes a param `buildConfig` which includes all of these same options. You can continue to use this param in Astro 1.x, but it is deprecated in favor of the new `build.config` options. All of the built-in adapters have been updated to the new format. If you have an integration that depends on this param we suggest upgrading to do this instead: | ||
```js | ||
export default function myIntegration() { | ||
return { | ||
name: 'my-integration', | ||
hooks: { | ||
'astro:config:setup': ({ updateConfig }) => { | ||
updateConfig({ | ||
build: { | ||
server: '...', | ||
}, | ||
}); | ||
}, | ||
}, | ||
}; | ||
} | ||
``` | ||
## 3.0.0 | ||
@@ -4,0 +48,0 @@ |
@@ -22,2 +22,3 @@ import esbuild from "esbuild"; | ||
let _buildConfig; | ||
let needsBuildConfig = false; | ||
const isModeDirectory = (args == null ? void 0 : args.mode) === "directory"; | ||
@@ -27,5 +28,16 @@ return { | ||
hooks: { | ||
"astro:config:setup": ({ config, updateConfig }) => { | ||
needsBuildConfig = !config.build.client; | ||
updateConfig({ | ||
build: { | ||
client: new URL("./static/", config.outDir), | ||
server: new URL("./", config.outDir), | ||
serverEntry: "_worker.js" | ||
} | ||
}); | ||
}, | ||
"astro:config:done": ({ setAdapter, config }) => { | ||
setAdapter(getAdapter(isModeDirectory)); | ||
_config = config; | ||
_buildConfig = config.build; | ||
if (config.output === "static") { | ||
@@ -38,8 +50,2 @@ throw new Error(` | ||
}, | ||
"astro:build:start": ({ buildConfig }) => { | ||
_buildConfig = buildConfig; | ||
buildConfig.client = new URL("./static/", _config.outDir); | ||
buildConfig.serverEntry = "_worker.js"; | ||
buildConfig.server = new URL("./", _config.outDir); | ||
}, | ||
"astro:build:setup": ({ vite, target }) => { | ||
@@ -61,2 +67,9 @@ if (target === "server") { | ||
}, | ||
"astro:build:start": ({ buildConfig }) => { | ||
if (needsBuildConfig) { | ||
buildConfig.client = new URL("./static/", _config.outDir); | ||
buildConfig.server = new URL("./", _config.outDir); | ||
buildConfig.serverEntry = "_worker.js"; | ||
} | ||
}, | ||
"astro:build:done": async () => { | ||
@@ -63,0 +76,0 @@ const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server); |
{ | ||
"name": "@astrojs/cloudflare", | ||
"description": "Deploy your site to cloudflare pages functions", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"type": "module", | ||
@@ -30,3 +30,3 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"astro": "1.4.5", | ||
"astro": "1.5.0", | ||
"astro-scripts": "0.0.8", | ||
@@ -33,0 +33,0 @@ "chai": "^4.3.6", |
@@ -1,2 +0,2 @@ | ||
import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig } from 'astro'; | ||
import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; | ||
import esbuild from 'esbuild'; | ||
@@ -10,2 +10,8 @@ import * as fs from 'fs'; | ||
interface BuildConfig { | ||
server: URL; | ||
client: URL; | ||
serverEntry: string; | ||
} | ||
export function getAdapter(isModeDirectory: boolean): AstroAdapter { | ||
@@ -33,2 +39,3 @@ return isModeDirectory | ||
let _buildConfig: BuildConfig; | ||
let needsBuildConfig = false; | ||
const isModeDirectory = args?.mode === 'directory'; | ||
@@ -39,5 +46,16 @@ | ||
hooks: { | ||
'astro:config:setup': ({ config, updateConfig }) => { | ||
needsBuildConfig = !config.build.client; | ||
updateConfig({ | ||
build: { | ||
client: new URL('./static/', config.outDir), | ||
server: new URL('./', config.outDir), | ||
serverEntry: '_worker.js', | ||
}, | ||
}); | ||
}, | ||
'astro:config:done': ({ setAdapter, config }) => { | ||
setAdapter(getAdapter(isModeDirectory)); | ||
_config = config; | ||
_buildConfig = config.build; | ||
@@ -51,8 +69,2 @@ if (config.output === 'static') { | ||
}, | ||
'astro:build:start': ({ buildConfig }) => { | ||
_buildConfig = buildConfig; | ||
buildConfig.client = new URL('./static/', _config.outDir); | ||
buildConfig.serverEntry = '_worker.js'; | ||
buildConfig.server = new URL('./', _config.outDir); | ||
}, | ||
'astro:build:setup': ({ vite, target }) => { | ||
@@ -76,2 +88,10 @@ if (target === 'server') { | ||
}, | ||
'astro:build:start': ({ buildConfig }) => { | ||
// Backwards compat | ||
if (needsBuildConfig) { | ||
buildConfig.client = new URL('./static/', _config.outDir); | ||
buildConfig.server = new URL('./', _config.outDir); | ||
buildConfig.serverEntry = '_worker.js'; | ||
} | ||
}, | ||
'astro:build:done': async () => { | ||
@@ -78,0 +98,0 @@ const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35694
516