forked from futurepress/epub.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
166 lines (133 loc) · 3.65 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
165
166
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var onError = function (err) {
gutil.log(gutil.colors.green(err));
};
var server = require("./tools/serve.js");
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sourcemaps = require('gulp-sourcemaps');
var size = require('gulp-size');
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var webpackConfig = require("./webpack.config");
var Server = require('karma').Server;
// modify some webpack config options
var watchConfig = Object.create(webpackConfig);
watchConfig.devtool = "sourcemap";
watchConfig.watch = true;
// create a single instance of the compiler to allow caching
var watchCompiler = webpack(watchConfig);
var buildDocs = require('gulp-documentation');
// Lint JS
gulp.task('lint', function() {
return gulp.src('src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('bundle', function (cb) {
webpack(webpackConfig, function(err, stats) {
if(err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack-bundle]", stats.toString({
colors: true,
chunks: true
}));
cb();
});
});
// Minify JS
gulp.task('minify', ['bundle'], function(){
var uglifyOptions = {
mangle: true,
preserveComments : "license"
};
return gulp.src(['dist/epub.js', 'dist/polyfills.js'])
.pipe(plumber({ errorHandler: onError }))
.pipe(rename({suffix: '.min'}))
// .pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify(uglifyOptions))
// .pipe(sourcemaps.write('./'))
.pipe(size({ showFiles: true }))
.pipe(gulp.dest('dist'));
});
// Watch Our Files
gulp.task('watch', function(cb) {
watchCompiler.watch({}, function(err, stats) {
if(err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack-watch]", stats.toString({
colors: true,
chunks: false
}));
});
});
gulp.task('test', function(done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: false
}, done).start();
});
gulp.task('test:once', function(done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task("serve", function(callback) {
server();
/*
var serverConfig = Object.create(webpackConfig);
serverConfig.devtool = "eval";
serverConfig.debug = true;
serverConfig.watch = true;
// Start a webpack-dev-server
new WebpackDevServer(webpack(serverConfig), {
stats: {
colors: true,
chunks: false
}
}).listen(8080, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/examples/index.html");
});
*/
});
gulp.task('docs:md', function () {
return gulp.src('./src/epub.js')
.pipe(buildDocs('md'))
.pipe(gulp.dest('documentation/md'));
});
gulp.task('docs:html', function () {
return gulp.src('./src/epub.js')
.pipe(buildDocs('html'))
.pipe(gulp.dest('documentation/html'));
});
gulp.task('docs:watch', function () {
return gulp.watch('./src/**/*.js', ['docs:html']);
});
gulp.task('docs', ['docs:html', 'docs:md']);
// Default
gulp.task('default', ['lint', 'bundle']);
function bundle(done) {
if (!done) {
webpackConfig.watch = true;
} else {
webpackConfig.watch = false;
}
webpack(webpackConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
colors: true,
chunks: false
}));
done && done();
});
}