-
Notifications
You must be signed in to change notification settings - Fork 25
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
[gh385] Minify the CSS and JS for production build #405
Conversation
2ce57f1
to
aeb4bd7
Compare
@@ -37,9 +37,16 @@ | |||
'--no-source-map', | |||
'--load-path=node_modules' | |||
] | |||
production_bundled_stylesheet_options = bundled_stylesheet_options + [ | |||
'--style=compressed' | |||
] | |||
|
|||
run %(npm set-script build "node app/javascript/build.js") | |||
run %( | |||
npm set-script build:css \ |
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.
It would be best to use a prefix here and avoid it below:
npm set-script build:css-production \
So production
is special, while dev
is the base/standard mode.
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.
Thanks for the suggestion! The default one should be the development
environment.
I've updated it in 2c9789c ✅
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.
The build:css-production
won't be trigger as no one call that, the https://github.com/rails/cssbundling-rails/blob/main/lib/tasks/cssbundling/build.rake#L20 enhance the css:build
by default, we need to go with the Sang's original solution FYI @olivierobert I will open a PR for that cc @sanG-github
![image](https://private-user-images.githubusercontent.com/11751745/250782020-199a8b88-ad30-4614-b487-8b6ab45ea795.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODY0ODcsIm5iZiI6MTczOTE4NjE4NywicGF0aCI6Ii8xMTc1MTc0NS8yNTA3ODIwMjAtMTk5YThiODgtYWQzMC00NjE0LWI0ODctOGI2YWI0NWVhNzk1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExMTYyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyY2U0YzdjYWFlMzhhYzk0NWNjYzFkYjJmYTY1M2Q5NzRlZTZlNjE2YzliMzM2M2ViZGZlNDZhZjE5Y2Y3MTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.yHA3PXCfWEU52L-BNeVbVdUg0fcHLVuRU7FV7_K9nWA)
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.
🔥 🚀 🔥
@@ -6,6 +6,7 @@ require('esbuild') | |||
inject: ['app/javascript/global.js'], | |||
bundle: true, | |||
sourcemap: true, |
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.
@sanG-github a small comment, we really don't use source map on Production, should we set this as
sourcemap: true, | |
sourcemap: !watch, |
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.
Wd do use sourcemap
😅 You might not but sourcemaps as essential for debugging
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.
@olivierobert , that's interesting, we have --no-source-map
for sass
, for all environments
'--no-source-map', |
Then, I tried enabling it for a local project, and it was trying to reference the file by its path 😄
![image](https://private-user-images.githubusercontent.com/39977805/246366181-21c3e90d-dfb2-4fc2-8173-13b21b75e5bd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODY0ODcsIm5iZiI6MTczOTE4NjE4NywicGF0aCI6Ii8zOTk3NzgwNS8yNDYzNjYxODEtMjFjM2U5MGQtZGZiMi00ZmMyLTgxNzMtMTNiMjFiNzVlNWJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExMTYyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcwYjk1MzQwYmVmMzE3OTNjODI3Mjc1NWEyYzYxMjc0MzY1MzdhMGZlMGNlZTI1MmQ3MmFhMjgzYmQ4ZjNkZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GepYMfMinHSgLhXTHeo52V9oPc67jNx6xWIeK8Yolzk)
I searched around and it seems like an existing issue for cssbundling-rails
I was wondering if you ever were able to use source maps for SCSS assets in a Rails project?
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.
@tyrro Nice catch! :o Should we create a dedicated issue to investigate this?
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.
@olivierobert but we don't debugging on Production 🤔
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.
ok, after checking this article https://css-tricks.com/should-i-use-source-maps-in-production/ it's better to have the source map information in the Production build cc @tyrro @olivierobert @malparty
There are 2 benefits
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.
@malparty if we have a chance, we could just remove this config on the same PR ;)
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.
@andyduong1920 , but source-map
doesn't work for cssbundling-rails
(please refer to my last comment).
So if we remove --no-source-map
option, it'll try to generate the source map, which will result in the following:
Screen.Recording.2023-06-16.at.4.30.16.PM.mov
which is not very helpful for debugging 😄
@malparty , IMHO it's not worth it at this moment.
jsbundling-rails
support source-map
(and we are using it too btw), css-bunding-rails
yet to support it. So, I'd keep it as it is regarding the --no-source-map
option!
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.
@andyduong1920 lets create an issue for that :)
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.
2c9789c
to
9639680
Compare
@sanG-github rebase needed 🙇 |
@tyrro rebase needed and then we can merge this one 🚀 |
@malparty , I'll tag @sanG-github so that he can do the rebasing for me 🙈 😏 |
9639680
to
4d587c1
Compare
close #385
What happened 👀
We customize the build process between development and
production
, as we want theproduction
build to be as minimal as possible.Insight 📝
With JS, we config the
esbuild
configuration:minify
option to be true in the case we don't have the--watch
option (production)With CSS, we separate two scripts:
build:css
for the production that included the'--style=compressed'
option.build:css-dev
for thedevelopment
environment, without the compressed option.Proof Of Work 📹
Generated package.json
Generated Procfile.dev