Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration.
From the Upstream docs
The
routes
option allows you to customise the_routes.json
file generated byadapter-cloudflare
.
include
defines routes that will invoke a function, and defaults to['/*']
exclude
defines routes that will not invoke a function — this is a faster and cheaper way to serve your app's static assets. This array can include the following special values:
<build>
contains your app's build artifacts (the files generated by Vite)<files>
contains the contents of yourstatic
directory<prerendered>
contains a list of prerendered pages<all>
(the default) contains all of the aboveYou can have up to 100
include
andexclude
rules combined. Generally you can omit theroutes
options, but if (for example) your<prerendered>
paths exceed that limit, you may find it helpful to manually create anexclude
list that includes'/articles/*'
instead of the auto-generated['/articles/foo', '/articles/bar', '/articles/baz', ...]
.
esBuildOptions
: Adds additional options to the esbuild process. See esbuild.BuildOptions
for more information.
Node.js modules.
If you had this error when trying to use a node module in your SvelteKit application:
> Using @sveltejs/adapter-cloudflare
✘ [ERROR] Could not resolve "path"
node_modules/bcrypt/bcrypt.js:4:19:
4 │ var path = require('path');
╵ ~~~~~~
The package "path" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
then you can just use an ESBuild plugin to polyfill the Node.js modules.
import {NodeModulesPolyfillPlugin} from '@esbuild-plugins/node-modules-polyfill'
import {NodeGlobalsPolyfillPlugin} from '@esbuild-plugins/node-globals-polyfill'
export default {
kit: {
adapter: adapter({
// See below for an explanation of these options
routes: {
include: ['/*'],
exclude: ['<all>']
},
esBuildOptions: {
plugins: [
NodeModulesPolyfillPlugin(),
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true
})
]
}
})
}
};
Those few lines of code will allow you to use Node.js modules in your SvelteKit application, even when deployed to Cloudflare Pages.
Downstream: Check commit history.
Upstream: The Changelog for this package is available on GitHub.