Skip to content

Commit b0cac77

Browse files
committedNov 11, 2014
Throw an error when trying to use unavailable class in WebPack build
1 parent 625dba4 commit b0cac77

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed
 

‎Gulpfile.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,27 @@ gulp.task('build-debug', [ 'concat-sjcl' ], function(callback) {
8989
}, callback);
9090
});
9191

92-
gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
93-
const NONE = 'var {}';
92+
/**
93+
* Generate a WebPack external for a given unavailable module which replaces
94+
* that module's constructor with an error-thrower
95+
*/
96+
97+
function buildUseError(cons) {
98+
return 'var {<CONS>:function(){throw new Error("Class is unavailable in this build: <CONS>")}}'
99+
.replace(new RegExp('<CONS>', 'g'), cons);
100+
};
94101

102+
gulp.task('build-core', [ 'concat-sjcl' ], function(callback) {
95103
webpack({
96104
entry: [
97105
'./src/js/ripple/remote.js'
98106
],
99107
externals: [
100108
{
101-
'./transaction': NONE,
102-
'./orderbook': NONE,
103-
'./account': NONE,
104-
'./serializedobject': NONE
109+
'./transaction': buildUseError('Transaction'),
110+
'./orderbook': buildUseError('OrderBook'),
111+
'./account': buildUseError('Account'),
112+
'./serializedobject': buildUseError('SerializedObject')
105113
}
106114
],
107115
output: {
@@ -135,7 +143,7 @@ gulp.task('bower-build-debug', [ 'build-debug' ], function(callback) {
135143

136144
gulp.task('bower-version', function() {
137145
gulp.src('./dist/bower.json')
138-
.pipe(bump({version: pkg.version}))
146+
.pipe(bump({ version: pkg.version }))
139147
.pipe(gulp.dest('./dist/'));
140148
});
141149

0 commit comments

Comments
 (0)
Please sign in to comment.