| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- const gulp = require('gulp')
- const webpack = require('webpack-stream')
- const filter = require('gulp-filter')
- const modify = require('gulp-modify-file')
- const uglify = require('gulp-uglify')
- const packageConfig = require('../package.json')
- const webpackConfig = require('../webpack.config')
- gulp.task('webpack', function() {
- return createStream()
- })
- gulp.task('webpack:dev', function() {
- return createStream(true)
- })
- gulp.task('webpack:watch', function() {
- createStream(true, true)
- })
- const jsFilter = filter([ '**/*.js' ], { restore: true })
- const localeFilter = filter([ '**/locale-all.js', '**/locale/*.js' ], { restore: true })
- function createStream(enableDev, enableWatch) {
- let stream = gulp.src([]) // don't pass in any files. webpack handles that
- .pipe(
- webpack(Object.assign({}, webpackConfig, {
- devtool: enableDev ? 'source-map' : false, // also 'inline-source-map'
- watch: enableWatch || false,
- }))
- )
- .pipe(
- // don't write bogus .css.js(.map) files webpack created for standalone css outputs
- filter([ '**', '!**/*.css.js*' ])
- )
- .pipe(
- // populate <%= %> variables in source code
- modify(function(content) {
- return content.replace(
- /<%=\s*(\w+)\s*%>/g,
- function(match, p1) {
- return packageConfig[p1]
- }
- )
- })
- )
- .pipe(jsFilter)
- .pipe(modify(function(content, path, file) {
- // for modules that plug into the core, webpack produces files that overwrite
- // the `FullCalendar` browser global each time. strip it out.
- if (file.relative !== 'dist/fullcalendar.js') {
- content = content.replace(/(root|exports)\[['"]FullCalendar['"]\]\s*=\s*/g, '')
- }
- // strip out "use strict", which moment and webpack harmony generates.
- content = content.replace(/['"]use strict['"]/g, '');
- return content
- }))
- .pipe(jsFilter.restore);
- if (!enableDev) {
- stream = stream
- .pipe(localeFilter)
- .pipe(uglify()) // uglify only the locale files, then bring back other files to stream
- .pipe(localeFilter.restore)
- }
- return stream.pipe(
- gulp.dest(webpackConfig.output.path)
- );
- }
|