-
Notifications
You must be signed in to change notification settings - Fork 28
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Why does bundle include source files and other non-runtime dependent files in the project? #95
Comments
Hey @fourpastmidnight 👋 I think you've found a spot with the documentation that needs more work. Yarn's workspace feature (having multiple local packages), is a really powerful tool for code sharing. It allows you to break up your application, while sharing common code, in the same way as if that code was pushed to npm. Except it can stay local to the monorepo, and can be versioned with everything else. When you run a The In the past with Imagine you have a monorepo with 10 lambdas/nodejs apps/microservices in it, and they all shared a bunch of code. Each package will have a different dependency graph, and wont need everything in the repo. So we can create a separate bundle for each. In contrast, when building and distributing to the web we often collapse everything into a single file. Or more recently, a collection of files.
The initial reason for this was that I typically build and deploy lambdas from CI, and so other release artifacts were not caught up in the final bundles. However, it's something that should be configurable, and at the very least should read the existing The other The intent of
Yep that's precisely the problem
You'd need to copy the
Yep sounds like you might not have copied everything you needed. You need all of
Just on this, it's helpful to control these. Either with
This sounds like a feature to add. I often write a lot of TypeScript code, and for packages that are shared I don't always compile then, instead just pointing I think we would need to add a per package config for folders to remove for the bundle, because it's not easy to know if a script in your output folder wants to reach into
Some of the plugins could be, though perhaps an option to clear them out might be useful. As an example, there's a plugin in this repo to allow you to use But mainly,
The That's not to say how you're doing it is wrong, just it's a different approach. I'd argue that having a different command for each package to build makes moving between packages hard for developers new to the project, and that anything that needs to be in the environment for build, should likely be passed in instead at runtime. The only exception to that would be Though also, You can add a The last part behind the philosophy here, is that you should build one artifact, test it, deploy it to dev, test it there, maybe run integration tests, then deploy it to production. The actual artifact never changes, giving you a higher confidence it will succeed in production. Then, the only things that change per environment are ENV vars, secrets (which should always be passed at runtime), and the state of feature flags. However, that may not be suitable for how your repository is setup. Which doesn't mean how you've setup is wrong, just it's different to what I think |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
I'm a bit new to the whole JavaScript ecosystem and packaging and bundling in general. I know enough to be dangerous 😛
At first, in my project, I was trying to put my "production build' outputs into their own folder hierarchy. Long story short, it somewhat worked—though with using Yarn PnP, I needed to mimic some of the actual project hierarchy (so that PnP path resolution worked, because there's no (good) way to "re-run" yarn install on a production output (unless you copy the package.json files???—and if you're output hierarchy is different from development hierarchy, this still doesn't work anyway). Anyway, my original "production build" looked like:
./releases
, which mimicked my project folder hierarchy to the point where the production built files could be resolved via.pnp.js
..pnp.js
file to this folder.env
file at the root (currently done by a PowerShell script for now.)And this worked. The biggest drawback is that I'm bringing over all the development dependencies (because I wasn't about to try and figure out what was needed and what is not).
And now I come to the point: I find
yarn.build
. This sounds promising. I didn't necessarily want to resort to using webpack or something.So I've been doing a LOT of build testing (prior to using yarn.build), and have several files "polluting" my repo, e.g. previous release builds, and self-extracting zips of those builds, etc. When I ran
yarn bundle
, it did exactly what I expected it NOT to do: grabbed everything in the repo except.git
(though, it did slim down the.yarn/cache
to just those things needed by my app—I think, I haven't actually tested that the bundle works yet).I thought
yarn bundle
was only supposed to package up only those things which are needed to run the project in production? So why are the various./src
directories for the monorepo packages being included? Why are non-project files being included (e.g. previous release builds in the root monorepo directory)? The bundle came out to a WHOPPING 89MB - 920MB!!! When I manually went into the generatedbundle.zip
and deleted everything NOT related to running the project, thebundle.zip
file size was 5MB. That's more what I expected (actually, I expected 20MB - 30MB, but that just shows you how much weight development dependencies add to a project--in my case, 75MB).To Reproduce
Steps to reproduce the behavior:
yarn bundle
in a distributable package in a dirty (😉) repoExpected behavior
I expected that only the output folders from the build (i.e. the folder listed in the
package.json#directories
,package.json#files
, or inferred files/directories based onpackage.json#main
to be included in the bundled output.Screenshots
I'm in the middle of trying to get my build working the way I want it to--so there's lots of cruft in my project workspace at the moment. Once I have good, stable production builds being packaged correctly, I intend on cleaning all of this up. But for now, this is what I've got. And this is being packaged in the bundle.zip, inflating its size from 5MB to 890MB!!!!!
![image](https://user-images.githubusercontent.com/6895593/130266721-66d0362a-d571-4f02-86a4-77bd1c142b85.png)
And here's what's contained in the bundle.zip:
Even yarn PnP specific stuff, like yarn sdks and plugins are included in the bundle!! But these aren't necessary at runtime, are they?? I never included them in my hodge-podge builds/packages I was creating before and this app is running in production just fine.
After deleting all the unnecessary cruft, here's what the bundle looks like, along with its size:
Qutie a difference!!!!
Desktop:
Additional Context
I did not use
yarn build
because the build scripts in my variouspackage.json
files are not simply namedbuild
and are not the same for all packages—e.g. for a react website, the command is simplybuild
, but for other packages, the command could be eitherbuild:dev
orbuild:prod
. The simplistic option of specifying a command via-c
is not sophisticated enough for my project. In addition, for the react web site, I need to pass different environment variables to Node depending on the environment I'm building for so that the right.env.*
files are used. (Perhaps it's possible to do this withyarn.build
, e.g.NODE_ENV=MyEnv yarn build
?? But I didn't see any documentation suggesting this would work.)The text was updated successfully, but these errors were encountered: