-
Notifications
You must be signed in to change notification settings - Fork 15
[Question] How to properly configure monorepo Typescript project? #141
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
Comments
Hi @vamcs ! We've got lots of clients doing both monorepos + TS with various different setups. I'd definitely recommend using tracing mode, although there is more configuration involved than legacy mode. Building TSJetpack only reads real JS files that Node.js can read. So you'll want to build your TS and point a serverless handler at that file. What we normally do in our monorepos is have the root This is nice because then serverless So assuming TS is already built (with a transpiled JavaScript entry point at like OPTION ONE -- Single ConfigThis is what we most typically do. Create a root-level service: SERVICE_NAME
custom:
jetpack:
concurrency: 4 # If you're on a Multi-CPU machine consider setting this to package in parallel.
collapsed:
bail: true # (OPTIONAL) Abort build if collapsed files in zip. (Sometimes an issue in monorepos).
preInclude:
- "!**" # Start with no files at all.
trace: # Trace actual dependencies at each entry point
dynamic:
bail: true # (OPTIONAL) Abort build if untraceable imports.
package:
individually: true # Package each function individually
plugins:
modules:
- serverless-jetpack
provider: # ...
functions:
service1:
# Transpiled JS file at: services/service1/dist/{ENTRY}.js
handler: services/service1/dist/{ENTRY}.{HANDLER_NAME}
service2:
handler: services/service2/dist/{ENTRY}.{HANDLER_NAME}
# ... To your "tree shaking" comment, this approach won't remove any unused code paths as it doesn't transform any source files. But it does trace and only include the files that are imported anywhere transitively starting at the entry point. In our experience, this ends up being not noticeably larger than an equivalent webpack build and often much nicer for things like debugging because you get stack traces from the real, original source files, etc. OPTION TWO -- Multiple ConfigsYou could also place individual config in something like But you would want to look at serverless config include features to avoid a lot of duplication. And if you wanted things like concurrent builds you'd have to script that yourself. AssessmentTracing mode normally needs some extra options for imports that can't be directly inferred, so I've given you a config with two Most configs end up with some combination of:
I do realize this is a bit of config to bite off from the relative simplicity of the webpack plugin, but once you've got the hang of things we'll hope you like it -- we've had pretty good responses from folks switching from the webpack plugin to Jetpack. And if you're encountering config issues getting started with Jetpack, feel free to drop them in here on this issue or create a public, minimal repo to replicate the structural problem you're trying to solve and I can jump in. Cheers and good luck! |
@ryan-roemer wow, thanks a lot for such a quick and comprehensive answer! I think I only missed tracing when I first set it up today but I'll continue tomorrow and report back before closing this issue. 🙂 |
I've managed to get it to work and the generate bundles were really small, like ~65KB each (the lambdas are very simple as of now though - they just basically reach for DynamoDB). But I'll can show how I set up the environment in case anyone else needs some help with it too: My Typescript setup with Babel, ESLint, Prettier and Serverless Jetpack:First of all, my project structure as of now is:
My initial plan was to also have a The relevant dev dependencies I use for the setup are:
The Babel config:
The ESLint config
The relevant parts of my
My
My build scripts in
There you go! Thanks a lot for this library and hope this is useful to someone else 🤠 |
Uh oh!
There was an error while loading. Please reload this page.
I got tired of
serverless-webpack
being too complex to set up with a monorepo and decided to tryserverless-jetpack
instead.Two questions:
serverless.yml
?I've read through #74 and started using
serverless-scriptable-plugin
with a manual build withtsc
but I don't quite get what to include or exclude and where to do that.Additional question: is there any sort of tree shaking going on? If I have the structure below and if I pack each function individually will I only get the (transpiled)
get.js
file in theget
function bundle? Or do I have to explicitly exclude everything else and only include that file for that function?Thanks a lot!
The text was updated successfully, but these errors were encountered: