Last active
August 29, 2015 14:17
-
-
Save teddy-ma/4e473ef609116f4441cf to your computer and use it in GitHub Desktop.
常用 gulp 例子
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// task | |
gulp.task('minify-html', function () { | |
gulp.src('app/*.html') // path to your files | |
.pipe(minifyHtml()) | |
.pipe(gulp.dest('dist/html')); | |
}); | |
gulp.task('rename', function () { | |
gulp.src('app/scripts/app.coffee') // path to your file | |
.pipe(coffee()) // compile coffeeScript | |
.pipe(rename('renamed.js')) // rename into "renamed.js" (original name "one.js") | |
.pipe(gulp.dest('dist/renamed')); | |
}); | |
// Get copyright using NodeJs file system | |
var getCopyrightVersion = function () { | |
return fs.readFileSync('Copyright'); | |
}; | |
// Get version using NodeJs file system | |
var getVersion = function () { | |
return fs.readFileSync('Version'); | |
}; | |
// task | |
gulp.task('concat-copyright', function () { | |
gulp.src('app/*.html') // path to your files | |
.pipe(concat('concat-copyright.txt')) // 把所有 html 文件内容都连起来,并且命名 | |
.pipe(header(getCopyrightVersion(), {version: getVersion()})) // copyright 的内容放前面 | |
.pipe(gulp.dest('dist/cp')); | |
}); | |
// task 把所有 coffee 文件打包在一起并且加上 copyright | |
gulp.task('bundle-one', function () { | |
gulp.src('app/scripts/*.coffee') // path to your files | |
.pipe(coffeelint()) // lint files | |
.pipe(coffeelint.reporter('fail')) // make sure the task fails if not compliant | |
.pipe(concat('bundleOne.js')) // concat files | |
.pipe(coffee()) // compile coffee | |
.pipe(uglify()) // minify files | |
.pipe(header(getCopyrightVersion(), {version: getVersion()})) // Add the copyright | |
.pipe(gulp.dest('dist/allcoffee')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment