Skip to content

Commit e4c2b34

Browse files
committed
Browser compatibility
This allows downstream consumers to use GPU.js with requirejs, d3-require, unpkg, jsdelivr, and probably some other systems. The main changes: - Set { standalone: 'UMD' } in browserify configuration. This makes it publish a UMD build that exposes a 'UMD' export or global for CommonJS, require, and AMD. - Move bin/ to dist/, because these are properly distribution files rather than binaries. - Update tests to point to the dist/ version. - Simplify browser.js to always export, because it is not the recommended entry point for any browser. - Add unpkg and jsdelivr fields to package.json so that those CDNs automatically pick up on the right file when someone tries to include from them.
1 parent 1c820a7 commit e4c2b34

File tree

8 files changed

+39
-69
lines changed

8 files changed

+39
-69
lines changed

bin/gpu-browser-core.js renamed to dist/gpu-browser-core.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.17
8-
* @date Mon Jun 24 2019 21:10:10 GMT-0400 (Eastern Daylight Time)
8+
* @date Wed Jun 26 2019 14:12:44 GMT-0700 (Pacific Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
1212
*
1313
* Copyright (c) 2019 gpu.js Team
14-
*/(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
14+
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GPU = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
1515

1616
},{}],2:[function(require,module,exports){
1717
function glWiretap(gl, options = {}) {
@@ -11159,15 +11159,8 @@ for (const p in lib) {
1115911159
if (p === 'GPU') continue;
1116011160
GPU[p] = lib[p];
1116111161
}
11162-
if (typeof module !== 'undefined') {
11163-
module.exports = GPU;
11164-
}
11165-
if (typeof window !== 'undefined') {
11166-
window.GPU = GPU;
11167-
}
11168-
if (typeof self !== 'undefined') {
11169-
self.GPU = GPU;
11170-
}
11162+
module.exports = GPU;
11163+
1117111164
},{"./index":84}],83:[function(require,module,exports){
1117211165
const gpuMock = require('gpu-mock.js');
1117311166
const { utils } = require('./utils');
@@ -12452,4 +12445,5 @@ const _systemEndianness = utils.getSystemEndianness();
1245212445
module.exports = {
1245312446
utils
1245412447
};
12455-
},{"./input":85,"./texture":88,"acorn":1}]},{},[82]);
12448+
},{"./input":85,"./texture":88,"acorn":1}]},{},[82])(82)
12449+
});

bin/gpu-browser-core.min.js renamed to dist/gpu-browser-core.min.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.17
8-
* @date Mon Jun 24 2019 21:10:12 GMT-0400 (Eastern Daylight Time)
8+
* @date Wed Jun 26 2019 14:12:46 GMT-0700 (Pacific Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -18,13 +18,13 @@
1818
* GPU Accelerated JavaScript
1919
*
2020
* @version 2.0.0-rc.17
21-
* @date Mon Jun 24 2019 21:10:10 GMT-0400 (Eastern Daylight Time)
21+
* @date Wed Jun 26 2019 14:12:44 GMT-0700 (Pacific Daylight Time)
2222
*
2323
* @license MIT
2424
* The MIT License
2525
*
2626
* Copyright (c) 2019 gpu.js Team
27-
*/(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
27+
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GPU = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2828

2929
},{}],2:[function(require,module,exports){
3030
function glWiretap(gl, options = {}) {
@@ -11172,15 +11172,8 @@ for (const p in lib) {
1117211172
if (p === 'GPU') continue;
1117311173
GPU[p] = lib[p];
1117411174
}
11175-
if (typeof module !== 'undefined') {
11176-
module.exports = GPU;
11177-
}
11178-
if (typeof window !== 'undefined') {
11179-
window.GPU = GPU;
11180-
}
11181-
if (typeof self !== 'undefined') {
11182-
self.GPU = GPU;
11183-
}
11175+
module.exports = GPU;
11176+
1118411177
},{"./index":84}],83:[function(require,module,exports){
1118511178
const gpuMock = require('gpu-mock.js');
1118611179
const { utils } = require('./utils');
@@ -12465,4 +12458,5 @@ const _systemEndianness = utils.getSystemEndianness();
1246512458
module.exports = {
1246612459
utils
1246712460
};
12468-
},{"./input":85,"./texture":88,"acorn":1}]},{},[82]);
12461+
},{"./input":85,"./texture":88,"acorn":1}]},{},[82])(82)
12462+
});

bin/gpu-browser.js renamed to dist/gpu-browser.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.17
8-
* @date Mon Jun 24 2019 21:10:10 GMT-0400 (Eastern Daylight Time)
8+
* @date Wed Jun 26 2019 14:12:45 GMT-0700 (Pacific Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
1212
*
1313
* Copyright (c) 2019 gpu.js Team
14-
*/(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
14+
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GPU = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
1515
(function (global, factory) {
1616
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
1717
typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -15923,15 +15923,8 @@ for (const p in lib) {
1592315923
if (p === 'GPU') continue;
1592415924
GPU[p] = lib[p];
1592515925
}
15926-
if (typeof module !== 'undefined') {
15927-
module.exports = GPU;
15928-
}
15929-
if (typeof window !== 'undefined') {
15930-
window.GPU = GPU;
15931-
}
15932-
if (typeof self !== 'undefined') {
15933-
self.GPU = GPU;
15934-
}
15926+
module.exports = GPU;
15927+
1593515928
},{"./index":85}],84:[function(require,module,exports){
1593615929
const gpuMock = require('gpu-mock.js');
1593715930
const { utils } = require('./utils');
@@ -17216,4 +17209,5 @@ const _systemEndianness = utils.getSystemEndianness();
1721617209
module.exports = {
1721717210
utils
1721817211
};
17219-
},{"./input":86,"./texture":89,"acorn":1}]},{},[83]);
17212+
},{"./input":86,"./texture":89,"acorn":1}]},{},[83])(83)
17213+
});

