Fixed uglifying for asm-code. Added dist-task for building distribution-files

pull/22/head
Christoph Oberhofer 11 years ago
parent 24ceb3480c
commit 594aeb2fc0

@ -10,7 +10,8 @@ module.exports = function(grunt) {
},
uglify : {
options : {
banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
preserveComments: 'some'
},
build : {
src : 'dist/<%= pkg.name %>.js',
@ -62,13 +63,18 @@ module.exports = function(grunt) {
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-requirejs');
grunt.loadNpmTasks('grunt-karma');
// Default task(s).
grunt.registerTask('default', ['jshint', 'requirejs']);
grunt.loadTasks('tasks');
grunt.registerTask('build', ['check', 'requirejs']);
grunt.registerTask('check', ['jshint']);
grunt.registerTask('dist', ['build', 'uglify', 'uglyasm']);
grunt.registerTask('test', ['karma']);
grunt.registerTask('default', ['build']);
};

24
dist/quagga.js vendored

@ -3682,27 +3682,6 @@ define("glMatrix", ["typedefs"], (function (global) {
};
}(this)));
/*
<augmentedJS: A javascript library for natural feature tracking>
Copyright (C) 2011
- Christoph Oberhofer (ar.oberhofer@gmail.com)
- Jens Grubert (jg@jensgrubert.de)
- Gerhard Reitmayr (reitmayr@icg.tugraz.at)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* glMatrixAddon.js
* Extension to the glMatrix library. The original glMatrix library
@ -5487,6 +5466,7 @@ define('rasterizer',["tracer"], function(Tracer) {
define('skeletonizer',[],function() {
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
"use asm";
@ -5680,6 +5660,7 @@ define('skeletonizer',[],function() {
skeletonize : skeletonize
};
}
/* @preserve ASM END */
return Skeletonizer;
});
@ -7044,7 +7025,6 @@ define('config',[],function(){
controls: false,
locate: true,
numOfWorkers: 4,
scriptName: 'quagga.js',
visual: {
show: true
},

File diff suppressed because one or more lines are too long

@ -50,7 +50,7 @@
</footer>
<script src="../src/vendor/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="../dist/quagga.js" type="text/javascript"></script>
<script src="../dist/quagga.min.js" type="text/javascript"></script>
<script src="live_w_locator.js" type="text/javascript"></script>
</body>
</html>

@ -51,7 +51,7 @@
</p>
</footer>
<script src="../src/vendor/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="../dist/quagga.js" type="text/javascript"></script>
<script src="../dist/quagga.min.js" type="text/javascript"></script>
<script src="static_images.js" type="text/javascript"></script>
</body>
</html>

@ -17,7 +17,6 @@ define(function(){
controls: false,
locate: true,
numOfWorkers: 4,
scriptName: 'quagga.js',
visual: {
show: true
},

@ -1,24 +1,3 @@
/*
<augmentedJS: A javascript library for natural feature tracking>
Copyright (C) 2011
- Christoph Oberhofer (ar.oberhofer@gmail.com)
- Jens Grubert (jg@jensgrubert.de)
- Gerhard Reitmayr (reitmayr@icg.tugraz.at)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* glMatrixAddon.js
* Extension to the glMatrix library. The original glMatrix library

@ -4,6 +4,7 @@
define(function() {
"use strict";
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
"use asm";
@ -197,6 +198,7 @@ define(function() {
skeletonize : skeletonize
};
}
/* @preserve ASM END */
return Skeletonizer;
});

@ -0,0 +1,56 @@
/**
* Idea taken from https://github.com/fpirsch/twin-bcrypt/blob/master/Gearfile.js
*/
'use strict';
var fs = require('fs');
module.exports = function(grunt) {
grunt.registerTask('uglyasm', function() {
var code = fs.readFileSync('dist/quagga.js', 'utf-8'),
minifiedCode = fs.readFileSync('dist/quagga.min.js', 'utf-8'),
commentEnd = '/* @preserve ASM END */',
asmStartIdx = code.indexOf('/* @preserve ASM BEGIN */'),
asmEndIdx = code.indexOf(commentEnd),
asmCode = code.substring(asmStartIdx, asmEndIdx + commentEnd.length),
asmFunctionRegex = /function (\w+)\(\w+,\s*\w+,\s*\w+\)\s*\{\s*"use asm";/,
asmModule,
asmModuleName,
asmCodeMinified,
asmMinifiedModuleName;
asmCodeMinified = asmCode
.replace(/\s*\/\/.*/g, '') // remove single-line comments
.replace(/\s*\/\*[^]*?\*\//g, '') // remove multi-line comments
.replace(/\n\s*/g, '') // remove indentation
.replace(/ ([+=^|&]|>+|<+) /g, '$1') // remove spaces around operators
.replace(/[\r\n/]/g, ''); // remove new lines
grunt.log.debug(asmCodeMinified);
asmModule = asmCode.match(asmFunctionRegex);
if (!asmModule) {
grunt.log.error("No ASM module found");
return;
}
asmModuleName = asmModule[1];
grunt.log.debug(asmModuleName);
asmModule = minifiedCode.match(asmFunctionRegex);
if (!asmModule) {
grunt.log.error("No ASM module found in minified file");
return;
}
asmMinifiedModuleName = asmModule[1];
grunt.log.debug(asmMinifiedModuleName);
asmCodeMinified = asmCodeMinified.replace(asmModuleName, asmMinifiedModuleName);
minifiedCode = minifiedCode.replace(/\/\* @preserve ASM BEGIN \*\/[^]*?\/\* @preserve ASM END \*\//, asmCodeMinified);
fs.writeFileSync('dist/quagga.min.js', minifiedCode);
grunt.log.ok('dist/quagga.min.js written');
});
};
Loading…
Cancel
Save