mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-21 23:12:19 +02:00
gulp: add minification
This commit is contained in:
@ -115,7 +115,7 @@
|
|||||||
"no-shadow": "error",
|
"no-shadow": "error",
|
||||||
"no-shadow-restricted-names": "error",
|
"no-shadow-restricted-names": "error",
|
||||||
"no-spaced-func": "error",
|
"no-spaced-func": "error",
|
||||||
"no-sync": "error",
|
"no-sync": "off",
|
||||||
"no-ternary": "off",
|
"no-ternary": "off",
|
||||||
"no-throw-literal": "error",
|
"no-throw-literal": "error",
|
||||||
"no-trailing-spaces": "error",
|
"no-trailing-spaces": "error",
|
||||||
@ -138,7 +138,7 @@
|
|||||||
"no-warning-comments": "off",
|
"no-warning-comments": "off",
|
||||||
"no-whitespace-before-property": "error",
|
"no-whitespace-before-property": "error",
|
||||||
"no-with": "error",
|
"no-with": "error",
|
||||||
"object-curly-spacing": ["error", "always"],
|
"object-curly-spacing": "off",
|
||||||
"object-property-newline": "off",
|
"object-property-newline": "off",
|
||||||
"object-shorthand": "off",
|
"object-shorthand": "off",
|
||||||
"one-var": "off",
|
"one-var": "off",
|
||||||
|
28
gulpfile.js
28
gulpfile.js
@ -1,8 +1,18 @@
|
|||||||
/*eslint-env node*/
|
/*eslint-env node*/
|
||||||
|
|
||||||
var gulp = require('gulp');
|
const fs = require('fs');
|
||||||
var useref = require('gulp-useref');
|
const gulp = require('gulp');
|
||||||
|
const useref = require('gulp-useref');
|
||||||
|
const cleanCSS = require('gulp-clean-css');
|
||||||
|
const babelMinify = require('babel-minify');
|
||||||
|
|
||||||
|
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`)
|
||||||
|
}
|
||||||
gulp.task('copyFiles', [], function() {
|
gulp.task('copyFiles', [], function() {
|
||||||
gulp
|
gulp
|
||||||
.src('src/lib/codemirror/theme/*')
|
.src('src/lib/codemirror/theme/*')
|
||||||
@ -33,7 +43,19 @@ gulp.task('useRef', ['copyFiles'], function() {
|
|||||||
.pipe(gulp.dest('app'));
|
.pipe(gulp.dest('app'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('generate-service-worker', ['useRef'], function(callback) {
|
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) {
|
||||||
var swPrecache = require('sw-precache');
|
var swPrecache = require('sw-precache');
|
||||||
var rootDir = 'app';
|
var rootDir = 'app';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user