Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Update browser script to again emit UMD bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Apr 14, 2016
1 parent d343b84 commit fd4a47e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
8 changes: 1 addition & 7 deletions browser-entry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
window.Should = require('./index');

Object.defineProperty(window, 'should', {
enumerable: false,
configurable: true,
value: window.Should
});
should = require('./index');
76 changes: 56 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,78 @@
var gulp = require('gulp');
'use strict';

var header = require('gulp-header');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
const gulp = require('gulp');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
const derequire = require('gulp-derequire');
const wrapper = require('gulp-wrapper');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');

var browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');

var pkg = require('./package.json');
const browserify = require('browserify');
const collapse = require('bundle-collapser');

var banner = [
'/*!',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @author <%= pkg.author %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
const pkg = require('./package.json');

gulp.task('script', function() {
const template = require('lodash.template')

const header = template(`
/*!
* <%= pkg.name %> - <%= pkg.description %>
* @version v<%= pkg.version %>
* @author <%= pkg.author %>
* @link <%= pkg.homepage %>
* @license <%= pkg.license %>
*/
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.Should = factory();
Object.defineProperty(root, 'should', {
enumerable: false,
configurable: true,
value: root.Should
});
}
}(this, function () {
var should, require = null;
`, { variable: 'pkg' })(pkg);

var footer = `
return should;
}));
`;

gulp.task('script', () => {
var bundleStream = browserify({
entries: './browser-entry',
builtins: null,
insertGlobals: false,
detectGlobals: false,
fullPaths: false
fullPaths: false,
hasExports: false
})
.plugin('bundle-collapser/plugin')
.bundle();

return bundleStream
.pipe(source('should.js'))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(derequire())
.pipe(wrapper({
header,
footer
}))
.pipe(gulp.dest('./'))
.pipe(uglify({ preserveComments: 'some' }))
.pipe(rename('should.min.js'))
.pipe(gulp.dest('./'));
});

gulp.task('default', ['script']);
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
"devDependencies": {
"bluebird": "^3.0.6",
"browserify": "latest",
"bundle-collapser": "^1.2.1",
"eslint": "^2.4.0",
"gulp": "^3.8.10",
"gulp-header": "^1.2.2",
"gulp-derequire": "^2.1.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.1",
"gulp-wrapper": "^1.0.0",
"lodash.template": "^4.2.4",
"mocha": "latest",
"mocha-better-spec-reporter": "latest",
"vinyl-buffer": "^1.0.0",
Expand Down

0 comments on commit fd4a47e

Please sign in to comment.