var compileSass = require('broccoli-sass');
var styles = compileSass(['scss', 'vendors'], 'main.scss', 'app.css');
var JSHinter = require('broccoli-jshint');
var esTranspiler = require('broccoli-babel-transpiler');
var concat = require('broccoli-concat');
var tree = new JSHinter('app');
tree = esTranspiler(tree);
tree = concat(tree, {
'outputFile': 'app.js'
});
module.exports = function(grunt) {
grunt.initConfig({
clean: {
dist: {
src: 'dist'
},
tmp: {
src: 'tmp'
}
},
eslint: {
src: {
src: ['app/**/*.js']
}
},
babel: {
options: {
comments: false,
sourceMap: false,
presets: ['es2015']
},
dist: {
files: {
'tmp/*.js': 'src/**/*.js'
}
}
},
concat: {
dist: {
src: ['tmp/*.js'],
dest: 'dist/app.js'
},
},
watch: {
js: {
files: 'app/**/*.js',
tasks: ['eslint', 'babel', 'concat']
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('default', ['clean', 'eslint', 'babel', 'concat']);
};
var gulp = require('gulp');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
var runSequence = require('run-sequence')
gulp.task('default', ['eslint', 'build', 'watch']);
gulp.task('eslint', function() {
return gulp.src('app/**/*.js')
.pipe(eslint());
});
gulp.task('build', function() {
return gulp.src('app/**/*.js')
.pipe(babel({
'presets': ['es2015']
}))
.pipe(concat('app.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
watch('app/**/*.js', function() {
runSequence(
['eslint', 'build']
);
});
});
var Plugin = require('broccoli-plugin');
MyPlugin.prototype = Object.create(Plugin.prototype);
MyPlugin.prototype.constructor = MyPlugin;
function MyPlugin(inputNode) {
Plugin.call(this, [inputNode]);
}
MyPlugin.prototype.build = function() {
// Build from this.inputPaths[0] to this.outputPath
};
Es el fichero principal en donde escribiremos toda la lógica necesaria para compilar la aplicación.
/* Brocfile.js */
var tree = 'app/';
// @TODO transform tree
module.exports = tree;
Arrancar servidor
broccoli serve
Deploy
broccoli build outputPath
var Plugin = require('broccoli-plugin');
MyPlugin.prototype = Object.create(Plugin.prototype);
MyPlugin.prototype.constructor = MyPlugin;
function MyPlugin(inputNodes, options) {
options = options || {};
Plugin.call(this, inputNodes, {
annotation: options.annotation
});
this.options = options;
}
Es la función que se ejecuta en cada (re)build. Variables de contexto (sólo lectura):
MyPlugin.prototype.build = function() {
var inputBuffer = fs.readFileSync(path.join(this.inputPaths[2], 'foo.txt'));
var outputBuffer = someCompiler(inputBuffer);
fs.writeFileSync(path.join(this.outputPath, 'bar.txt'), outputBuffer);
};
Es una función de uso avanzado. Devuelve el contexto sobre el que se ejecutará la función build()
MyPlugin.prototype.getCallbackObject = function() {
return {
cachePath: '/tmp',
build: this.buildWrapper.bind(this)
};
};
MyPlugin.prototype.build = function() {
var self = this;
return new Promise(function(resolve, reject) {
reject ({
message: self.inputPaths[0] + 'is not a directory',
treeDir: self.inputPaths[0]
});
});
};
env, log, debug, beforeBuild, afterBuild, wrapBuild, ...
// Brocfile.js
var Funnel = require('broccoli-funnel');
var ES2015 = require('broccoli-es6modules');
var log = require('broccoli-stew').log;
var app = new Funnel('app', {
destDir: 'my-app-name'
});
var loggedApp = log(app, { output: 'tree', label: 'my-app-name tree' });
var transpiledTree = new ES2015(loggedApp);
module.exports = transpiledTree;
Debugging