melizeche / ayudapy

Humanitarian platform to help people help people
https://ayudapy.org
GNU Affero General Public License v3.0
111 stars 60 forks source link

try terser as JS minifier #268

Open melizeche opened 4 years ago

melizeche commented 4 years ago

just a draft, @jorgeramirez @juanhuttemann can you guys tests if this approach is valid for #261 ? reqs: npm install -g terser

ref: https://django-pipeline.readthedocs.io/en/latest/compressors.html#example

jorgeramirez commented 4 years ago

@melizeche thanks!

I haven't tested it yet. But you could try using shutil package to discover the path to terser in a cross-platform way. For example

import shutil
print(shutil.which("yuglify"))
> '/Users/jorge/.nvm/versions/node/v8.9.1/bin/yuglify'

I'll check your changes soon. I also wonder if this tool does the "translating" part (ES6+ => ES5).

melizeche commented 4 years ago

it's a minifier but we don't need translate to ES5, ES6 at least const is supported since android 2.2 https://caniuse.com/#search=const we just need not to go full ES7 features and we will be fine I think... and fuck IE edit: I misread the comment

melizeche commented 4 years ago

@juanhuttemann in theory it should work fine with env as https://github.com/melizeche/ayudapy/pull/268/files#diff-5e96265fa524caa1877f88f3c1958635R4 but didt't work on my case

juanhuttemann commented 4 years ago

@juanhuttemann in theory it should work fine with env as https://github.com/melizeche/ayudapy/pull/268/files#diff-5e96265fa524caa1877f88f3c1958635R4 but didt't work on my case

fix to work on any platform

import shutil
...
TERSER_BINARY = shutil.which("terser")
jorgeramirez commented 4 years ago

@melizeche it works like a charm, though I used @juanhuttemann fix. I guess if you update the PR with his suggestion is good to go 👌