Skip to content
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

Minify inline JS - Package link broken? #78

Open
berstend opened this issue Feb 2, 2016 · 7 comments
Open

Minify inline JS - Package link broken? #78

berstend opened this issue Feb 2, 2016 · 7 comments

Comments

@berstend
Copy link

berstend commented Feb 2, 2016

I'm interested in using minimize to compress inline JS tags as well.

Unfortunately the link to the minimize uglify npm package seems to be broken:
https://github.com/Swaagie/minimize#available-plugins

I couldn't find any reference to uglifyjs in the minimize code - is compressing inlined JS snippets still supported?

@Swaagie
Copy link
Owner

Swaagie commented Mar 10, 2016

Sorry been a bit busy last weeks. This plugin is still in an uncommitted repo on my harddrive. I'll try to push it to github asap.

@gmetais
Copy link

gmetais commented Jul 7, 2016

Hi @Swaagie

How can I help? Would you like me to help publishing https://github.com/Swaagie/minimize-plugin-uglifyjs on npm (and than transfer the ownership to you)?

@simllll
Copy link

simllll commented Oct 12, 2016

any updates on this? :)

@simllll
Copy link

simllll commented Oct 12, 2016

What I did to get this working:

  1. used the index.js from minizie-plugin-uglifyjs and copied it to my project
  2. modified it to let it look like following code:
'use strict';

var uglifyjs = require('uglify-js');

//
// Unique ID to identify the plugin.
//
exports.id = 'uglifyjs';

//
// Minify the JS with uglify JS.
//
exports.element = function plugin(element, done) {
    if(!element.parent || element.parent.name != 'script') return done();

    var content, code
        , options = uglifyjs.defaults({
        fromString: true,
        compress: {//unused: false <-- doesn't make any difference
        },
        mangle: {}
    });

    // 1. parse
    content = uglifyjs.parse(element.data, options);

    // 2. compress <-- slowest part
    content.figure_out_scope();
    options.compress.screw_ie8 = true;
    options.compress.warnings = false;
    content = content.transform(uglifyjs.Compressor(options.compress));

    // 3. mangle
    options.mangle.screw_ie8 = true;
    content.figure_out_scope(options.mangle);
    content.compute_char_frequency(options.mangle);
    content.mangle_names(options.mangle);

    // 4. output
    var stream = uglifyjs.OutputStream();
    content.print(stream);
    element.data = stream.toString();
    done();
};
  1. included the plugin:
var Minimize = require('minimize')
        , jsuglify = require('./controller/thirdparty/minizime-plugin-uglify')
        , minimize = new Minimize({ plugins: [jsuglify]});

tried to optimize the performance, unfortuantely it's still at least 50% slower than without a uglifyjs2.

@dickeylth
Copy link

any updates on this? :)

@Swaagie
Copy link
Owner

Swaagie commented Mar 17, 2017

After a forced break from OS (mainly time restraints) this should receive updates shortly. Last week I opened a project https://github.com/Swaagie/minimize/projects/1 to track this work.

@alessioalex
Copy link

ping @Swaagie can you push the branch at least so we can help you out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants