Code Monkey home page Code Monkey logo

Comments (15)

wigman avatar wigman commented on June 9, 2024 5

This is what a bash script that does this looks like:

THEME_FOLDER=('pub/static/frontend/Magento/luma/')
find ${THEME_FOLDER[@]} \( -name '*.js' -not -name '*.min.js' -not -name 'core-bundle.js' -not -name 'requirejs-bundle-config.js' \) -exec terser \{} -c -m reserved=['$','jQuery','define','require','exports'] -o \{} \;

from baler.

krzksz avatar krzksz commented on June 9, 2024 2

+1 for destructive approach, IMHO this is not baller's responsibility to handle backing up the files. In case redeploying static content is not an option for somebody, then they should make the copy themselves.

from baler.

JelleGroenendal avatar JelleGroenendal commented on June 9, 2024 2

@GuiltyNL thanks that improved my deploy by 30 minutes :)

@DrewML missed that thanks love baler so far.

from baler.

DrewML avatar DrewML commented on June 9, 2024 1

If they are already running then there is an issue that not all JavaScript in the static directory is minified.

That's what this issue is open to address :)

from baler.

DrewML avatar DrewML commented on June 9, 2024

@wigman since you work regularly with Magento, how would you expect this to work in an ideal scenario? Few options:

Destructive
We replace every .js file in pub/static with its minified version. No file name changes, no backups

Additive
We write minified files to {filename}.min.js, and either use a "resolver" to rewrite files (like core does), or just re-write paths in requirejs-bundle-config.js (bit harder, can hit some edge cases)

Backup
We rename every .js file to {filename}.js.bak, and then write the minified version to {filename}.js

My gut wants to go with destructive, but I want to be sensitive to overwriting data because I know some folks have very long static deploy times.

from baler.

wigman avatar wigman commented on June 9, 2024

Personally, I'd be fine with destructive, since that's what my command does as well. But I'm trying to think along for those that have massive amount of theme's / locales.

What about a --keep-source-files flag that does the backup ?

The question is, what's the use-case? Do you think minification can potentially fail and the command would need to run twice?
In that case, how would you re-run the command so that it uses the original files again?

I haven't had a case of Terser failing before, so I'm not sure what the use-case is.

If the idea is that someone would quickly want to switch back to the "un-baled" version of the static-content. I guess a backup of the entire locale would be the quickest solution.

baler build --backup-source could first copy all the locales to en_US_source.
baler build --revert-backup could remove the "baled" locales and move the originals back.

That way, people can decide for themselves if they want to have a backup for whatever reason.

Maybe we poll Twitter for some opinions?

from baler.

wigman avatar wigman commented on June 9, 2024

@krzksz Yes that actually makes a lot of sense.

from baler.

DrewML avatar DrewML commented on June 9, 2024

Sounds like we'll start with destructive 👍. Want to avoid adding config options where not critical because we'll end up like setup:static-content:deploy 😂

from baler.

JelleGroenendal avatar JelleGroenendal commented on June 9, 2024

Hi @wigman @DrewML ,
I'm failing to understand why you don't want to / cant use the default minify done by Magento. We have 7 languages / storeviews that would have to go trough terser. The total deploy then takes 1 hour, about 45 minutes of that is just running terser (server stats depended of course but it gives a bit perspective). If you use the default minify you don't have to minify separately.

from baler.

TimQSO avatar TimQSO commented on June 9, 2024

@JelleGroenendal we run a separate .sh after the deployment on the production server itself to minify with Terser. And we minify all the storeviews with parallel processes. It just takes a couple of minutes. And because the statics are excluded from Varnish the minified .js files will be served inmediately.

After that we do a Brotli precompression for Nginx.

from baler.

DrewML avatar DrewML commented on June 9, 2024

I'm failing to understand why you don't want to / cant use the default minify done by Magento

Three motivators:

  1. The built-in minifier results in significantly larger bundles compared to Terser
  2. The built-in minifier doesn't actually parse the JS code, so it wouldn't be capable of advanced optimizations performed by Terser (identifier mangling, constant folding, etc)
  3. The built-in minifier does not generate source-maps for baler to ingest. It's a design goal of baler to have high-fidelity source-maps for production builds, to enable better error logging + debugging.

We have 7 languages / storeviews that would have to go trough terser. The total deploy then takes 1 hour, about 45 minutes of that is just running terser

Are you running these jobs serially? The abstraction around terser in this project spins up a collection of worker processes so everything is done in parallel.

from baler.

JelleGroenendal avatar JelleGroenendal commented on June 9, 2024

I'm currently running it serially. I'm using the cmd line Wigman provided

find ${THEME_FOLDER[@]} \( -name '*.js' -not -name '*.min.js' -not -name 'core-bundle.js' -not -name 'requirejs-bundle-config.js' \) -exec terser \{} -c -m reserved=['$','jQuery','define','require','exports'] -o \{} \;

I'm not sure how to spin up the workers to minify or how this part works. If they are already running then there is an issue that not all JavaScript in the static directory is minified.

from baler.

TimQSO avatar TimQSO commented on June 9, 2024

I do this to run them parallel:

#!/usr/bin/env bash OLDIFS=$IFS IFS=$'\n' echo $datestart "Starting .js minify" for FILE in $(find /var/www/application/current/pub/static/frontend/Theme/nl_NL/ -type f -name '*.js' -not -name '*.min.js' -not -name 'core-bundle.js' -not -name 'requirejs-bundle-config.js'); do echo -n "Minifying Theme NL .js ${FILE}..." terser $FILE -c -m reserved=['$','jQuery','define','require','exports'] -o $FILE; echo "done." done & for FILE in $(find /var/www/application/current/pub/static/frontend/Theme/en_US/ -type f -name '*.js' -not -name '*.min.js' -not -name 'core-bundle.js' -not -name 'requirejs-bundle-config.js'); do echo -n "Minifying Theme EN .js ${FILE}..." terser $FILE -c -m reserved=['$','jQuery','define','require','exports'] -o $FILE; echo "done." done IFS=$OLDIFS

So in one shell script I repeat the command with & and specify all the theme folders. So there is one process per theme folder running. In our case that means 12 processes in parallel.

from baler.

VivekShingala avatar VivekShingala commented on June 9, 2024

While running this command, I am getting this.

zsh: no matches found: reserved=[$,jQuery,define,require,exports]

from baler.

VivekShingala avatar VivekShingala commented on June 9, 2024

While running this command, I am getting this.

zsh: no matches found: reserved=[$,jQuery,define,require,exports]

It worked fine. I had to run all the commands through bash script. I was trying it one by one on the terminal.

Thanks.

from baler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.