-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: generate .assetsignore
file for Cloudflare deployment
#13109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
14b662f
32ccc2e
0e9b1fc
ee1e4bb
6892797
9061fc5
1259966
ae98415
38a0220
896318c
3b27f87
99d2fd9
a1ec57a
728fb08
68bdb25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
'@sveltejs/adapter-cloudflare': patch | ||
--- | ||
|
||
.assetsignore file generation for Cloudflare deployment. It is corresponded to https://github.com/cloudflare/workers-sdk/pull/6640 | ||
methanoya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_worker.js | ||
_routes.json | ||
_headers | ||
_redirects |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||
import { existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||||||||||||
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||||||||||||
import { posix, dirname } from 'node:path'; | ||||||||||||
import { execSync } from 'node:child_process'; | ||||||||||||
import esbuild from 'esbuild'; | ||||||||||||
|
@@ -143,6 +143,8 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {}) | |||||||||||
); | ||||||||||||
} | ||||||||||||
|
||||||||||||
copyFileSync(`${files}/.assetsignore`, `${dirname(main)}/.assetsignore`); | ||||||||||||
|
writeFileSync(`${dest}/_headers`, generate_headers(builder.getAppPath()), { flag: 'a' }); |
_headers
to the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like #13072 is in a draft state, this PR is ready to use.
The source of the .assetsignore
is https://github.com/cloudflare/workers-sdk/blob/main/packages/create-cloudflare/templates-experimental/svelte/js/static/.assetsignore They created it some way, so it makes sense to keep it the same and copy from there if updated. It is a better point to control the list of server-side-only files. Another approach is adding files like _worker.js
to the .assetsignore
once they are created, but it is probably less clear. Let me know if you have a strong opinion, I will update the PR accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that Cloudflare's .assetsignore
file is part of a starting template, whereas we need to take into account a user having their own file. I'd recommend that we write using append mode so it's created if it doesn't exist, otherwise it writes to the existing file.
I'm also not sure copying it to main
corresponds to the root of the assets directory. Isn't it currently site.bucket
?
kit/packages/adapter-cloudflare-workers/index.js
Lines 146 to 149 in 33600ee
builder.log.minor('Copying assets...'); | |
const bucket_dir = `${site.bucket}${builder.config.kit.paths.base}`; | |
builder.writeClient(bucket_dir); | |
builder.writePrerendered(bucket_dir); |
But I'm also not sure if copying it to the bucket root would have any effect since it's part of the old Workers sites feature. cc: @petebacondarwin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a shipping update for adapter-cloudflare
only since it would work differently for adapter-cloudflare-workers
and can depend on #13072 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making .assetsignore
based on an existing one can be a good idea, but it looks like adapter-cloudflare
takes responsibility for making the right bundle for the Cloudflare deployment. I am not sure that a user can have a reason to make any non-asset file.
We can show a warning message if .assetsignore
is already present as a current workaround.
I am open to both approaches if maintainers strongly believe either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a shipping update for
adapter-cloudflare
only since it would work differently foradapter-cloudflare-workers
and can depend on #13072 ?
Yeah, I think we can probably split the Workers part into another PR.
Making
.assetsignore
based on an existing one can be a good idea, but it looks likeadapter-cloudflare
takes responsibility for making the right bundle for the Cloudflare deployment. I am not sure that a user can have a reason to make any non-asset file. We can show a warning message if.assetsignore
is already present as a current workaround. I am open to both approaches if maintainers strongly believe either way.
The main purpose of the file is to prevent certain assets from being made public. This can be desirable if the user has server only assets. I think we should append to an existing .assetsignore
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eltigerchino I have removed the -workers
code from the PR and added .assetsignore
merging. It may be overcomplicated, and we would need to add just one file to another. Let me know your thoughts.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/files | ||
/files/* | ||
!/files/.assetsignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_worker.js | ||
_routes.json | ||
_headers | ||
_redirects |
Uh oh!
There was an error while loading. Please reload this page.