2015-12-28 23:34:32 +00:00
|
|
|
var path = require('path');
|
2015-04-29 22:45:02 +00:00
|
|
|
var exec = require('child_process').exec;
|
2016-01-25 00:01:37 +00:00
|
|
|
var url = require('url');
|
2015-04-29 22:45:02 +00:00
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
var gulp = require('gulp');
|
2015-06-07 22:11:03 +00:00
|
|
|
var gutil = require('gulp-util');
|
2015-12-28 23:34:32 +00:00
|
|
|
var nano = require('gulp-cssnano');
|
2015-01-17 01:37:21 +00:00
|
|
|
var autoprefixer = require('gulp-autoprefixer');
|
2015-05-12 21:50:55 +00:00
|
|
|
var concat = require('gulp-concat');
|
2015-06-07 23:06:08 +00:00
|
|
|
var cache = require('gulp-cached');
|
2015-12-28 23:34:32 +00:00
|
|
|
var express = require('express');
|
2016-01-25 00:01:37 +00:00
|
|
|
var proxy = require('express-http-proxy');
|
2015-12-28 23:34:32 +00:00
|
|
|
var webpack = require('webpack');
|
2017-04-14 02:33:44 +00:00
|
|
|
var through = require('through2');
|
|
|
|
var br = require('brotli');
|
|
|
|
|
|
|
|
function brotli(opts) {
|
|
|
|
return through.obj(function(file, enc, callback) {
|
|
|
|
if (file.isNull()) {
|
|
|
|
return callback(null, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file.isStream()) {
|
|
|
|
this.emit('error', new gutil.PluginError('brotli', 'Streams not supported'));
|
|
|
|
} else if (file.isBuffer()) {
|
|
|
|
file.path += '.br';
|
|
|
|
file.contents = new Buffer(br.compress(file.contents, opts).buffer);
|
|
|
|
return callback(null, file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-06-07 22:11:03 +00:00
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
gulp.task('css', function() {
|
2016-02-03 01:22:45 +00:00
|
|
|
return gulp.src(['src/css/fonts.css', 'src/css/fontello.css', 'src/css/style.css'])
|
2015-12-28 23:34:32 +00:00
|
|
|
.pipe(concat('bundle.css'))
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(nano())
|
|
|
|
.pipe(gulp.dest('dist'));
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
gulp.task('js', function(cb) {
|
|
|
|
var config = require('./webpack.config.prod.js');
|
|
|
|
var compiler = webpack(config);
|
2015-01-17 01:37:21 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
process.env['NODE_ENV'] = 'production';
|
2015-06-07 22:11:03 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
compiler.run(function(err, stats) {
|
|
|
|
if (err) throw new gutil.PluginError('webpack', err);
|
2015-06-07 22:11:03 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
gutil.log('[webpack]', stats.toString({
|
|
|
|
colors: true
|
|
|
|
}));
|
2016-01-06 23:28:11 +00:00
|
|
|
|
|
|
|
if (stats.hasErrors()) process.exit(1);
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
cb();
|
|
|
|
});
|
2015-06-01 22:09:28 +00:00
|
|
|
});
|
|
|
|
|
2015-02-16 20:53:01 +00:00
|
|
|
gulp.task('fonts', function() {
|
2015-12-28 23:34:32 +00:00
|
|
|
return gulp.src('src/font/*')
|
|
|
|
.pipe(gulp.dest('dist/font'));
|
2015-02-16 20:53:01 +00:00
|
|
|
});
|
|
|
|
|
2016-02-03 01:22:45 +00:00
|
|
|
gulp.task('fonts:woff', function() {
|
|
|
|
return gulp.src('src/font/*(*.woff|*.woff2)')
|
2017-04-14 02:33:44 +00:00
|
|
|
.pipe(gulp.dest('dist/br/font'));
|
2016-02-03 01:22:45 +00:00
|
|
|
});
|
|
|
|
|
2015-05-25 02:00:21 +00:00
|
|
|
gulp.task('config', function() {
|
2015-12-28 23:34:32 +00:00
|
|
|
return gulp.src('../config.default.toml')
|
2017-04-14 02:33:44 +00:00
|
|
|
.pipe(gulp.dest('dist/br'));
|
2015-05-25 02:00:21 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
function compress() {
|
2017-04-14 02:33:44 +00:00
|
|
|
return gulp.src(['dist/**/!(*.br|*.woff|*.woff2)', '!dist/{br,br/**}'])
|
|
|
|
.pipe(brotli({ quality: 11 }))
|
|
|
|
.pipe(gulp.dest('dist/br'));
|
2015-12-28 23:34:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 02:33:44 +00:00
|
|
|
gulp.task('compress', ['css', 'js', 'fonts'], compress);
|
|
|
|
gulp.task('compress:dev', ['css', 'fonts'], compress);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2017-04-14 02:33:44 +00:00
|
|
|
gulp.task('bindata', ['compress', 'config'], function(cb) {
|
|
|
|
exec('go-bindata -nomemcopy -nocompress -pkg assets -o ../assets/bindata.go -prefix "dist/br" dist/br/...', cb);
|
2015-02-05 00:37:34 +00:00
|
|
|
});
|
|
|
|
|
2017-04-14 02:33:44 +00:00
|
|
|
gulp.task('bindata:dev', ['compress:dev', 'config'], function(cb) {
|
|
|
|
exec('go-bindata -debug -pkg assets -o ../assets/bindata.go -prefix "dist/br" dist/br/...', cb);
|
2015-06-07 22:21:10 +00:00
|
|
|
});
|
|
|
|
|
2017-04-14 02:33:44 +00:00
|
|
|
gulp.task('dev', ['css', 'fonts', 'fonts:woff', 'config', 'compress:dev', 'bindata:dev'], function() {
|
2015-12-28 23:34:32 +00:00
|
|
|
gulp.watch('src/css/*.css', ['css']);
|
|
|
|
|
|
|
|
var config = require('./webpack.config.dev.js');
|
|
|
|
var compiler = webpack(config);
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
app.use(require('webpack-dev-middleware')(compiler, {
|
|
|
|
noInfo: true,
|
|
|
|
publicPath: config.output.publicPath
|
|
|
|
}));
|
2015-04-29 22:45:02 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
app.use(require('webpack-hot-middleware')(compiler));
|
2015-04-29 22:45:02 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
app.use('/', express.static('dist'));
|
|
|
|
|
2016-01-25 00:01:37 +00:00
|
|
|
app.use('*', proxy('localhost:1337', {
|
|
|
|
forwardPath: function(req, res) {
|
2017-04-21 01:31:35 +00:00
|
|
|
return req.originalUrl;
|
2016-01-25 00:01:37 +00:00
|
|
|
}
|
|
|
|
}));
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2016-01-11 20:04:57 +00:00
|
|
|
app.listen(3000, function (err) {
|
2015-12-28 23:34:32 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Listening at http://localhost:3000');
|
|
|
|
});
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
|
|
|
|
2017-04-14 02:33:44 +00:00
|
|
|
gulp.task('build', ['css', 'js', 'fonts', 'fonts:woff', 'config', 'compress', 'bindata']);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
gulp.task('default', ['dev']);
|