-
Notifications
You must be signed in to change notification settings - Fork 106
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
base: develop
Are you sure you want to change the base?
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: |
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
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 |
Hi,
this PR (still in draft) aims to improve the build process and better utilize TS / Webpack combination
still 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.