-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
135 lines (124 loc) · 3.1 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
const gulp = require('gulp');
const rollup = require('rollup').rollup;
const babel = require('rollup-plugin-babel');
const buble = require('rollup-plugin-buble');
const eslint = require('rollup-plugin-eslint');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const uglifyRollup = require('rollup-plugin-uglify');
const multiEntry = require('rollup-plugin-multi-entry');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const jshint = require('gulp-jshint');
const stylish = require('jshint-stylish');
const path = require('path');
const rename = require('gulp-rename');
const browserSync = require('browser-sync').create();
let sourcemapsDest = 'sourcemaps';
let watch = {
js: 'tests/js/*.js',
html: '**/*.html'
};
function errorlog (error) {
console.error.bind(error);
this.emit('end');
}
gulp.task('script', function () {
return rollup({
entry: 'src/go-native.js',
context: 'window',
plugins: [
resolve({
jsnext: true,
main: true,
browser: true,
}),
],
}).then(function (bundle) {
return bundle.write({
dest: 'dist/go-native.js',
format: 'iife',
moduleName: 'gn',
})
})
});
gulp.task('min', ['script'], function () {
return gulp.src('dist/go-native.js')
.pipe(uglify())
.pipe(rename('go-native.min.js'))
.pipe(gulp.dest('dist'))
});
gulp.task('script-ie8', function () {
return gulp.src([
"bower_components/nwmatcher/src/nwmatcher.js",
"bower_components/selectivizr_will/selectivizr.js",
"bower_components/respond/dest/respond.src.js",
"src/es5/**/*.js",
"src/ie8/**/*.js"
])
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(concat('go-native.ie8.js'))
.on('error', errorlog)
.pipe(gulp.dest('dist'))
.pipe(rename('go-native.ie8.min.js'))
.pipe(uglify({
mangle: false,
output: {
quote_keys: true,
},
compress: {
properties: false,
}
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
gulp.task('test', function () {
return rollup({
entry: 'tests/js/test.es2015.src.js',
context: 'window',
plugins: [
resolve({
jsnext: true,
main: true,
browser: true,
}),
],
}).then(function (bundle) {
return bundle.write({
dest: 'tests/js/test.es2015.js',
format: 'iife',
moduleName: 'gn',
})
})
});
// browser-sync
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: './'
},
port: '3000',
open: false,
notify: false
});
});
// Watch
gulp.task('watch', function () {
gulp.watch('src/**/*.js', ['min']).on('change', browserSync.reload);
gulp.watch(watch.js).on('change', browserSync.reload);
gulp.watch(watch.html).on('change', browserSync.reload);
});
// Default Task
gulp.task('default', [
'browserSync',
'watch',
// 'script',
// 'min',
// 'test'
// 'script-ie8',
]);