Skip to content

Commit 9cbfafe

Browse files
committed
Added ENV for dead-code elimination in production mode
1 parent b7ffeec commit 9cbfafe

13 files changed

+286
-124
lines changed

dist/quagga.js

+136-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

env/development.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
production: false,
3+
development: true,
4+
node: false
5+
};

env/node.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
production: true,
3+
development: false,
4+
node: true
5+
};

env/production.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
production: true,
3+
development: false,
4+
node: false
5+
};

example/file_input.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ $(function() {
9595
patchSize: "large",
9696
halfSample: false
9797
},
98-
numOfWorkers: 1,
9998
decoder: {
10099
readers: ["code_128_reader"]
101100
},
102101
locate: true,
103102
src: null
104103
}
105104
};
106-
105+
107106
App.init();
108107

109108
function calculateRectFromArea(canvas, area) {
@@ -168,4 +167,4 @@ $(function() {
168167
$node.find("h4.code").html(code);
169168
$("#result_strip ul.thumbnails").prepend($node);
170169
});
171-
});
170+
});

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"babel-loader": "^5.3.2",
1212
"chai": "^3.4.1",
1313
"core-js": "^1.2.1",
14+
"cross-env": "^1.0.7",
1415
"eslint": "^1.10.3",
1516
"grunt": "^0.4.5",
1617
"grunt-cli": "^0.1.13",
@@ -39,8 +40,8 @@
3940
"scripts": {
4041
"test": "grunt test",
4142
"integrationtest": "grunt integrationtest",
42-
"build": "webpack && webpack --config webpack.config.min.js && grunt uglyasm && webpack --config webpack.node.config.js",
43-
"watch": "webpack --watch",
43+
"build:dev": "webpack && webpack --config webpack.config.min.js && grunt uglyasm && webpack --config webpack.node.config.js",
44+
"watch": "cross-env BUILD_ENV=development webpack --watch",
4445
"lint": "eslint src"
4546
},
4647
"repository": {

src/config/config.dev.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = {
2+
inputStream: {
3+
name: "Live",
4+
type: "LiveStream",
5+
constraints: {
6+
width: 640,
7+
height: 480,
8+
minAspectRatio: 0,
9+
maxAspectRatio: 100,
10+
facing: "environment" // or user
11+
},
12+
area: {
13+
top: "0%",
14+
right: "0%",
15+
left: "0%",
16+
bottom: "0%"
17+
},
18+
singleChannel: false // true: only the red color-channel is read
19+
},
20+
locate: true,
21+
numOfWorkers: 0,
22+
decoder: {
23+
readers: [
24+
'code_128_reader'
25+
],
26+
debug: {
27+
drawBoundingBox: false,
28+
showFrequency: false,
29+
drawScanline: false,
30+
showPattern: false,
31+
}
32+
},
33+
locator: {
34+
halfSample: true,
35+
patchSize: "medium", // x-small, small, medium, large, x-large
36+
debug: {
37+
showCanvas: true,
38+
showPatches: true,
39+
showFoundPatches: false,
40+
showSkeleton: false,
41+
showLabels: false,
42+
showPatchLabels: false,
43+
showRemainingPatchLabels: false,
44+
boxFromPatches: {
45+
showTransformed: false,
46+
showTransformedBox: false,
47+
showBB: false
48+
}
49+
}
50+
}
51+
};

src/config/config.js

+12-48
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
1-
export default {
2-
inputStream: {
3-
name: "Live",
4-
type: "LiveStream",
5-
constraints: {
6-
width: 640,
7-
height: 480,
8-
minAspectRatio: 0,
9-
maxAspectRatio: 100,
10-
facing: "environment" // or user
11-
},
12-
area: {
13-
top: "0%",
14-
right: "0%",
15-
left: "0%",
16-
bottom: "0%"
17-
},
18-
singleChannel: false // true: only the red color-channel is read
19-
},
20-
debug: false,
21-
locate: true,
22-
numOfWorkers: 4,
23-
decoder: {
24-
drawBoundingBox: false,
25-
showFrequency: false,
26-
drawScanline: false,
27-
showPattern: false,
28-
readers: [
29-
'code_128_reader'
30-
]
31-
},
32-
locator: {
33-
halfSample: true,
34-
patchSize: "medium", // x-small, small, medium, large, x-large
35-
showCanvas: false,
36-
showPatches: false,
37-
showFoundPatches: false,
38-
showSkeleton: false,
39-
showLabels: false,
40-
showPatchLabels: false,
41-
showRemainingPatchLabels: false,
42-
boxFromPatches: {
43-
showTransformed: false,
44-
showTransformedBox: false,
45-
showBB: false
46-
}
47-
}
48-
};
1+
let config;
2+
3+
console.log(ENV);
4+
if(ENV.development){
5+
config = require('./config.dev.js');
6+
} else if (ENV.node) {
7+
config = require('./config.node.js');
8+
} else {
9+
config = require('./config.prod.js');
10+
}
11+
12+
export default config;

src/config/config.node.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
inputStream: {
3+
type: "ImageStream",
4+
sequence: false,
5+
size: 800,
6+
area: {
7+
top: "0%",
8+
right: "0%",
9+
left: "0%",
10+
bottom: "0%"
11+
},
12+
singleChannel: false // true: only the red color-channel is read
13+
},
14+
locate: true,
15+
numOfWorkers: 0,
16+
decoder: {
17+
readers: [
18+
'code_128_reader'
19+
]
20+
},
21+
locator: {
22+
halfSample: true,
23+
patchSize: "medium", // x-small, small, medium, large, x-large
24+
}
25+
};

