From 89d32316b61168cfac3227bb88c775b9f07dacba Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 4 Aug 2015 10:08:44 -0700 Subject: [PATCH] Add umd distribution builds via webpack --- CHANGELOG.md | 1 + createWebpackConfig.js | 37 +++++++++++++++++++++++++++++++++++++ gulpfile.js | 41 ++++++++++++++++++++++++++++++++++++----- package.json | 5 ++++- webpack.config.js | 3 +++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 createWebpackConfig.js create mode 100644 webpack.config.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f84a4ca..acb6d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## [unreleased] +* Add umd distribution builds via webpack. (https://github.com/aaronjensen/updeep/issues/3) ## [0.2.2] * Fix `Object.isFrozen` breaking on null in chrome. (https://github.com/aaronjensen/updeep/pull/5) diff --git a/createWebpackConfig.js b/createWebpackConfig.js new file mode 100644 index 0000000..7038cf3 --- /dev/null +++ b/createWebpackConfig.js @@ -0,0 +1,37 @@ +'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ +var webpack = require('webpack'); + +module.exports = function createWebpackConfig(options) { + var config = { + plugins: [ + new webpack.optimize.OccurrenceOrderPlugin(), + ], + + module: { + loaders: [ + { test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }, + ], + }, + + output: { + library: 'updeep', + libraryTarget: 'umd', + }, + + resolve: { + extensions: ['', '.js'], + }, + }; + + config.output.filename = options.filename; + + if (options.minify) { + config.plugins.push(new webpack.optimize.UglifyJsPlugin({ + compressor: { + screw_ie8: true, + }, + })); + } + + return config; +}; diff --git a/gulpfile.js b/gulpfile.js index 0c2098d..e270a44 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,17 @@ 'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ var gulp = require('gulp'); + +var babel = require('gulp-babel'); +var batch = require('gulp-batch'); var eslint = require('gulp-eslint'); var excludeGitignore = require('gulp-exclude-gitignore'); var mocha = require('gulp-mocha'); var nsp = require('gulp-nsp'); -var babel = require('gulp-babel'); -var watch = require('gulp-watch'); -var batch = require('gulp-batch'); var rimraf = require('rimraf'); +var watch = require('gulp-watch'); +var webpack = require('webpack-stream'); + +var createWebpackConfig = require('./createWebpackConfig.js'); // Initialize the babel transpiler so ES2015 files gets compiled // when they're loaded @@ -34,7 +38,7 @@ gulp.task('test', function() { .pipe(mocha({reporter: 'spec'})); }); -gulp.task('babel', ['clean'], function() { +gulp.task('babel', function() { return gulp.src('lib/**/*.js') .pipe(babel()) .pipe(gulp.dest('dist')); @@ -46,5 +50,32 @@ gulp.task('watch', function() { })); }); -gulp.task('prepublish', ['nsp', 'babel']); +gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min']); + +gulp.task('webpack:standalone', function() { + var config = createWebpackConfig({ filename: 'updeep-standalone.js' }); + + return gulp.src('lib/index.js') + .pipe(webpack(config)) + .pipe(gulp.dest('dist/umd/')); +}); + +gulp.task('webpack:standalone:min', function() { + var config = createWebpackConfig({ + filename: 'updeep-standalone.min.js', + minify: true, + }); + + return gulp.src('lib/index.js') + .pipe(webpack(config)) + .pipe(gulp.dest('dist/umd/')); +}); + +gulp.task('build', ['babel', 'webpack']); + +gulp.task('build:clean', ['clean'], function(done) { + gulp.start('build', done); +}); + +gulp.task('prepublish', ['nsp', 'build:clean']); gulp.task('default', ['static', 'test']); diff --git a/package.json b/package.json index bb8fcce..74f4a7f 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "devDependencies": { "babel-core": "^5.5.0", "babel-eslint": "^4.0.5", + "babel-loader": "^5.3.2", "chai": "^3.2.0", "eslint": "^0.24.1", "eslint-config-airbnb": "0.0.7", @@ -44,6 +45,8 @@ "gulp-nsp": "^0.4.5", "gulp-watch": "^4.3.4", "lodash": "^3.0.0", - "rimraf": "^2.4.2" + "rimraf": "^2.4.2", + "webpack": "^1.10.5", + "webpack-stream": "^2.1.0" } } diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..25cdc8b --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,3 @@ +'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ + +module.exports = require('./createWebpackConfig')();