我想将coffee编译为js,然后将两个js文件合并为一个js。我怎样才能做到这一点?我试过gulp-useref,但似乎无法实现。
在:
<html>
<body>
<script src="lib.js"></script>
<script src="page.coffee" type="text/coffeescript"></script>
</body>
</html>
后:
<html>
<body>
<script src="mian.js"></script>
</body>
</html>
答案 0 :(得分:2)
var gulp = require('gulp');
var gulpCoffee = require('gulp-coffee');
var gulpUglify = require('gulp-uglify');
var gulpConcat = require('gulp-concat');
var merge2 = require('merge2');
gulp.task('default', function () {
var coffee = gulp.src('file2.coffee') //1
.pipe(gulpCoffee()); //1
var js = gulp.src('file1.js'); //2
merge2([coffee, js]) //3
.pipe(gulpConcat('main.js')) //3
.pipe(gulpUglify()) //4
.pipe(gulp.dest('dest')); //5
});