I do not know why it works! None of us know why it works! But it seems to work!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var browserify = require('browserify'); | |
| var browserSync = require('browser-sync'); | |
| var del = require('del'); | |
| var gulp = require('gulp'); | |
| var less = require('gulp-less'); | |
| var minifycss = require('gulp-minify-css'); | |
| var notify = require('gulp-notify'); | |
| var plumber = require('gulp-plumber'); | |
| var reactify = require('reactify'); | |
| var runSequence = require('run-sequence'); | |
| var rename = require('gulp-rename'); | |
| var tap = require('gulp-tap'); | |
| var debug = require('gulp-debug'); | |
| var source = require('vinyl-source-stream'); | |
| var buffer = require('vinyl-buffer'); | |
| var uglify = require('gulp-uglify'); | |
| var gulp = require("gulp"); | |
| var babel = require("gulp-babel"); | |
| var babelify = require("babelify"); | |
| var hash = require("gulp-hash"); | |
| var paths = { | |
| app_js: './js/app.jsx', | |
| build: './static/**', | |
| build_html: './static/**/*.html', | |
| build_images: './static/img/**', | |
| build_scripts: './static/js/app/**', | |
| build_styles: './static/css/**', | |
| images: './img/**/*', | |
| html: './html/**/*.html', | |
| scripts: './js/**/*.js*', | |
| styles: ['./css/**/*.less', './css/**/*.css'] | |
| }; | |
| var onError = function(err) { | |
| notify.onError({ | |
| message: "Error: <%= error.message %>", | |
| subtitle: "Failure!", | |
| sound: "Beep", | |
| title: "Gulp" | |
| })(err); | |
| this.emit('end'); | |
| }; | |
| gulp.task('clean', function(done) { | |
| /* del([paths.build], done); */ | |
| }); | |
| gulp.task('clean-scripts', function(done) { | |
| del([paths.build_scripts], done); | |
| }); | |
| gulp.task('clean-styles', function(done) { | |
| del([paths.build_styles], done); | |
| }); | |
| gulp.task('clean-html', function(done) { | |
| del([paths.build_html], done); | |
| }); | |
| gulp.task('clean-images', function(done) { | |
| del([paths.build_images], done); | |
| }); | |
| gulp.task('bootstrap', [], function() { | |
| return gulp.src('./js/bootstrap.js') | |
| .pipe(buffer()) | |
| .pipe(uglify()) | |
| .pipe(rename('bootstrap.js')) | |
| .pipe(gulp.dest('./static/js/app/')); | |
| }); | |
| gulp.task('underscore', [], function() { | |
| return gulp.src('./js/underscore-min.js') | |
| .pipe(buffer()) | |
| .pipe(uglify()) | |
| .pipe(rename('underscore.js')) | |
| .pipe(gulp.dest('./static/js/app/')); | |
| }); | |
| gulp.task('scripts', ['bootstrap', 'underscore'], function() { | |
| return gulp.src(paths.app_js) | |
| .pipe(plumber({ | |
| errorHandler: onError | |
| })) | |
| .pipe(tap( | |
| function(file) { | |
| file.contents = browserify({ | |
| entries: [file.path], | |
| extensions: ['.jsx', '.js'], | |
| debug: false | |
| }) | |
| .transform(babelify.configure({ | |
| stage: 1, | |
| })) | |
| .transform(reactify) | |
| .bundle(); | |
| } | |
| )) | |
| .pipe(buffer()) | |
| //.pipe(uglify()) | |
| .pipe(rename('bundle.js')) | |
| .pipe(gulp.dest('./static/js/app/')); | |
| }); | |
| gulp.task('scripts-for-deploy', ['bootstrap', 'underscore'], function() { | |
| return gulp.src(paths.app_js) | |
| .pipe(plumber({ | |
| errorHandler: onError | |
| })) | |
| .pipe(tap( | |
| function(file) { | |
| file.contents = browserify({ | |
| entries: [file.path], | |
| extensions: ['.jsx', '.js'], | |
| debug: false | |
| }) | |
| .transform(babelify.configure({ | |
| stage: 1, | |
| })) | |
| .transform(reactify) | |
| .bundle(); | |
| } | |
| )) | |
| .pipe(buffer()) | |
| .pipe(rename('blotter-bundle.js')) | |
| .pipe(hash()) | |
| .pipe(gulp.dest('./static/js/app/')); | |
| }); | |
| gulp.task('styles', ['clean-styles'], function() { | |
| return gulp.src(paths.styles) | |
| .pipe(plumber({ | |
| errorHandler: onError | |
| })) | |
| .pipe(less()) | |
| .pipe(gulp.dest('./static/css')) | |
| .pipe(minifycss()) | |
| .pipe(rename({ | |
| suffix: '.min' | |
| })) | |
| .pipe(gulp.dest('./static/css/')); | |
| }); | |
| gulp.task('html', ['clean-html'], function() { | |
| gulp.src(paths.html) | |
| .pipe(gulp.dest('./static/')); | |
| }); | |
| gulp.task('images', ['clean-images'], function() { | |
| gulp.src(paths.images) | |
| .pipe(gulp.dest('./static/img/')); | |
| gulp.src(paths.images) | |
| .pipe(gulp.dest('./static/fonts/')); | |
| }); | |
| gulp.task('default', ['clean', 'scripts', 'styles', 'html', 'images'], function() {}); | |
| gulp.task('watch', function() { | |
| gulp.watch(paths.scripts, ['scripts']); | |
| gulp.watch(paths.styles, ['styles']); | |
| gulp.watch(paths.html, ['html']); | |
| gulp.watch(paths.images, ['images']); | |
| }); | |
| gulp.task('serve', function(cb) { | |
| runSequence('default', function() { | |
| browserSync({ | |
| browser: "Google Chrome", | |
| host: "127.0.0.1", | |
| injectChanges: false, | |
| notify: false, | |
| online: false, | |
| port: 8000, | |
| server: { | |
| baseDir: "./static/" | |
| } | |
| }); | |
| gulp.watch(paths.scripts, ['scripts']); | |
| gulp.watch(paths.styles, ['styles']); | |
| gulp.watch(paths.html, ['html']); | |
| gulp.watch(paths.images, ['images']); | |
| cb(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment