diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js index f0e5b41..e94199b 100644 --- a/gulp/tasks/build.js +++ b/gulp/tasks/build.js @@ -1,3 +1,30 @@ +var gulp = require("gulp"); +var gutil = require("gulp-util"); +var bundle = require("./bundle"); +var uglify = require('gulp-uglify'); +var webpackConfig = require("../../config/webpack.config.js"); var gulp = require('gulp'); +var rename = require('gulp-rename'); -gulp.task('build', ['dist','styles']); +gulp.task("build", function(callback) { + + var onBundle = function(){ + gulp.src('dist/ReactGridWithAddons.js') + .pipe(uglify()) + .pipe(rename('ReactGridWithAddons.min.js')) + .pipe(gulp.dest('dist')) + .on('error', gutil.log) + + gulp.src('dist/ReactGrid.js') + .pipe(uglify()) + .pipe(rename('ReactGrid.min.js')) + .pipe(gulp.dest('dist')) + .on('error', gutil.log) + callback(); + } + + bundle(Object.create(webpackConfig), onBundle); + + + +}); diff --git a/gulp/tasks/bundle.js b/gulp/tasks/bundle.js new file mode 100644 index 0000000..7751fa0 --- /dev/null +++ b/gulp/tasks/bundle.js @@ -0,0 +1,33 @@ +var Webpack = require("webpack"); +var gutil = require("gulp-util"); + +var defaultErrorHandler = function(err, ctx) { +// if(err) throw new gutil.PluginError("webpack", err); + + gutil.log("[webpack]", err); +} +module.exports = function (config, done, handlers) { + handlers = handlers || {}; + handlers = { + onFatalError: handlers.onFatalError || defaultErrorHandler, + onError: handlers.onError || defaultErrorHandler, + onWarning: handlers.onWarning || defaultErrorHandler + }; + Webpack(config, function(err, stats) { + + if(err) return handlers.onFatalError(err, 'Fatal error'); + var jsonStats = stats.toJson(); + if(!jsonStats) { + + } + if(jsonStats.errors.length > 0) { + return handlers.onError(jsonStats.errors.toString(), 'Stats error'); + } + if(jsonStats.warnings.length > 0) { + return handlers.onWarning(jsonStats.warnings.toString(), 'Stats warning'); + } + done(); + + + }); +} diff --git a/gulp/tasks/examples.js b/gulp/tasks/examples.js index e61f51b..077fe7e 100644 --- a/gulp/tasks/examples.js +++ b/gulp/tasks/examples.js @@ -1,14 +1,46 @@ var gulp = require('gulp'); var concat = require('gulp-concat'); -var webpack = require("./webpack"); +var webpack = require("webpack"); +var bundle = require('./bundle'); var gutil = require("gulp-util"); var path = require("path"); -var webpackConfig = require("../../config/webpack.config.js"); +webpackConfig = { + entry: { + 'index' : './examples/index.js', + 'shared' : './examples/shared.js', + 'examples' : './examples/examples.js' + }, + output: { + path: path.join(__dirname, "../../examples/build"), + filename: "[name].js", + libraryTarget: "umd" + }, + externals: { + "react/addons": { + root : 'React', + commonjs : 'react/addons', + commonjs2 : 'react/addons', + amd : 'react/addons' + }, + "moment" : "moment" + }, + module: { + loaders: [ + { test: /\.js$/, loader: 'jsx-loader?stripTypes&harmony' } // loaders can take parameters as a querystring + ] + }, + plugins: [ + new webpack.optimize.DedupePlugin(), + new webpack.optimize.OccurenceOrderPlugin(), + new webpack.optimize.AggressiveMergingPlugin() + ] +} gulp.task('script-deps', function() { + return gulp.src([ 'node_modules/es5-shim/es5-shim.js' ]) @@ -33,18 +65,7 @@ gulp.task('styles', function () { gulp.task("examples", ['script-deps', 'copy-dist', 'styles'], function(callback) { - //override config entry / output - webpackConfig.entry = { - 'index' : './examples/index.js', - 'shared' : './examples/shared.js', - 'examples' : './examples/examples.js' - }; - - webpackConfig.output = { - path: path.join(__dirname, "../../examples/build"), - filename: "[name].js", - libraryTarget: "umd" - }; + // run webpack - webpack(webpackConfig, callback); + bundle(Object.create(webpackConfig), callback); }); diff --git a/gulp/tasks/watch.js b/gulp/tasks/watch.js index 400f6c8..45cc869 100644 --- a/gulp/tasks/watch.js +++ b/gulp/tasks/watch.js @@ -1,7 +1,7 @@ var gulp = require('gulp'); - +var del = require('del'); gulp.task('watch', ['setWatch', 'browserSync'], function() { gulp.watch('themes/**', ['styles']); gulp.watch('src/**', ['examples']); - // Note: The browserify task handles js recompiling with watchify + });