-
Notifications
You must be signed in to change notification settings - Fork 110
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
build: improvements for TS & Webpack & Docker #1225
Conversation
5e9a33d
to
6a82a3a
Compare
Now that's a lot of changes. 😮 |
hope that's not a problem ;-) a) make sure |
update: I'll probably split out the swc Terser plugin work onto its own PR, so that we can at least have the improved ts/webpack building – and the build speed optimization (which would've been introduced by swc TerserPlugin) can come in later, after some additional investigation on how to handle the most elegant way: → it is currently giving me some issues during Github CI, due to it requiring "platform" specific packages (e.g. like Potentially will also try to just install the required deps in the CI, after running https://forum.strapi.io/t/package-error-swc-code-darwin-x64-deploying-to-strapi-cloud/37922 => will update the PR accordingly this evening |
5915250
to
2fdb9cb
Compare
I'd say I am done with this PR now, just need to do a quick test on a Windows machine as well, to make sure the copy-dist script does not behave a bit unexpectedly and I'll then rebase onto latest develop to avoid merge conflicts. edit: confirmed on Win11 -> copy-dist works exactly as on my Linux machine :-) Quick first stats from these changes: develop branch
vs this PR
some more details to follow on what exactly changed later this evening edit: |
2fdb9cb
to
e810715
Compare
update on the docker build: => also I do realize that this PR is getting bigger and bigger, but the issue is: The build process was so messy, you start pulling one thread, and you end up needing to take care of every other little bit as well :-D |
9e3a20d
to
fb49467
Compare
another update on the status here: Docker build is working now and looks a lot cleaner (and even a tiny bit smaller in size) than before. Couple of things left to do:
that will probably happen tomorrow and then I can finally open this up for reviews. I will then also hopefully have a detailed list of changes and comparisons |
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.
quick comment on this change:
the installation of these dependencies was originally added 7 years ago:
9cb9ea6
but I don't see any comment as to why these where added in the first place.
Not sure if 7 years ago they actually were needed for some rason, but currently they are definitely not, as I've confirmed by building the project without these :-)
Did run a test with a slightly modified main-docker.yml workflow (where I removed the "Login" actions, to not fail the workflow, before it even begins building docker): CI builds :-) will provide more details and what exactly I did tomorrow, but marking this one as ready for review already, for everyone to check |
6a7927a
to
d2b86df
Compare
@eliandoran Looking forward to your review on this :-) (afterwards I can finally start looking into Electron build improvements as well) |
this prevents tsc from unnecessarily transpiling the frontend part as well: previously it was transpiled by tsc, but the files got discarded and replaced by the files built by webpack. speeds up tsc command a bit as well: from 14 seconds to ~8 secs
output the bundled files directly in the build folder a) keeps the src folder clean from build output b) it saves us some "manual" copying work
as per https://webpack.js.org/configuration/devtool/#production serving the `source-map` file to "normal" users seems to be not recommended, so instead let's go with `nosources-source-map`: a) this drastically reduces app-dist folder size from 20MB down to 8.7MB b) it still allows for stack traces
not sure why, but seems like it doesn't like `[jt]s` – which causes it to skip certain .d.ts files, making tsc fail
since we build into the build folder -> we should also clean the folder before building as well also it makes sense to run tsc first, as it runs faster, so if there's any TS errors, we will have a faster failing build
these folder are already "excluded" implicitly, since we only include "./src" folder
webpack bundling already ran before this script, so there is no need to copy this file over
stop the build folder from being copied into the dist/src subfolder → there is no sense in doing that → the contents of the build folder are corretly copied previously already (see line 26ff)
we have the bundled "app-dist" already in the "dist", copying over the original unbundled "app" folder serves no benefit here
the "srcDirsToCopy" block is useless now, we can just use the previous dirsToCopy to achieve the exact same thing
… copying job there's no benefit in having them split up like before
there's no need to read the folder structure and then copy each single file in a loop => just copy the whole folder and be done with it :-)
there's no benefit from stripping "node_modules/" from the string, to later add it again using the `DEST_DIR_NODE_MODULES` constant => just copy directly into the `DEST_DIR` folder and preserver the `node_modules` part in the path
since this is a "standalone" script we are running and no other JS scritps are running "in the background", there's no real benefit for async here.
since we don't export this anywhere, might as well just call the steps directly
TS and Webpack build into the dist folder directly now
this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities. Build Stage: * do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally * build into a "build" subfolder, for easier clean up during build stage * get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist` * no `npm prune` needed here, as we delete the whole build folder anyways in the last build step Runtime stage: * move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies * move to `npm ci` for reproducible installations – but only installing runtime deps here * get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
same changes as for the "non-alpine" Dockerfile previously commited, but adapted to Alpine. this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities. Build Stage: * do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally * build into a "build" subfolder, for easier clean up during build stage * get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist` * no `npm prune` needed here, as we delete the whole build folder anyways in the last build step Runtime stage: * move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies * move to `npm ci` for reproducible installations – but only installing runtime deps here * get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
this is now handled fully inside Docker. exception for "test_docker" job in "main-docker" -> it seems that one needs to be there still, since it runs Playwright tests from outside the container
…es fodler from dist folder added a TODO as well, to get rid of this strange step here at some point
d2b86df
to
70e227f
Compare
Hi,
this PR
(still in draft)aims to improve the build process and better utilize TS / Webpack combinationstill a little bit work left to do here, but wanted to make this more visible to avoid any "duplicated work", while I work on this.more details about the what and why and some comparison data, will be provided tomorrow.
if you try to understand my changes before that -> I recommended going through the commits chronologically, instead of looking only at the "Files changed" overview :-)
Edit:
Overview of changes
concentrate build output into one single folder: "dist", previously we had
introduced a separate tsconfig for transpiling the server side code only
added build:ts and build:clean (for easily removing build folder)
improved copy-dist
updated Docker build (Dockerfile)
updated Docker build (Github CI)