forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a hacky browserify transform to remove runtime checks
- Loading branch information
1 parent
288b11e
commit a2549e6
Showing
8 changed files
with
6,719 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
var path = require('path') | ||
var fs = require('fs') | ||
var browserify = require('browserify') | ||
var ClosureCompiler = require('google-closure-compiler').compiler | ||
|
||
var closureCompiler = new ClosureCompiler({ | ||
js: 'dist/regl.js', | ||
compilation_level: 'ADVANCED', | ||
js_output_file: 'dist/regl.min.js' | ||
}) | ||
|
||
closureCompiler.run(function (exitCode, stdOut, stdErr) { | ||
console.log('closure stdout:', stdOut) | ||
console.log('closure stderr:', stdErr) | ||
process.exit(exitCode) | ||
}) | ||
var INPUT_FILE = path.join(__dirname, '../regl.js') | ||
var UNCHECKED_FILE = path.join(__dirname, '../dist/regl.unchecked.js') | ||
var OUTPUT_FILE = path.join(__dirname, '../dist/regl.min.js') | ||
|
||
console.log('removing checks from ', INPUT_FILE) | ||
console.log('writing to ', UNCHECKED_FILE) | ||
|
||
browserify(INPUT_FILE, { standalone: 'initREGL' }) | ||
.transform(require('./remove-check')) | ||
.bundle() | ||
.pipe(fs.createWriteStream(UNCHECKED_FILE)) | ||
.on('close', function () { | ||
|
||
console.log('minifying script: ', UNCHECKED_FILE) | ||
|
||
var closureCompiler = new ClosureCompiler({ | ||
js: UNCHECKED_FILE, | ||
compilation_level: 'SIMPLE', | ||
js_output_file: OUTPUT_FILE | ||
}) | ||
|
||
closureCompiler.run(function (exitCode, stdOut, stdErr) { | ||
console.log('closure stdout:', stdOut) | ||
console.log('closure stderr:', stdErr) | ||
process.exit(exitCode) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var through2 = require('through2') | ||
var falafel = require('falafel') | ||
|
||
function isCheckCall (node) { | ||
if (node.type === 'Identifier' && node.name === 'check') { | ||
return true | ||
} | ||
return ( | ||
node.type === 'MemberExpression' && | ||
node.object.type === 'Identifier' && | ||
node.object.name === 'check') | ||
} | ||
|
||
function isCheckRequire (node) { | ||
return node.id.name === 'check' | ||
} | ||
|
||
module.exports = function () { | ||
var data = '' | ||
return through2(write, end) | ||
|
||
function write (chunk, enc, done) { | ||
data += chunk | ||
done() | ||
} | ||
|
||
function end (done) { | ||
try { | ||
var result = falafel(data, function (node) { | ||
switch (node.type) { | ||
case 'CallExpression': | ||
if (isCheckCall(node.callee)) { | ||
node.update('') | ||
return | ||
} | ||
break | ||
case 'VariableDeclaration': | ||
if (node.declarations.length === 1 && | ||
isCheckRequire(node.declarations[0])) { | ||
node.update('') | ||
return | ||
} | ||
break | ||
} | ||
}) | ||
this.push(result.toString()) | ||
} catch(e) { | ||
this.push(data) | ||
} | ||
done() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.