#35 added bundling to gulpfile
This commit is contained in:
parent
0cb210dd4b
commit
df33bdfa84
28
gulpfile.js
28
gulpfile.js
|
@ -3,6 +3,10 @@ const cssnano = require('cssnano')
|
||||||
const gulpLoadPlugins = require('gulp-load-plugins')
|
const gulpLoadPlugins = require('gulp-load-plugins')
|
||||||
const uglify = require('gulp-uglify-es').default;
|
const uglify = require('gulp-uglify-es').default;
|
||||||
const del = require('del');
|
const del = require('del');
|
||||||
|
const browserify = require('browserify');
|
||||||
|
const babelify = require('babelify');
|
||||||
|
const source = require('vinyl-source-stream');
|
||||||
|
const buffer = require('vinyl-buffer');
|
||||||
|
|
||||||
const $ = gulpLoadPlugins()
|
const $ = gulpLoadPlugins()
|
||||||
|
|
||||||
|
@ -29,7 +33,6 @@ const tmp = {
|
||||||
scripts: '.tmp/javascript',
|
scripts: '.tmp/javascript',
|
||||||
images: '.tmp/images',
|
images: '.tmp/images',
|
||||||
vendor: '.tmp/libs',
|
vendor: '.tmp/libs',
|
||||||
maps: '../sourcemaps',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dist path
|
// Dist path
|
||||||
|
@ -40,7 +43,6 @@ const dist = {
|
||||||
scripts: 'dist/javascript',
|
scripts: 'dist/javascript',
|
||||||
images: 'dist/images',
|
images: 'dist/images',
|
||||||
vendor: 'dist/libs',
|
vendor: 'dist/libs',
|
||||||
maps: 'dist/sourcemaps',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build mode
|
// Build mode
|
||||||
|
@ -86,21 +88,27 @@ gulp.task('styles', () => {
|
||||||
showFiles: true
|
showFiles: true
|
||||||
}))
|
}))
|
||||||
// write sourcemaps
|
// write sourcemaps
|
||||||
.pipe($.if(isDev, $.sourcemaps.write(tmp.maps)))
|
.pipe($.if(isDev, $.sourcemaps.write()))
|
||||||
.pipe(gulp.dest(tmp.styles))
|
.pipe(gulp.dest(tmp.styles))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('scripts', () => {
|
gulp.task('scripts', () => {
|
||||||
return gulp.src(`${src.scripts}/**/*.js`)
|
let b = browserify({
|
||||||
|
entries: `${src.scripts}/index.js`,
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
return b.transform('babelify').bundle()
|
||||||
.pipe($.plumber())
|
.pipe($.plumber())
|
||||||
.pipe($.if(isDev, $.sourcemaps.init()))
|
.pipe(source('app.js'))
|
||||||
.pipe($.babel())
|
.pipe(buffer())
|
||||||
|
.pipe($.if(isDev, $.sourcemaps.init({ loadMaps: true })))
|
||||||
|
//.pipe(uglify({ compress: { drop_console: isProd, drop_debugger: isProd } }))
|
||||||
.pipe($.rename({ suffix: '.min' }))
|
.pipe($.rename({ suffix: '.min' }))
|
||||||
.pipe($.if('*.js', uglify({ compress: { drop_console: isProd, drop_debugger: isProd } })))
|
|
||||||
.pipe($.size({
|
.pipe($.size({
|
||||||
showFiles: true,
|
showFiles: true,
|
||||||
}))
|
}))
|
||||||
.pipe($.if(isDev, $.sourcemaps.write(tmp.maps)))
|
.pipe($.if(isDev, $.sourcemaps.write()))
|
||||||
.pipe(gulp.dest(`${tmp.scripts}`))
|
.pipe(gulp.dest(`${tmp.scripts}`))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -165,10 +173,6 @@ gulp.task('dist:copy', (done) => {
|
||||||
gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`)
|
gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`)
|
||||||
.pipe(gulp.dest(dist.styles))
|
.pipe(gulp.dest(dist.styles))
|
||||||
|
|
||||||
// sourcemaps
|
|
||||||
gulp.src(`${tmp.root}/**/*.map`)
|
|
||||||
.pipe(gulp.dest(dist.root))
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue