1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-01-18 04:48:50 +01:00
php-web-maker/gulpfile.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-01-13 14:54:49 +05:30
/*eslint-env node*/
2018-01-13 23:09:35 +05:30
const fs = require('fs');
const gulp = require('gulp');
const useref = require('gulp-useref');
const cleanCSS = require('gulp-clean-css');
const babelMinify = require('babel-minify');
2017-11-08 01:04:59 +05:30
2018-01-13 23:09:35 +05:30
function minifyJs(fileName) {
const content = fs.readFileSync(fileName, "utf8");
const minifiedContent = babelMinify(content).code;
fs.writeFileSync(fileName, minifiedContent);
console.log(`[${fileName}]: before -> ${content.length}kb`)
console.log(`[${fileName}]: after -> ${minifiedContent.length}kb`)
}
2018-01-13 14:54:49 +05:30
gulp.task('copyFiles', [], function() {
2018-01-13 14:55:39 +05:30
gulp
.src('src/lib/codemirror/theme/*')
.pipe(gulp.dest('app/lib/codemirror/theme'));
gulp
.src('src/lib/codemirror/mode/**/*')
.pipe(gulp.dest('app/lib/codemirror/mode'));
2018-01-13 14:59:37 +05:30
gulp
.src('src/lib/transpilers/*')
.pipe(gulp.dest('app/lib/transpilers'));
2018-01-13 14:54:49 +05:30
gulp.src('src/partials/*').pipe(gulp.dest('app/partials'));
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib'));
gulp.src('src/icon-48.png').pipe(gulp.dest('app'));
2018-01-13 14:55:39 +05:30
gulp
.src([
'src/FiraCode.ttf',
'src/Fixedsys.ttf',
'src/Inconsolata.ttf',
'src/Monoid.ttf'
])
.pipe(gulp.dest('app'));
2017-11-08 01:04:59 +05:30
});
2018-01-13 14:55:39 +05:30
gulp.task('useRef', ['copyFiles'], function() {
return gulp
.src('src/index.html')
.pipe(useref())
.pipe(gulp.dest('app'));
2017-11-08 01:04:59 +05:30
});
2018-01-13 23:09:35 +05:30
gulp.task('minify', ['useRef'], function() {
minifyJs('app/script.js');
minifyJs('app/vendor.js');
gulp.src('app/*.css')
.pipe(cleanCSS({ debug: true }, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(gulp.dest('app'));
});
gulp.task('generate-service-worker', ['minify'], function(callback) {
2017-11-19 23:47:02 +05:30
var swPrecache = require('sw-precache');
var rootDir = 'app';
2017-11-08 01:04:59 +05:30
2017-11-19 23:47:02 +05:30
swPrecache.write(
`${rootDir}/service-worker.js`,
{
staticFileGlobs: [
rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'
],
2018-01-14 00:39:03 +05:30
stripPrefix: `${rootDir}/`,
// has to be increased to around 2.8mb for sass.worker.js
maximumFileSizeToCacheInBytes: 2900000
2017-11-19 23:47:02 +05:30
},
callback
);
2017-11-08 01:04:59 +05:30
});
2017-11-19 23:47:02 +05:30
gulp.task('default', ['generate-service-worker']);