-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
164 lines (150 loc) · 4.91 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');
var del = require('del');
var htmlmin = require('gulp-htmlmin');
var ngTemplate = require('gulp-angular-templatecache');
var merge = require('merge-stream');
var autoprefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var umd = require('gulp-umd');
var paths = {
scripts: ['src/js/*.js'],
less : ['src/css/*.less'],
tpl : ['src/tpl/*.html']
};
// Not all tasks need to use streams
// A gulpfile is just another node program and you can use any package available on npm
gulp.task('clean', function (cb) {
// You can use multiple globbing patterns as you would with `gulp.src`
del(['dest'], cb);
});
gulp.task('templates:dev', function () {
return gulp.src(paths.tpl)
.pipe(ngTemplate("wt-editor.tpl.js", {
root : "wt-editor",
module: "wt.editor.tpl",
standalone:true
}))
.pipe(gulp.dest('src'));
});
gulp.task('templates:dist', function () {
return gulp.src('src/tpl/*.html')
.pipe(ngTemplate("wt-editor.tpl-min.js", {
root : "wt-editor",
module: "wt.editor.tpl"
}))
.pipe(uglify())
.pipe(gulp.dest('dist')); // output file: 'dist/js/templates.js'
});
gulp.task('scripts:dev', function () {
return gulp.src(paths.scripts)
.pipe(concat('wt-editor.js'))
.pipe(gulp.dest('src'));
});
//gulp.task('scripts:dist', function () {
// return gulp.src(paths.scripts)
// .pipe(uglify())
// .pipe(concat('wt-editor-min.js'))
// .pipe(gulp.dest('dist'));
//});
gulp.task('scripts:dist', ['templates:dev'],function () {
return gulp.src(paths.scripts.concat(["src/wt-editor.tpl.js"]))
.pipe(concat('wt-editor.js'))
.pipe(umd({
exports: function(file) {
return 'wtEditor';
},
namespace: function(file) {
return 'wtEditor';
},
dependencies: function(file) {
return [
{
name: '$',
amd: 'jquery',
cjs: 'jquery',
global: 'jQuery',
param: '$'
},
{
name: 'marked',
amd: 'marked',
cjs: 'marked',
global: 'marked',
param: 'marked'
}
];
}
}))
.pipe(gulp.dest('dist'));
});
gulp.task('scripts:dist_all_min', ['templates:dev'],function () {
return gulp.src(paths.scripts.concat(["src/wt-editor.tpl.js"]))
.pipe(umd({
exports: function(file) {
return 'wtEditor';
},
namespace: function(file) {
return 'wtEditor';
},
dependencies: function(file) {
return [
{
name: '$',
amd: 'jquery',
cjs: 'jquery',
global: 'jQuery',
param: '$'
},
{
name: 'marked',
amd: 'marked',
cjs: 'marked',
global: 'marked',
param: 'marked'
}
];
}
}))
.pipe(uglify())
.pipe(concat('wt-editor-min.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('lessc:dev', function () {
return gulp.src('./src/css/*.less')
.pipe(less())
.pipe(gulp.dest('./src/css/'));
});
gulp.task('lessc:dist', function () {
return gulp.src('./src/css/*.less')
.pipe(less())
.pipe(concat('editor.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade : false
}))
.pipe(gulp.dest('dist'));
});
gulp.task('lessc:dist_all_min', function () {
return gulp.src('./src/css/*.less')
.pipe(less())
.pipe(concat('editor-min.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade : false
}))
.pipe(minifycss())
.pipe(gulp.dest('dist'));
});
// Rerun the task when a file changes
gulp.task('watch', function () {
gulp.watch(paths.scripts, ['scripts:dev']);
gulp.watch(paths.scripts, ['templates:dev']);
gulp.watch(paths.less, ['lessc:dev']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'scripts:dev', 'templates:dev', 'lessc:dev']);
gulp.task('build', ['clean','watch', 'scripts:dist','scripts:dist_all_min', 'lessc:dist','lessc:dist_all_min','templates:dist']);