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
feat: building without node_modules #10202
Conversation
🦋 Changeset detectedLatest commit: 83a7ca2 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e705fd6
to
125316f
Compare
This would be a great addition, thanks for taking this on!
|
Yes, in the current implementation I added To avoid this, I plan to move the option from the If anyone sees weaknesses in this implementation, welcome to the discussions, I will be glad to receive any feedback :) |
For the current PR's approach, I sent an upstream PR (vitejs/vite#16019), that should simplify the configuration, so simply setting
This is true though. My PR won't solve this, and the workaround would be to force Instead I think we should check each |
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.
Thank you, @aleksandrjet, for this great addition. This PR requires updating the documentation too: https://docs.astro.build/en/guides/integrations-guide/node/
Will you do that too? Let us know if you have the capacity. If not, we will do that
@@ -10,6 +10,7 @@ export interface UserOptions { | |||
* - 'standalone' - Build to a standalone server. The server starts up just by running the built script. | |||
*/ | |||
mode: 'middleware' | 'standalone'; | |||
isIndependent?: boolean; |
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.
I would call the option independent
. Also, it requires some documentation
"@astrojs/node": minor | ||
--- | ||
|
||
Added the `isIndependent: true` option to the `NodeJS` adapter. With this option, when building, the output folder `dist/server` will contain all the necessary data to start the server. And your server will be able to work without the `node_modules` folder |
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.
Added the `isIndependent: true` option to the `NodeJS` adapter. With this option, when building, the output folder `dist/server` will contain all the necessary data to start the server. And your server will be able to work without the `node_modules` folder | |
Added the `isIndependent: true` option. With this option, when building, the output folder `dist/server` will contain all the necessary data to start the server. And your server will be able to work without the `node_modules` folder |
The package @astrojs/node
is already the adapter, I think it's redundant to say "to the Node.js adapter".
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.
I plan to move this to experimental config:
export default defineConfig({
output: 'server',
adapter: node({
mode: 'standalone',
}),
experimental: {
isIndependent: true,
}
});
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.
In this PR?
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.
Yes, I have now moved this option to config.experimental.isIndependent
. Without this change, building without node_modules
will not work for some frameworks
125316f
to
dd4a343
Compare
I will be glad if you help with docs, but previously we need to wait PR of @bluwy |
be18872
to
b4b4c2e
Compare
b4b4c2e
to
b64a59d
Compare
I was thinking that we shouldn't need this PR or option at all. Once vitejs/vite#16019 lands, we only need to document that they can set However of course, there are integrations today that force set |
Thanks for the contribution, but after discussing it I think we're going to wait on the Vite option and avoid making the Node adapter more complicated. |
Changes
I added the
isIndependent: true
option to theNodeJS
adapter. With this option, when building, the output folderdist/server
will contain all the necessary data to start the server. And your server will be able to work without thenode_modules
folder.For what
Including external dependencies in the build helps reduce the size of the application. In new example, the weight of the docker image with the application with the node modules folder is 244 MB, and without it - 135 MB.
At the same time, if you remove size of the os and NodeJS from the comparison, then the difference is much more significant - 110 MB versus 500 KB!
You can see more details about the difference in docker images in the new example.
All this can be configured in astro.config.mjs yourself. Why make a new parameter?
Vite
andNodeJS
, since you cannot simply passexternal: false
to the config and get resultTesting
I added tests to the
integrations/node
folder. These tests checks functionality after deletingnode_modules
folderDocs
cc @sarah11918