src/config/config.prod.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
inputStream: {
3+
name: "Live",
4+
type: "LiveStream",
5+
constraints: {
6+
width: 640,
7+
height: 480,
8+
minAspectRatio: 0,
9+
maxAspectRatio: 100,
10+
facing: "environment" // or user
11+
},
12+
area: {
13+
top: "0%",
14+
right: "0%",
15+
left: "0%",
16+
bottom: "0%"
17+
},
18+
singleChannel: false // true: only the red color-channel is read
19+
},
20+
locate: true,
21+
numOfWorkers: 4,
22+
decoder: {
23+
readers: [
24+
'code_128_reader'
25+
]
26+
},
27+
locator: {
28+
halfSample: true,
29+
patchSize: "medium", // x-small, small, medium, large, x-large
30+
}
31+
};

src/decoder/barcode_decoder.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export default {
9595
var i,
9696
vis = [{
9797
node: _canvas.dom.frequency,
98-
prop: config.showFrequency
98+
prop: config.debug.showFrequency
9999
}, {
100100
node: _canvas.dom.pattern,
101-
prop: config.showPattern
101+
prop: config.debug.showPattern
102102
}];
103103

104104
for (i = 0; i < vis.length; i++) {
@@ -154,12 +154,12 @@ export default {
154154
i,
155155
barcodeLine = Bresenham.getBarcodeLine(inputImageWrapper, line[0], line[1]);
156156

157-
if (config.showFrequency) {
157+
if (ENV.development && config.debug.showFrequency) {
158158
ImageDebug.drawPath(line, {x: 'x', y: 'y'}, _canvas.ctx.overlay, {color: 'red', lineWidth: 3});
159159
Bresenham.debug.printFrequency(barcodeLine.line, _canvas.dom.frequency);
160160
}
161161
Bresenham.toBinaryLine(barcodeLine);
162-
if (config.showPattern) {
162+
if (ENV.development && config.debug.showPattern) {
163163
Bresenham.debug.printPattern(barcodeLine.line, _canvas.dom.pattern);
164164
}
165165

@@ -228,8 +228,10 @@ export default {
228228
result,
229229
lineLength;
230230

231-
if (config.drawBoundingBox && ctx) {
232-
ImageDebug.drawPath(box, {x: 0, y: 1}, ctx, {color: "blue", lineWidth: 2});
231+
if (ENV.development) {
232+
if (config.debug.drawBoundingBox && ctx) {
233+
ImageDebug.drawPath(box, {x: 0, y: 1}, ctx, {color: "blue", lineWidth: 2});
234+
}
233235
}
234236

235237
line = getLine(box);

src/quagga.js

-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ export default {
489489
size: 800,
490490
src: config.src
491491
},
492-
numOfWorkers: 1,
493492
locator: {
494493
halfSample: false
495494
}

webpack.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module.exports = {
3333
plugins: [
3434
new MyUmdPlugin({
3535
library: 'Quagga'
36+
}),
37+
new webpack.DefinePlugin({
38+
ENV: require(path.join(__dirname, './env/', process.env.BUILD_ENV))
3639
})
3740
]
3841
};

0 commit comments

Comments
 (0)