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;
|
|
|
|
|
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 htmlmin = require('gulp-htmlmin');
|
|
|
|
var nano = require('gulp-cssnano');
|
2015-01-17 01:37:21 +00:00
|
|
|
var autoprefixer = require('gulp-autoprefixer');
|
2015-02-05 00:37:34 +00:00
|
|
|
var gzip = require('gulp-gzip');
|
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');
|
|
|
|
var webpack = require('webpack');
|
2015-06-07 22:11:03 +00:00
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
gulp.task('html', function() {
|
2015-12-28 23:34:32 +00:00
|
|
|
return gulp.src('src/*.html')
|
|
|
|
.pipe(htmlmin({
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeAttributeQuotes: true
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist'));
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('css', function() {
|
2015-12-28 23:34:32 +00:00
|
|
|
return gulp.src(['src/css/fontello.css', 'src/css/style.css'])
|
|
|
|
.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
|
|
|
|
}));
|
|
|
|
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
|
|
|
});
|
|
|
|
|
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')
|
|
|
|
.pipe(gulp.dest('dist/gz'));
|
2015-05-25 02:00:21 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
function compress() {
|
|
|
|
return gulp.src(['dist/**/!(*.gz)', '!dist/{gz,gz/**}'])
|
|
|
|
.pipe(gzip())
|
|
|
|
.pipe(gulp.dest('dist/gz'));
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('gzip', ['html', 'css', 'js', 'fonts'], compress);
|
|
|
|
gulp.task('gzip:dev', ['html', 'css', 'fonts'], compress);
|
|
|
|
|
|
|
|
gulp.task('bindata', ['gzip', 'config'], function(cb) {
|
|
|
|
exec('go-bindata -nomemcopy -nocompress -pkg assets -o ../assets/bindata.go -prefix "dist/gz" dist/gz/...', cb);
|
2015-02-05 00:37:34 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
gulp.task('bindata:dev', ['gzip:dev', 'config'], function(cb) {
|
|
|
|
exec('go-bindata -debug -pkg assets -o ../assets/bindata.go -prefix "dist/gz" dist/gz/...', cb);
|
2015-06-07 22:21:10 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
gulp.task('dev', ['html', 'css', 'fonts', 'config', 'gzip:dev', 'bindata:dev'], function() {
|
|
|
|
gulp.watch('src/*.html', ['html']);
|
|
|
|
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'));
|
|
|
|
|
|
|
|
app.get('*', function (req, res) {
|
|
|
|
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
|
|
|
|
});
|
|
|
|
|
|
|
|
app.listen(3000, 'localhost', function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Listening at http://localhost:3000');
|
|
|
|
});
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
gulp.task('build', ['html', 'css', 'js', 'fonts', 'config', 'gzip', 'bindata']);
|
|
|
|
|
|
|
|
gulp.task('default', ['dev']);
|