elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

Feature: Optimize the build output #142

Closed maraisr closed 7 years ago

maraisr commented 7 years ago

First off - love the language! Absolutely brilliant, just a tad concerned about the output size.

With reference to line 386 onwards, can we do something like:

let alpha = 'abcdefghijklmnopqrstuvwxyz';

function createFunction() {
    return new Function(...arguments, `return ${arguments[0]}.arity === ${arguments.length - 1} ? ${arguments[0]}.func(${[...arguments].slice(1).join(', ')}) : ${arguments[0]}${[...arguments].slice(1).map(v => `(${v})`).join('')};`);
}

new Array(8).fill(null).forEach((val, key) => {
    window[`A${key+2}`] = createFunction.apply(this, ['fun'].concat(new Array(key+2).fill(null).map((v, k) => alpha[k])))
});

or es5:

var alpha = 'abcdefghijklmnopqrstuvwxyz';

function createFunction() {
    return new (Function.prototype.bind.apply(Function, [null].concat(Array.prototype.slice.call(arguments), ['return ' + arguments[0] + '.arity === ' + (arguments.length - 1) + ' ? ' + arguments[0] + '.func(' + [].concat(Array.prototype.slice.call(arguments)).slice(1).join(', ') + ') : ' + arguments[0] + [].concat(Array.prototype.slice.call(arguments)).slice(1).map(function (v) {
        return '(' + v + ')';
    }).join('') + ';'])))();
}

new Array(8).fill(null).forEach(function (val, key) {
    window['A' + (key + 2)] = createFunction.apply(undefined, ['fun'].concat(new Array(key + 2).fill(null).map(function (v, k) {
        return alpha[k];
    })));
});

to like dynamically create these functions? That way in the future we can analyse the app, work out what the max arity is going to be an adjust that array.

You could do something similar with the F* functions.

Just a thought...

Would like to spark the conversion (if not already sparked), to output some sort of ES6 output, so that we can have the goodness of tree shaking or something.

process-bot commented 7 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

evancz commented 7 years ago

Optimizing output is in the plans already, and I don't want to track it here.

In the meantime, use a JS minifier like Closure Compiler or UglifyJS. Output that starts as 300kb will go down to ~50kb with minification, and then down to ~30kb after gzip. So the output is not actually very big as is. It's often about as much as jQuery.

There are many ways to do better than this though, and that's quite high on my priority list.

screendriver commented 6 years ago

Any news on that @evancz ? Are there any plans to integrate a minifier / uglyfier into elm-make?