module.exports = function (grunt) { "use strict"; // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), jshint: { files: ['<%= pkg.name %>.js'] }, concat: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, main: { src: ['<%= pkg.name %>.js'], dest: 'build/<%= pkg.name %>.js' } }, uglify: { main: { src: 'build/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); grunt.loadTasks('tasks/'); grunt.registerTask('default', ['jshint', 'concat', 'uglify']); return grunt; };
module.exports = function (grunt) { "use strict"; // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), karma: { options: { configFile: 'karma.conf.js' }, unit: {}, travis: { browsers: ['Firefox'] } }, jshint: { files: ['<%= pkg.name %>.js'] }, concat: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, main: { src: ['<%= pkg.name %>.js'], dest: 'build/<%= pkg.name %>.js' } }, uglify: { main: { src: 'build/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } }, copy: { main: { expand: true, cwd: 'docs/', src: ['**', '!**/*.tpl.html'], dest: 'build/' } }, buildcontrol: { options: { dir: 'build', connectCommits: false, commit: true, push: true, message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%' }, pages: { options: { remote: 'git@github.com:just-boris/angular-ymaps.git', branch: 'gh-pages' } } } }); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-karma'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-build-control'); grunt.registerTask('test', 'Run tests on singleRun karma server', function() { if (process.env.TRAVIS) { //this task can be executed in Travis-CI grunt.task.run('karma:travis'); } else { grunt.task.run('karma:unit'); } }); grunt.registerTask('build', ['jshint', 'test', 'concat', 'uglify']); grunt.registerTask('default', ['build', 'demo']); grunt.registerTask('build-gh', ['default', 'buildcontrol:pages']); return grunt; };
$ cat *.coffee \ | coffee \ | concat \ | uglify \ > build/app.min.js
pipe()
function is used instead of the vertical bar here.
gulp.src('*.coffee') .pipe(coffee()) .pipe(concat()) .pipe(uglify()) .pipe(gulp.dest('build/'))
npm install -g gulp
less
and csso
.
var gulp = require('gulp'); var csso = require('gulp-csso'); var less = require('gulp-less'); gulp.task('default', function() { return gulp.src('bower_components/bootstrap/less/bootstrap.less') .pipe(less()) .pipe(csso()) .pipe(gulp.dest('dest/')); });
module.exports = function(grunt) { require('time-grunt')(grunt); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-csso'); grunt.initConfig({ less: { compile: { src: 'bower_components/bootstrap/less/bootstrap.less', dest: 'dest/bootstrap.css' } }, csso: { compile: { src: 'dest/bootstrap.css', dest: 'dest/bootstrap.min.css' } } }); grunt.registerTask('default', ['less', 'csso']); };
var stream = require('stream'), greeterStream = new stream.Transform({objectMode: true}); greeterStream._transform = function(str) { this.push('Hello, '+str+'!'); }; greeterStream.pipe(process.stdout) greeterStream.write('world'); // Hello, world! greeterStream.write('uncle Ben'); // Hello, uncle Ben!
_transform
method. He is given a string at the entrance so that we process it and return it. We write to him, and he converts. You do not need to connect anything, this is the node.js native API. To see how all this is embedded in the Gulp, remove the cover from it and look inside. There we will see two modules: Orchestrator and Vinyl fs. Orchestrator conducts streams, builds them in a queue, tries to perform them with maximum parallelism, and generally ensures that everything works like an orchestra. With Vinyl everything is a little more interesting. A stream is a data set, and we collect files. It is more than just data; it is also a name, an extension, and other attributes. I would like to somehow separate the continuous stream into separate files. Vinyl does all that. In essence, this is a wrapper over files: we receive not just data, but objects. Vinyl puts all the required fields there. We can modify and manage them.
var coffeeFile = new File({ cwd: "/", base: "/test/", path: "/test/file.coffee" contents: new Buffer("test = 123") });
var through = require('through2'); module.exports = function() { return through.obj(function(/**Vinyl*/file, enc, callback) { var content = file.contents.toString('utf-8'), checksum = createMD5(content), file.path = checksum; this.push(file); callback(); }); };
var freeze = require('./index.js') var testStream = freeze() testStream.on('data', function(file) { //assert here }); testStream.write(fakeFile);
var map = require('vinyl-map'); var yate = require('yate'); gulp.src('*.yate') .pipe(map(function(code, filename) { // return yate.compile(code.toString('utf-8')).js; })) .pipe(gulp.dest('dist/'))
gulp.task('jekyll', function() { return gulp.src('_posts/**') .pipe(liquid.collectMeta()) // .pipe(post()) // .pipe(gulp.src('!_*/?*')) // .pipe(markdown()) // html, .pipe(liquid.template()) // .pipe(gulp.dest('_site/')); // });
Source: https://habr.com/ru/post/239993/