Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by tliang on 3/9/2018.
- */
- var gulp = require('gulp');
- var concat = require('gulp-concat');
- var uglify = require('gulp-uglify');
- var react = require('gulp-react');
- var htmlreplace = require('gulp-html-replace');
- var babel = require('gulp-babel');
- var source = require('vinyl-source-stream');
- var browserify = require('browserify');
- var watchify = require('watchify');
- var reactify = require('reactify');
- var streamify = require('gulp-streamify');
- var babelify = require('babelify');
- var gutil = require('gulp-util');
- var chalk = require('chalk');
- var sourcemaps = require('gulp-sourcemaps');
- function map_error(err) {
- if (err.fileName) {
- // regular error
- gutil.log(chalk.red(err.name)
- + ': '
- + chalk.yellow(err.fileName.replace(__dirname + '/src/', ''))
- + ': '
- + 'Line '
- + chalk.magenta(err.lineNumber)
- + ' & '
- + 'Column '
- + chalk.magenta(err.columnNumber || err.column)
- + ': '
- + chalk.blue(err.description))
- } else {
- // browserify error..
- gutil.log(chalk.red(err.name)
- + ': '
- + chalk.yellow(err.message))
- }
- //this.end()
- }
- var path = {
- HTML: 'src/index.html',
- ALL: ['src/*.js','src/**/*.js','src/index.html'],
- JS: ['src/*.js','src/**/*.js'],
- MINIFIED_OUT: 'build.min.js',
- DEST_SRC: './dist/src',
- DEST_BUILD: './dist/build',
- DEST: 'dist',
- ENTRY_POINT: './src/index.js',
- OUT: 'build.js'
- };
- gulp.task('build1',function(){
- return gulp.src(path.JS)
- .pipe(babel({
- presets:['es2015','react']
- }))
- .pipe(concat(path.MINIFIED_OUT))
- .pipe(uglify())
- .pipe(gulp.dest(path.DEST_BUILD));
- });
- gulp.task('build2', function(){
- browserify({
- entries: [path.ENTRY_POINT],
- debug:true
- }).transform ('babelify',{presets:['es2015','react']
- }).bundle()
- .pipe(source(path.MINIFIED_OUT))
- .pipe(streamify(uglify(path.MINIFIED_OUT)))
- .pipe(sourcemaps.write('./maps'))
- .pipe(gulp.dest(path.DEST_BUILD));
- });
- function build() {
- return gulp.src(path.JS)
- .pipe(babel({
- presets:['es2015','react']
- }))
- .pipe(concat(path.MINIFIED_OUT))
- .pipe(uglify())
- .pipe(gulp.dest(path.DEST_BUILD));
- }
- gulp.task('transform', function() {
- return gulp.src(path.JS)
- .pipe(babel({
- presets:['es2015','react']
- }))
- .pipe(gulp.dest(path.DEST_SRC));
- });
- gulp.task('copy',function() {
- return gulp.src(path.HTML)
- .pipe(gulp.dest(path.DEST));
- });
- /*gulp.task('watch',function() {
- gulp.watch(path.ALL,'transform');
- gulp.watch(path.ALL,'copy');
- });*/
- gulp.task('replaceHTML',function() {
- return gulp.src(path.HTML)
- .pipe(htmlreplace({
- 'js':'build/' + path.MINIFIED_OUT
- }))
- .pipe(gulp.dest(path.DEST));
- });
- gulp.task('copy-to-app',['build'],function () {
- return gulp.src('./build/reactapptest.js')
- .pipe(gulp.dest('C:\\Users\\tliang\\Workspaces\\SpringBoot2\\src\\main\\webapp\\WEB-INF\\jsp\\'))
- });
- gulp.task('watch',function () {
- gulp.watch(path.HTML,['copy']);
- var watcher = watchify(browserify({
- entries: [path.ENTRY_POINT],
- transform: [reactify],
- debug: true,
- cache: {}, packageCache: {}, fullPaths: true
- }));
- return watcher.on('update',function () {
- watcher.bundle()
- .pipe(source(path.OUT))
- .pipe(gulp.dest(path.DEST_SRC))
- console.log('Updated');
- })
- });
- gulp.task('build',function () {
- browserify({
- entries:[path.ENTRY_POINT],
- transform:['babelify',{presets:['es2015']}]
- })
- .bundle()
- .pipe(source(path.MINIFIED_OUT))
- .pipe(streamify(uglify(path.MINIFIED_OUT)))
- .pipe(gulp.dest(path.DEST_BUILD));
- });
- var b = watchify(browserify({
- entries: ['./src/index.js'],
- extensions: ['.js','.jsx'],
- debug: true,
- fullPaths: true,
- cache: {},
- packageCache: {}
- }),{poll:true});
- b.transform("babelify",{"presets":["es2015","react"],
- "plugins": ["transform-object-rest-spread"]});
- function bundle() {
- return b.bundle()
- .on('error',map_error)
- .pipe(source(path.MINIFIED_OUT))
- .pipe(gulp.dest(path.DEST_BUILD));
- }
- gulp.task('babel',bundle);
- gulp.task('default',['watch']);
- /*gulp.task('default',['copy-to-app']);*/
- gulp.task('production',['replaceHTML','build']);
Add Comment
Please, Sign In to add comment