Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve browserify/webpack support #333

Merged
merged 4 commits into from
Aug 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ module.exports = function(grunt) {
browserifyOptions: {
standalone: 'JSZip',
transform: ['package-json-versionify'],
insertGlobalVars : {
Buffer: function () {
// instead of the full polyfill, we just use the raw value
// (or undefined).
return '(typeof Buffer !== "undefined" ? Buffer : undefined)';
}
}
insertGlobalVars: {
process: undefined,
Buffer: undefined,
__filename: undefined,
__dirname: undefined
},
builtins: false
},
ignore : ["./lib/nodejs/*"],
banner : grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version)
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/external.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/* global Promise */
'use strict';

// load the global object first:
// - it should be better integrated in the system (unhandledRejection in node)
// - the environment may have a custom Promise implementation (see zone.js)
var ES6Promise = global.Promise || require("lie");
var ES6Promise = null;
if (typeof Promise !== "undefined") {
ES6Promise = Promise;
} else {
ES6Promise = require("lie");
}

/**
* Let the user use/change some implementations.
Expand Down
9 changes: 9 additions & 0 deletions lib/readable-stream-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* This file is used by module bundlers (browserify/webpack/etc) when
* including a stream implementation. We use "readable-stream" to get a
* consistent behavior between nodejs versions but bundlers often have a shim
* for "stream". Using this shim greatly improve the compatibility and greatly
* reduce the final size of the bundle (only one stream implementation, not
* two).
*/
module.exports = require("stream");
9 changes: 8 additions & 1 deletion lib/stream/StreamHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ var utils = require('../utils');
var ConvertWorker = require('./ConvertWorker');
var GenericWorker = require('./GenericWorker');
var base64 = require('../base64');
var NodejsStreamOutputAdapter = require('../nodejs/NodejsStreamOutputAdapter');
var support = require("../support");
var external = require("../external");

var NodejsStreamOutputAdapter = null;
if (support.nodestream) {
try {
NodejsStreamOutputAdapter = require('../nodejs/NodejsStreamOutputAdapter');
} catch(e) {}
}

/**
* Apply the final transformation of the data. If the user wants a Blob for
* example, it's easier to work with an U8intArray and finally do the
Expand Down
6 changes: 5 additions & 1 deletion lib/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ else {
}
}

exports.nodestream = !!require("./nodejs/NodejsStreamOutputAdapter").prototype;
try {
exports.nodestream = !!require('readable-stream').Readable;
} catch(e) {
exports.nodestream = false;
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
}
],
"main": "./lib/index",
"browser": {
"readable-stream": "./lib/readable-stream-browser.js"
},
"repository": {
"type": "git",
"url": "https://github.com/Stuk/jszip.git"
Expand Down