bin/gpu-browser.min.js renamed to dist/gpu-browser.min.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0-rc.17
8-
* @date Mon Jun 24 2019 21:10:12 GMT-0400 (Eastern Daylight Time)
8+
* @date Wed Jun 26 2019 14:12:46 GMT-0700 (Pacific Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -18,13 +18,13 @@
1818
* GPU Accelerated JavaScript
1919
*
2020
* @version 2.0.0-rc.17
21-
* @date Mon Jun 24 2019 21:10:10 GMT-0400 (Eastern Daylight Time)
21+
* @date Wed Jun 26 2019 14:12:45 GMT-0700 (Pacific Daylight Time)
2222
*
2323
* @license MIT
2424
* The MIT License
2525
*
2626
* Copyright (c) 2019 gpu.js Team
27-
*/(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
27+
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GPU = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2828
(function (global, factory) {
2929
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3030
typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -15936,15 +15936,8 @@ for (const p in lib) {
1593615936
if (p === 'GPU') continue;
1593715937
GPU[p] = lib[p];
1593815938
}
15939-
if (typeof module !== 'undefined') {
15940-
module.exports = GPU;
15941-
}
15942-
if (typeof window !== 'undefined') {
15943-
window.GPU = GPU;
15944-
}
15945-
if (typeof self !== 'undefined') {
15946-
self.GPU = GPU;
15947-
}
15939+
module.exports = GPU;
15940+
1594815941
},{"./index":85}],84:[function(require,module,exports){
1594915942
const gpuMock = require('gpu-mock.js');
1595015943
const { utils } = require('./utils');
@@ -17229,4 +17222,5 @@ const _systemEndianness = utils.getSystemEndianness();
1722917222
module.exports = {
1723017223
utils
1723117224
};
17232-
},{"./input":86,"./texture":89,"acorn":1}]},{},[83]);
17225+
},{"./input":86,"./texture":89,"acorn":1}]},{},[83])(83)
17226+
});

gulpfile.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ const stripComments = require('gulp-strip-comments');
1212
const merge = require('merge-stream');
1313

1414
gulp.task('build', function() {
15-
const gpu = browserify('./src/browser.js')
15+
const gpu = browserify('./src/browser.js', {standalone: 'GPU'})
1616
.ignore('gl')
1717
.bundle()
1818
.pipe(source('gpu-browser.js'))
1919
.pipe(buffer())
2020
.pipe(stripComments())
2121
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
22-
.pipe(gulp.dest('bin'))
22+
.pipe(gulp.dest('dist'))
2323
.on('error', console.error);
2424

25-
const gpuCore = browserify('./src/browser.js')
25+
const gpuCore = browserify('./src/browser.js', {standalone: 'GPU'})
2626
.ignore('gl')
2727
.ignore('acorn')
2828
.bundle()
2929
.pipe(source('gpu-browser-core.js'))
3030
.pipe(buffer())
3131
.pipe(stripComments())
3232
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
33-
.pipe(gulp.dest('bin'))
33+
.pipe(gulp.dest('dist'))
3434
.on('error', console.error);
3535

3636
return merge(gpu, gpuCore);
3737
});
3838

3939
/// Minify the build script, after building it
4040
gulp.task('minify', function() {
41-
const gpu = gulp.src('bin/gpu-browser.js')
41+
const gpu = gulp.src('dist/gpu-browser.js')
4242
.pipe(rename('gpu-browser.min.js'))
4343
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
44-
.pipe(gulp.dest('bin'))
44+
.pipe(gulp.dest('dist'))
4545
.on('error', console.error);
4646

47-
const gpuCore = gulp.src('bin/gpu-browser-core.js')
47+
const gpuCore = gulp.src('dist/gpu-browser-core.js')
4848
.pipe(rename('gpu-browser-core.min.js'))
4949
.pipe(header(fs.readFileSync('./src/browser-header.txt', 'utf8'), { pkg : pkg }))
50-
.pipe(gulp.dest('bin'))
50+
.pipe(gulp.dest('dist'))
5151
.on('error', console.error);
5252

5353
return merge(gpu, gpuCore);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
},
88
"main": "./src/index.js",
99
"files": [
10-
"src"
10+
"src", "dist"
1111
],
12+
"unpkg": "./dist/gpu-browser.min.js",
13+
"jsdelivr": "./dist/gpu-browser.min.js",
1214
"directories": {
1315
"doc": "doc",
1416
"test": "test"

src/browser.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,4 @@ for (const p in lib) {
55
if (p === 'GPU') continue; //prevent recursive reference
66
GPU[p] = lib[p];
77
}
8-
if (typeof module !== 'undefined') {
9-
module.exports = GPU;
10-
}
11-
if (typeof window !== 'undefined') {
12-
window.GPU = GPU;
13-
}
14-
if (typeof self !== 'undefined') {
15-
self.GPU = GPU;
16-
}
8+
module.exports = GPU;

test/all.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
77

88
<!-- gpu.js scripts -->
9-
<script src="../bin/gpu-browser.js"></script>
9+
<script src="../dist/gpu-browser.js"></script>
1010
</head>
1111
<body>
1212
<div id="qunit"></div>

0 commit comments

Comments
 (0)