diff --git a/package.json b/package.json index da98b9d..cb84db7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "babelify": "^6.3.0", "brfs": "^1.4.1", "browserify": "^11.1.0", - "browserify-shim": "^3.8.10", "camelcase": "^1.2.1", "capitalize": "^1.0.0", "chalk": "^1.1.1", @@ -32,6 +31,7 @@ "gulp-rename": "^1.2.2", "gulp-streamify": "^1.0.2", "gulp-uglify": "^1.4.1", + "gulp-umd": "^0.2.0", "gulp-util": "^3.0.6", "merge-stream": "^1.0.0", "vinyl-source-stream": "^1.1.0", diff --git a/tasks/dist.js b/tasks/dist.js index 3bed69c..6f5de60 100644 --- a/tasks/dist.js +++ b/tasks/dist.js @@ -4,10 +4,10 @@ var del = require('del'); var gutil = require('gulp-util'); var less = require('gulp-less'); var rename = require('gulp-rename'); -var shim = require('browserify-shim'); var source = require('vinyl-source-stream'); var streamify = require('gulp-streamify'); var uglify = require('gulp-uglify'); +var umd = require('gulp-umd'); var minifyCSS = require('gulp-minify-css'); module.exports = function (gulp, config) { @@ -21,18 +21,18 @@ module.exports = function (gulp, config) { }) .transform(babelify.configure({ plugins: [require('babel-plugin-object-assign')] - })) - .transform(shim); - - config.component.dependencies.forEach(function (pkg) { - standalone.exclude(pkg); - }); + })); return standalone.bundle() .on('error', function (e) { gutil.log('Browserify Error', e); }) .pipe(source(config.component.pkgName + '.js')) + .pipe(umd({ + dependencies: function(file){ + return config.component.dependencies; + } + })) .pipe(gulp.dest(config.component.dist)) .pipe(rename(config.component.pkgName + '.min.js')) .pipe(streamify(uglify())) diff --git a/tasks/examples.js b/tasks/examples.js index c0439ec..cbd1d45 100644 --- a/tasks/examples.js +++ b/tasks/examples.js @@ -7,22 +7,27 @@ var del = require('del'); var gutil = require('gulp-util'); var less = require('gulp-less'); var merge = require('merge-stream'); -var shim = require('browserify-shim'); var source = require('vinyl-source-stream'); +var umd = require('gulp-umd'); var watchify = require('watchify'); module.exports = function (gulp, config) { - function doBundle (target, name, dest) { + function doBundle (target, name, dest, dependencies) { return target.bundle() .on('error', function (e) { gutil.log('Browserify Error', e); }) .pipe(source(name)) + .pipe(umd({ + dependencies: function(file){ + return dependencies; + } + })) .pipe(gulp.dest(dest)) .pipe(connect.reload()); } - function watchBundle (target, name, dest) { + function watchBundle (target, name, dest, dependencies) { return watchify(target) .on('update', function (scriptIds) { scriptIds = scriptIds @@ -35,7 +40,7 @@ module.exports = function (gulp, config) { gutil.log(scriptIds[0] + ' updated, rebuilding...'); } - doBundle(target, name, dest); + doBundle(target, name, dest, dependencies); }) .on('time', function (time) { gutil.log(chalk.green(name + ' built in ' + (Math.round(time / 10) / 100) + 's')); @@ -65,7 +70,6 @@ module.exports = function (gulp, config) { plugins: [require('babel-plugin-object-assign')] })); config.aliasify && standalone.transform(aliasify); - standalone.transform(shim); } var examples = config.example.scripts.map(function (file) { @@ -85,11 +89,6 @@ module.exports = function (gulp, config) { config.component.dependencies.forEach(function (pkg) { common.require(pkg); - bundle.exclude(pkg); - if (standalone) standalone.exclude(pkg); - examples.forEach(function (eg) { - eg.bundle.exclude(pkg); - }); }); if (dev) { @@ -102,16 +101,16 @@ module.exports = function (gulp, config) { } var bundles = [ - doBundle(common, 'common.js', dest), - doBundle(bundle, 'bundle.js', dest) + doBundle(common, 'common.js', dest, config.component.dependencies), + doBundle(bundle, 'bundle.js', dest, config.component.dependencies) ]; if (standalone) { - bundles.push(doBundle(standalone, 'standalone.js', dest)); + bundles.push(doBundle(standalone, 'standalone.js', dest, config.component.dependencies)); } return merge(bundles.concat(examples.map(function (eg) { - return doBundle(eg.bundle, eg.file, dest); + return doBundle(eg.bundle, eg.file, dest, config.component.dependencies); }))); }; }