brunch / terser-brunch

A javascript minifier for brunch files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fail to compress js builded from typescript

baptistedonaux opened this issue · comments

I made a little plugin to build typescript with brunch (https://www.npmjs.com/package/brunch-typescript). For a personal project, I want build and uglify but I have an error with compression. So strange, because when I execute manually uglify-js, I don't have fail.

'use strict';

exports.config = {
    paths: {
        'public': 'dist',
        'watched': [
            'src'
        ]
    },
    files: {
        javascripts: {
            joinTo: {
                'dest.js': 'my/source.ts'
            }
        },
    },
    plugins: {
        uglify: {
            mangle: true
        }
    }
};

My package.json :

{
    "dependencies": {
        "brunch": "1.8.*",
        "brunch-typescript": "1.5.*",
        "uglify-js-brunch": "1.7.*"
    }
}

Sorry, the log given is :

14 Aug 12:05:12 - error: JS minification failed on dist/dest.js: Unexpected token: name (Params) (line: 123, col: 10, pos: 3308)

Error
    at new JS_Parse_Error (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:196:18)
    at js_error (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:204:11)
    at croak (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:684:41)
    at token_error (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:688:9)
    at unexpected (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:694:9)
    at semicolon (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:714:43)
    at simple_statement (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:894:73)
    at /data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:767:19
    at /data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:727:24
    at block_ (/data/node_modules/uglify-js-brunch/node_modules/uglify-js/lib/parse.js:1007:20)

… and other warning logs display by brunch-typescript

We can't really help here unless we see the result source code i'm afraid.

Try looking into your non-minified (disable it) dest.js — maybe there's something wrong with it

Yes of course !

I try build my project https://github.com/autocompletejs/autocomplete.js/tree/2.0. I have versionned the brunch-config.js.

The fail appears when I execute brunch b -P.

Up ! Do you have a little time to show my autocomplete build :-/

Thank you for less time devoted at my problem.

I am experiencing the same issue when trying to minify TypeScript files.

By the way, minification works well when I paste the compiled TypeScript code to http://lisperator.net/uglifyjs

@kripod Do you have a solution ? I have re-search a solution in brunch-typescript (I searched a possible workflow error) but unfortunately no…

It's really damage, brunch it's a great solution to build simple project but this little is disappointing… :-/

@baptistedonaux how does your plugin work? Just took a very quick look at https://github.com/baptistedonaux/brunch-typescript/blob/master/index.js, and it doesn't seem like you're passing the compiled result back to brunch in the compile method. Seems like you're just passing the source data back and somehow bypassing the brunch compilation pipeline to get your typescript compiled, which would easily explain why uglify chokes on it.

This issue really belongs in your plugin's issue tracker, as it doesn't function the way a brunch compiler plugin is supposed to. Or just shift attention over to the typescript plugin that already existed and does seem to follow the regular plugin conventions https://github.com/joshheyse/typescript-brunch, although it seems it could use some updating.

@baptistedonaux I have no solution, and also suspended my projects written in TypeScript, sorry.

@kripod The last release of brunch-typescript@1.7.0 (dev by @colinbate ) supports production flag.