coderaiser / minify

Minifier of js, css, html and img
https://coderaiser.github.io/minify
MIT License
225 stars 29 forks source link

minify fails on es6 template literals (`whatever`) #36

Closed chrisGoad closed 8 years ago

chrisGoad commented 8 years ago

Emits an error with message: Unexpected error character `

coderaiser commented 8 years ago

The thing is minify uses uglify for js minification. Unfortunately uglify doesn't support minification of es6 yes and I do not know any uglifiers with similar functionality and es-support.

Anyway you can use babel for this purpose. This is how:

coderaiser@cloudcmd:~$ cat > hello.js
const hello = 'world';
console.log(`${hello}`);
if (false) { console.log(hello);}
^C

coderaiser@cloudcmd:~$ babel --preset es2015 hello.js | minify --js
"use strict";var hello="world";console.log(""+hello);

Is it works for you?

Martii commented 8 years ago

Hmm this was working from OUJS perspective a little while back. Is this repo using the harmony branch?

coderaiser commented 8 years ago

What is OUJS? This repo uses uglify from npm.

chrisGoad commented 8 years ago

Thank you for your response. My use of template literals was very minimal, and the easiest thing for me to do has been to dispense with them. Do think uglify might evolve towards complete es6 support? Maybe I'll monitor that.

--Chris

On Mon, Aug 8, 2016 at 1:29 AM, coderaiser notifications@github.com wrote:

The thing is minify uses uglify https://github.com/mishoo/UglifyJS2 for js minification. Unfortunately uglify doesn't support minification of es6 yes https://github.com/mishoo/UglifyJS2/issues/448 and I do not know any uglifiers with similar functionality and es-support.

Anyway you can use babel https://babeljs.io/ for this purpose. This is how:

coderaiser@cloudcmd:~$ cat > hello.js const hello = 'world'; console.log(${hello});if (false) { console.log(hello);} ^C

coderaiser@cloudcmd:~$ babel --preset es2015 hello.js | minify --js"use strict";var hello="world";console.log(""+hello);

Is it works for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/coderaiser/minify/issues/36#issuecomment-238161082, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3QRpexLB3ziHdFiRdLUgeRVBvSOpU8ks5qdtrSgaJpZM4Jd6MU .

coderaiser commented 8 years ago

I think it definitely will. It event has harmony branch and I think they will merge it to master someday.

Martii commented 8 years ago

@coderaiser

harmony branch and of course you may already know the issue thread.

This repo uses uglify from npm.

That would probably be why your template string literals are failing is because you are using the ES5 master which is published to npmjs.com and not the harmony branch... just thought I'd give a welcome hand.

coderaiser commented 8 years ago

@martii I don't think that using code under active development that has no version is a good idea. I think they will merge some day (I hope it will be soon :)).

Martii commented 8 years ago

@coderaiser

I think they will merge some day (I hope it will be soon :)).

Us too but our project/repo/production is currently listing it as experimental and there is strong interest. :)