-
Notifications
You must be signed in to change notification settings - Fork 156
Add an option for createStaticAssets to respect the basePath of Next.js #821
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
Conversation
|
Coverage Report
File Coverage
|
commit: |
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.
If we do that we'll need to modify this file as well otherwise it will break existing aws deployment https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/generateOutput.ts
I'm wondering if the good long term solution would be to actually use that output file instead ?
Yes, it's more a short term hack for cloudflare... |
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.
Yeah it is used in sst and other places, but i've missed the useBasePath
which should make it do nothing there.
FYI every places that use this function need to use the basePath (this includes public file)
I'm not quite sure what the best way to move forward here is? |
I'm not 100% sure either, my first idea would be that cloudflare (or anyone else) should use the output file to actually finalize the deployment from the created assets from OpenNext. For example these 2 lines: opennextjs-aws/packages/open-next/src/build/generateOutput.ts Lines 201 to 202 in 73281c9
createStaticAssets because files would be at .open-next/assets/basePath and would thus create an _assets/basePath/basePath folder.
|
The thing I don't get with this code is that static assets do not seem to be prefixed by the basePath? |
On aws it's on the behavior for cloudfront, not in the bucket themselves |
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.
@vicb What do you want to do with this one ? I'm fine with adding it like that for now as long as we add some comment about it (it won't have any effect on aws since we won't use useBasePath
)
fs.cpSync( | ||
path.join(appBuildOutputPath, ".next/static"), | ||
path.join(outputPath, "_next", "static"), | ||
path.join(outputPath, basePath, "_next", "static"), | ||
{ recursive: true }, | ||
); | ||
if (fs.existsSync(appPublicPath)) { |
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.
Everything in here should be under outputPath/basePath
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 do you mean by "everything in here"?
Looking at the blog example, path are not re-written. The avatar will not be fetch for the basePath. Only <Image/>
and <Link/>
will use the base path.
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.
Favicon and assets in public should also start with basePath
. That's the behavior in next start
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.
That's not the behavior I observe on the blog example with next start
?
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.
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.
Oops, you'right.
What I did with the blog example is that I probably used npm preview
and make that work.
As the path are nor rewritten, the assets should not be prefixed if you want to access them.
But it must be an overlook in the blog example.
In conclusion, you are right, everything must be prefixed.
Would that work if the copy is unconditionally done to the basePath subDir and the basePath logic is removed from the output file? I think this could be a way to support Cloudflare & AWS?
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.
We need to add it to the behavior as well anyway (to avoid intercepting things it should not).
I think we go for your solution for now, just add a comment about it, and try to figure out a way to create an output that could be used by everyone.
I had this idea awhile back to add an outputOverride
to be able to compute an output that could be used in each platform easily. This inside something like an open-next.build.ts
could be something that could help us in a lot of ways.
I updated the PR to add a comment, does it looks good like this? |
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.
LGTM Thanks
Thanks Nico! |
The plan is to use this in cloudflare so that the path it handled by the Workers Assets automatically when a basePath is configured