support html5 application cache

This commit is contained in:
MaysWind 2016-08-03 00:03:00 +08:00
parent 0623374b39
commit 9b1544880d
4 changed files with 39 additions and 11 deletions

View file

@ -41,24 +41,29 @@ gulp.task('lint', function () {
});
gulp.task('html', ['styles', 'scripts', 'views'], function () {
return gulp.src('src/*.html')
.pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
return gulp.src([
'src/*.html'
]).pipe($.useref({searchPath: ['.tmp', 'src', '.']}))
.pipe($.if('js/*.js', $.replace(/\/\/# sourceMappingURL=.*/g, '')))
.pipe($.if('css/*.css', $.replace(/\/\*# sourceMappingURL=.* \*\/$/g, '')))
.pipe($.if(['js/moment-with-locales-*.min.js', 'js/plugins.min.js', 'js/aria-ng.min.js'], $.uglify({preserveComments: 'license'})))
.pipe($.if(['css/plugins.min.css', 'css/aria-ng.min.css'], $.cssnano({safe: true, autoprefixer: false})))
.pipe($.if(['js/plugins.min.js', 'js/aria-ng.min.js', 'css/plugins.min.css', 'css/aria-ng.min.css'], $.rev()))
.pipe($.if('*.html', $.htmlmin({collapseWhitespace: true})))
.pipe($.revReplace())
.pipe(gulp.dest('dist'));
});
gulp.task('langs', function () {
return gulp.src('src/langs/**/*')
.pipe(gulp.dest('dist/langs'));
return gulp.src([
'src/langs/**/*'
]).pipe(gulp.dest('dist/langs'));
});
gulp.task('images', function () {
return gulp.src('src/imgs/**/*')
.pipe(gulp.dest('dist/imgs'));
return gulp.src([
'src/imgs/**/*'
]).pipe(gulp.dest('dist/imgs'));
});
gulp.task('fonts', function () {
@ -69,6 +74,20 @@ gulp.task('fonts', function () {
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('manifest', function () {
return gulp.src([
'dist/**'
], {base: 'dist/'})
.pipe($.manifest({
hash: true,
preferOnline: true,
network: ['*'],
filename: 'index.manifest',
exclude: 'index.manifest'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('extras', function () {
return gulp.src([
'src/*.*',
@ -94,7 +113,7 @@ gulp.task('serve', ['styles', 'scripts', 'fonts'], function () {
gulp.watch([
'src/*.html',
'src/langs/*.json',
'src/langs/*.txt',
'src/views/*.html',
'src/imgs/**/*',
'.tmp/fonts/**/*'
@ -115,10 +134,14 @@ gulp.task('serve:dist', function () {
});
});
gulp.task('build', ['lint', 'html', 'langs', 'images', 'fonts', 'extras'], function () {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
gulp.task('info', function () {
return gulp.src([
'dist/**/*'
]).pipe($.size({title: 'build', gzip: true}));
});
gulp.task('build', $.sequence('lint', 'html', 'langs', 'images', 'fonts', 'manifest', 'extras', 'info'));
gulp.task('default', ['clean'], function () {
gulp.start('build');
});

View file

@ -14,8 +14,12 @@
"gulp-htmlmin": "^2.0.0",
"gulp-if": "^2.0.1",
"gulp-load-plugins": "^1.2.4",
"gulp-manifest": "^0.1.1",
"gulp-plumber": "^1.1.0",
"gulp-replace": "^0.5.4",
"gulp-rev": "^7.1.0",
"gulp-rev-replace": "^0.4.3",
"gulp-sequence": "^0.4.5",
"gulp-size": "^2.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.4",

View file

@ -13,6 +13,7 @@ if [ $CI == "true" ] && [ $CIRCLE_BRANCH == "master" ]; then
rm -rf langs;
rm -rf imgs;
rm -f index.html;
rm -f index.manifest;
rm -f README.md;
rm -f LICENSE;
@ -31,4 +32,4 @@ if [ $CI == "true" ] && [ $CIRCLE_BRANCH == "master" ]; then
rm -rf $CIRCLE_ARTIFACTS/dist;
rm -f $CIRCLE_ARTIFACTS/README.md;
rm -f $CIRCLE_ARTIFACTS/LICENSE;
fi
fi

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="ariaNg">
<html ng-app="ariaNg" manifest="index.manifest">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>