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
Exclude dev dependencies from Node.js runtime package #603
Comments
I think you would have to do this manually in your build hook. You could do something like {
"build": "npm run build && rm -rf node_modules && npm install --only=production"
} |
It would be super cool to handle this magically, but it may be quite a bit of work, unless npm has something like Re-installing each time is definitely not ideal. Some people do it in CI so you're not constantly replacing node_modules, another alternative is bundling with browserify or similar—this is ideal for cold start performance as well. |
Hmm it does have prod listing, but node's boot time for running the
It takes 2s just to run on a small app, but maybe that'll be fine as a stop-gap. https://github.com/tj/node-prune helps too, honestly bundling with browserify is best if possible, since that strips all of the markdown and random files. |
Hmm so you advice to use browserify to make single file bundle and completely ignore node_modules? |
Yep, it has a few benefits: much smaller build since it ignores many files, much faster cold start times due to the syscall overhead of many thousands of |
Thanks I will try it. I never thought about browserifying server side code, always used pure babel to just transpile sepearate files, but in lambda environment it sounds reasonable. |
I've seen some strange behaviour with ignoring dev dependencies. I have a next project - and the build process bundles into a dist. But if i ignore any of the source files (etc /pages) the deployed app fails. Same if i remove any node_modules - even dev dependencies. The build is client side - so Im wondering why this may have problems. If i run the build process manually - I can remove the source files and things run fine. [Perhaps is thread spamming - but seemed relevant to the discussion] |
@glenarama I can't comment on the Next stuff, I'm not sure what it expects, but that does sound strange. What's your |
Package.json Scripts: up.json: { When running up - it goes through the build process - obviously with a large number of files, the zip is very large. So im keen to be aggressive on my up.ignore filters. |
My bad...you even warn about it in the docs:
I was including "pages" rather than "./pages" which removed some of the dist files. |
ahh!! that'll do it, when in doubt you can do |
For now, the best solution I find is by using # in the build hook, this command will remove dev dependencies
npm prune --production
# in the clean hook, bring the dev dependencies back without downloading anything
npm i --offline As a example, you can find these configs in my project: Refs:
|
The
|
We were successfully using @timchambers solution above until we tried to do this when Here's some more info about how |
@k00k yeah, that's a better approach. Here are my updated hooks. I switched to using the "hooks": {
"predeploy": "yarn install --production",
"postdeploy": "yarn install --production=false"
}, |
"hooks": { In your package.json file It's worked for me |
Prerequisites
up upgrade
)-v, --verbose
flag.Description
I am getting
Error: building: building: zip contents is 269 MB, exceeding Lambda's limit of 262 MB
because my devDependencies in node_modules (Node.js project) are included in a zip file. I have quite a lot of them so putting them manually to.upignore
is not convenient. Would be nice if there was an option to automatically exclude devDependencies from Lambda zip package. I know that serverless.js does this automatically when building Lambda package(s).For example here is a list of my dev dependencies:
The text was updated successfully, but these errors were encountered: