lixin-web
Version:
vue and bootstrap
178 lines (157 loc) • 6.04 kB
JavaScript
var gulp = require('gulp');
var newer = require('gulp-newer');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
// var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var imageminWebp = require('imagemin-webp');
// var toDatauri = require('./build/toDatauri')
var rename = require("gulp-rename");
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var revdel = require('gulp-rev-delete-original');
var useref = require('gulp-useref');
var inject = require('gulp-inject');
var cdnizer = require("gulp-cdnizer");
require('./build/plugins_task')();
gulp.task('uglify', function() {
return gulp.src([
'webapp/module/**/*.js','!webapp/module/**/*.min.js',
'!webapp/module/ref/**','!webapp/module/webqq/**',
'!webapp/module/game/lottery/lottery.xy28.js'
])
.pipe(newer('production/module'))
.pipe(uglify())
.pipe(gulp.dest('production/module'));
});
gulp.task('vendor', function() {
return gulp.src([
'node_modules/es6-promise/dist/es6-promise.auto.min.js',
'webapp/dist/js/commons.bundle.js'
])
.pipe(concat('commons.bundle.js'))
.pipe(gulp.dest('./webapp/dist/js'));
});
//webpack ExtractTextPlugin css-loader minimize cssnano uniqueSelectors failure
// use postcss-cli
// gulp.task('css', function () {
// return gulp.src(['production/dist/css/*.css'])
// .pipe(cssnano({discardComments: {removeAll: true}}))
// .pipe(gulp.dest('production/dist/css'));
// });
//use webpack url-loader in production
// gulp.task('datauri', function () {
// gulp.src(['webapp/img/datauri/lottery/*.png'])
// .pipe(toDatauri('hot','new'))
// .pipe(concat('lottery.css'))
// .pipe(gulp.dest('webapp/css/datauri'));
//
// gulp.src(['webapp/img/datauri/event/*.png'])
// .pipe(toDatauri('game-event>.container:before','game-event-nav>li','game-event-nav>li:hover,.game-event-nav>.active'))
// .pipe(concat('event.css'))
// .pipe(gulp.dest('webapp/css/datauri'));
// });
gulp.task('copyJS', function() {
return gulp.src([
'webapp/module/**/*.min.js','webapp/module/**/*.swf',
'!webapp/module/ref/**','!webapp/module/webqq/**'
])
.pipe(newer('production/module'))
.pipe(gulp.dest('production/module'));
});
gulp.task('img',['webp'], function() {
return gulp.src('webapp/img/sample/**')
.pipe(newer('production/img/sample'))
.pipe(imagemin())
.pipe(gulp.dest('production/img/sample'));
});
gulp.task('webp', function() {
return gulp.src([
'webapp/img/sample/**/*preload.jpg','webapp/img/sample/**/*preload.png',
'!webapp/img/sample/index/index_bg_preload.jpg'
])
// newer and gulp-changed file's no result
// .pipe(newer('webapp/img/sample'))
.pipe(imagemin([imageminWebp({quality:85})]))
.pipe(rename({
extname: ".webp"
}))
.pipe(gulp.dest('webapp/img/sample'));
});
gulp.task('audio', function() {
return gulp.src('webapp/audio/**')
.pipe(newer('production/audio'))
.pipe(gulp.dest('production/audio'));
});
gulp.task('dist',['vendor'],function() {
return gulp.src(['webapp/dist/**','!webapp/dist/report.html','!webapp/dist/iconstats.json'])
.pipe(newer('production/dist'))
.pipe(gulp.dest('production/dist'));
});
gulp.task('webqq', function() {
return gulp.src(['webapp/module/webqq/**','!webapp/module/webqq/**/*.js','!webapp/module/webqq/**/*.css'])
.pipe(newer('production/module/webqq'))
.pipe(gulp.dest('production/module/webqq'));
});
gulp.task('injectHtml', function() {
gulp.src(['webapp/*.html','!webapp/include-*.html'])
.pipe(inject(gulp.src(['webapp/include-nav.html']), {
starttag: '<!-- inject:nav:{{ext}} -->',
transform: function (filePath, file) {
// return file contents as string
return file.contents.toString('utf8')
}
}))
.pipe(inject(gulp.src(['webapp/include-footer.html']), {
starttag: '<!-- inject:footer:{{ext}} -->',
transform: function (filePath, file) {
// return file contents as string
return file.contents.toString('utf8')
}
}))
.pipe(inject(gulp.src(['webapp/dist/iconstats.json']), {
starttag: '<!-- inject:icon -->',
transform: function (filePath, file) {
// return file contents as string
return JSON.parse(file.contents.toString('utf8')).html.join('')
}
}))
.pipe(inject(gulp.src(['webapp/dist/index.html']), {
starttag: '<!-- inject:preload -->',
transform: function (filePath, file) {
// return file contents as string
return file.contents.toString('utf8').match(/<link\srel=".+as="script">/g).join()
}
}))
.pipe(useref())
// .pipe(cdnizer({
// defaultCDNBase: "//test.lixinceshi.com:8888/",
// files:['img/**','dist/**','css/**','module/**']
// }))
.pipe(gulp.dest('production'));
});
gulp.task("revision", function(){
return gulp.src([
"production/**/*.css","production/**/*.js",
"!production/dist/js/chuck/**","!production/module/**/*.min.js",
"!production/module/game/lottery/lottery.11x5.js",
"!production/module/game/lottery/lottery.3d.js",
"!production/module/game/lottery/lottery.k3.js",
"!production/module/game/lottery/lottery.kl8.js",
"!production/module/game/lottery/lottery.pk10.js",
"!production/module/game/lottery/lottery.ssc.js",
"!production/module/lzma_worker.js"
])
.pipe(rev())
.pipe(revdel())
.pipe(gulp.dest('production'))
.pipe(rev.manifest())
.pipe(gulp.dest('production'))
})
gulp.task("revreplace",["revision"], function(){
var manifest = gulp.src("production/rev-manifest.json");
return gulp.src("production/*.html")
.pipe(revReplace({manifest: manifest}))
.pipe(gulp.dest('production'));
});
gulp.task('default', ['img','audio','copyJS','dist','webqq']);