azproduction / lmd

LMD - JavaScript Module-Assembler for building better web applications :warning: Project is no longer supported :warning:
http://azproduction.ru/lmd/
MIT License
449 stars 27 forks source link

Integrate LMD with Autopolyfiller #194

Open monolithed opened 9 years ago

monolithed commented 9 years ago

Хотелось бы иметь секцию в конфиге для Autopolyfiller'a, как с UglifyJS, т.к. сейчас приходится держать аж три отдельных таска:

    grunt-lmd (-> build.js) 
    grunt-autopolyfiller (->polyfills.js) 
    grunt-contrib-concat (-> polyfills.js + build.js)

В grunt-таске это может быть секция use:

const autopolyfiller = require('autopolyfiller');

...
options: {
    use: [ autopolyfiller ]
}
...

Подобный биндинг я использую в grunt-contrib-stylus c csso-stylus

PS: перечислять в autopolyfiller'e список файлов, и затем подключать его lmd не вариант, т.к. это будет копипаст, проще на уже готовую сборку натравить autopolyfiller.

azproduction commented 9 years ago

На самом делe внедрение UglifyJS в lmd было большой ошибкой. lmd в первую очередь сборщик модулей. Минификация это не прямая обязанность.

Я не думаю, что многошаговая сборка это что-то плохое. По крайней мере все это делается автоматически.

monolithed commented 9 years ago

Полностью согласен насчет UglifyJS, предлагаю выпилить и перенести эту часть логики в grunt-таск (секция use) :metal:

azproduction commented 9 years ago

Я против use в рамках lmd ;) Т.к. того же результата можно добиться конфигурацией, а не кодом.

monolithed commented 9 years ago

Один небольшой таск:

// tasks/lmd.js
const autopolyfiller = require('autopolyfiller');
const uglify = require('uglifyjs');

module.exports = function (grunt, options) {
    return {
        dev: {
            build: 'dev',
            use: [autopolyfiller, uglify]
        }
    };
};

Против (у меня сейчас подобная схема):

// tasks/lmd.js
module.exports = function (grunt, options) {
    return {
        dev: {
            build: 'dev'
        }
    };
};
// tasks/autopolyfiller.js
module.exports = function (grunt) {
    return {
        dev: {
            files: {
                'polifills.js': ['build.js']
            }
        }
    };
};
// tasks/concat.js
module.exports = function (grunt, options) {
    return {
        production: {
            files: {
                'build.js': ['polifills.js', 'build.js']
            }
        }
    };
};
// tasks/uglify.js
module.exports = function (grunt, options) {
    return {
        dev: {
            files: [
                {
                    src: 'build.js'
                }
            ]
        }
    };
};

Быть может я не прав, что один небольшой файл лучше четырех, но пока вижу в этом только профит.