Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gulp = require('gulp'),
- uglify = require('gulp-uglify-es').default,
- rename = require("gulp-rename"),
- gutil = require('gulp-util'),
- less = require('gulp-less'),
- cleanCSS = require('gulp-clean-css'),
- babel = require('gulp-babel'),
- c = require('ansi-colors'),
- tap = require('gulp-tap'),
- path = require('path'),
- changed = require('gulp-changed'),
- plumber = require('gulp-plumber');
- gulp.task('js', function () {
- return gulp.src(['./o/js/*.js'])
- .pipe(changed('./js/', {extension: '.min.js'}))
- .pipe(plumber())
- .pipe(babel({
- presets: ['@babel/env']
- }))
- .pipe(uglify())
- .on('error', function (err) {
- gutil.log(gutil.colors.red('[Error]'), err.toString());
- })
- .pipe(rename(function (path) {
- path.basename += '.min';
- path.extname = '.js';
- }))
- .pipe(gulp.dest('./js/'))
- .pipe(tap(function (file, t) {
- console.log(c.bold(`⚡️ ${c.grey(' [JS]')} ${c.red.bold(path.basename(file.path))} ${c.blue('✔')}`));
- }));
- });
- var lessFiles = [
- './o/LESS/index.less',
- './o/LESS/default.less'
- ];
- gulp.task('less', function () {
- return gulp.src(lessFiles) // path to your file
- .pipe(changed('./css/', {extension: '.min.css'}))
- .pipe(plumber())
- .pipe(less().on('error', function (err) {
- gutil.log(gutil.colors.red('[Error]'), err.toString());
- this.emit('end');
- }))
- .pipe(cleanCSS({ rebaseTo: './pathIsIrrevelant' }))
- .pipe(rename({ suffix: '.min' }))
- .pipe(gulp.dest('./css/'))
- .pipe(tap(function (file, t) {
- console.log(c.bold(`⚡️ ${c.grey(' [LESS]')} ${c.red.bold(path.basename(file.path))} ${c.blue('✔')}`));
- }));
- });
- gulp.task('build', function () {
- return Promise.all([
- new Promise(function (resolve, reject) {
- gulp.src(lessFiles) // path to your file
- .pipe(less().on('error', function (err) {
- gutil.log(gutil.colors.red('[Error]'), err.toString());
- this.emit('end');
- }))
- .pipe(cleanCSS({ rebaseTo: './pathIsIrrevelant' }))
- .pipe(rename({ suffix: '.min' }))
- .pipe(gulp.dest('./css/'))
- .on('end', function () {
- console.log(c.grey.bold('======== LESS 編譯完成 ========'));
- })
- .on('end', resolve)
- .pipe(tap(function (file, t) {
- console.log(c.bold(`⚡️ ${c.grey(' [LESS]')} ${c.red.bold(path.basename(file.path))} ${c.blue('✔')}`));
- }));
- }),
- new Promise(function (resolve, reject) {
- gulp.src(['./o/js/*.js'])
- .pipe(babel({
- presets: ['@babel/env']
- }))
- .pipe(uglify())
- .on('error', function (err) {
- gutil.log(gutil.colors.red('[Error]'), err.toString());
- })
- .pipe(rename(function (path) {
- path.basename += '.min';
- path.extname = '.js';
- }))
- .pipe(gulp.dest('./js/'))
- .on('end', function () {
- console.log(c.grey.bold('======== JS 編譯完成 ========'));
- })
- .on('end', resolve)
- .pipe(tap(function (file, t) {
- console.log(c.bold(`⚡️ ${c.grey(' [JS]')} ${c.red.bold(path.basename(file.path))} ${c.blue('✔')}`));
- }));
- })
- ]).then(function () {
- console.log();
- console.log(c.bold(`Build Completed 🎉 🎉 🎉`));
- console.log();
- })
- })
- gulp.task('watch', function (done) {
- gulp.watch('o/js/*.js', ['js']);
- gulp.watch('./o/LESS/*.less', ['less']);
- });
- gulp.task('default', ['build', 'watch']);
Add Comment
Please, Sign In to add comment