Browse Source

Revert "Bundle tesseract.js, worker.js and tesseract-core.js together"

This reverts commit 936cfa6f48.
pull/288/head
Jerome Wu 6 years ago
parent
commit
26d3aecbcc
  1. 10
      package-lock.json
  2. 3
      package.json
  3. 3
      scripts/webpack.config.common.js
  4. 10
      scripts/webpack.config.dev.js
  5. 10
      scripts/webpack.config.prod.js
  6. 22
      src/browser/index.js
  7. 23
      src/browser/worker.js

10
package-lock.json generated

@ -9808,16 +9808,6 @@
"errno": "~0.1.7" "errno": "~0.1.7"
} }
}, },
"worker-loader": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/worker-loader/-/worker-loader-2.0.0.tgz",
"integrity": "sha512-tnvNp4K3KQOpfRnD20m8xltE3eWh89Ye+5oj7wXEEHKac1P4oZ6p9oTj8/8ExqoSBnk9nu5Pr4nKfQ1hn2APJw==",
"dev": true,
"requires": {
"loader-utils": "^1.0.0",
"schema-utils": "^0.4.0"
}
},
"wrap-ansi": { "wrap-ansi": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",

3
package.json

@ -44,8 +44,7 @@
"wait-on": "^3.2.0", "wait-on": "^3.2.0",
"webpack": "^4.26.0", "webpack": "^4.26.0",
"webpack-cli": "^3.1.2", "webpack-cli": "^3.1.2",
"webpack-dev-middleware": "^3.4.0", "webpack-dev-middleware": "^3.4.0"
"worker-loader": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"axios": "^0.18.0", "axios": "^0.18.0",

3
scripts/webpack.config.common.js

@ -20,7 +20,4 @@ module.exports = {
}, },
], ],
}, },
node: {
fs: 'empty',
},
}; };

10
scripts/webpack.config.dev.js

@ -29,10 +29,8 @@ module.exports = [
library: 'Tesseract', library: 'Tesseract',
libraryTarget: 'umd', libraryTarget: 'umd',
}), }),
/* genConfig({
*genConfig({ entry: path.resolve(__dirname, '..', 'src', 'browser', 'worker.js'),
* entry: path.resolve(__dirname, '..', 'src', 'browser', 'worker.js'), filename: 'worker.dev.js',
* filename: 'worker.dev.js', }),
*}),
*/
]; ];

10
scripts/webpack.config.prod.js

@ -23,10 +23,8 @@ module.exports = [
library: 'Tesseract', library: 'Tesseract',
libraryTarget: 'umd', libraryTarget: 'umd',
}), }),
/* genConfig({
*genConfig({ entry: path.resolve(__dirname, '..', 'src', 'browser', 'worker.js'),
* entry: path.resolve(__dirname, '..', 'src', 'browser', 'worker.js'), filename: 'worker.min.js',
* filename: 'worker.min.js', }),
*}),
*/
]; ];

22
src/browser/index.js

@ -10,8 +10,6 @@
const check = require('check-types'); const check = require('check-types');
const resolveURL = require('resolve-url'); const resolveURL = require('resolve-url');
const axios = require('axios'); const axios = require('axios');
// eslint-disable-next-line
const TessWorker = require('worker-loader?inline=true&fallback=false!./worker');
const { defaultOptions } = require('../common/options'); const { defaultOptions } = require('../common/options');
const { version } = require('../../package.json'); const { version } = require('../../package.json');
@ -121,17 +119,15 @@ exports.defaultOptions = {
* @param {string} options.workerPath - worker script path * @param {string} options.workerPath - worker script path
*/ */
exports.spawnWorker = (instance, { workerPath }) => { exports.spawnWorker = (instance, { workerPath }) => {
const worker = new TessWorker(); let worker;
/* if (Blob && URL) {
*if (Blob && URL) { const blob = new Blob([`importScripts("${workerPath}");`], {
* const blob = new Blob([`importScripts("${workerPath}");`], { type: 'application/javascript',
* type: 'application/javascript', });
* }); worker = new Worker(URL.createObjectURL(blob));
* worker = new Worker(URL.createObjectURL(blob)); } else {
*} else { worker = new Worker(workerPath);
* worker = new Worker(workerPath); }
*}
*/
worker.onmessage = ({ data }) => { worker.onmessage = ({ data }) => {
if (data.jobId.startsWith('Job')) { if (data.jobId.startsWith('Job')) {

23
src/browser/worker.js

@ -11,8 +11,6 @@
const check = require('check-types'); const check = require('check-types');
const workerUtils = require('../common/workerUtils'); const workerUtils = require('../common/workerUtils');
let TesseractCore = null;
/* /*
* register message handler * register message handler
*/ */
@ -28,24 +26,21 @@ workerUtils.setAdapter({
getCore: (corePath, res) => { getCore: (corePath, res) => {
if (check.undefined(global.TesseractCore)) { if (check.undefined(global.TesseractCore)) {
res.progress({ status: 'loading tesseract core', progress: 0 }); res.progress({ status: 'loading tesseract core', progress: 0 });
// global.importScripts(corePath); global.importScripts(corePath);
/* /*
* Depending on whether the browser supports WebAssembly, * Depending on whether the browser supports WebAssembly,
* the version of the TesseractCore will be different. * the version of the TesseractCore will be different.
*/ */
/* if (check.not.undefined(global.TesseractCoreWASM) && typeof WebAssembly === 'object') {
*if (check.not.undefined(global.TesseractCoreWASM) && typeof WebAssembly === 'object') { global.TesseractCore = global.TesseractCoreWASM;
* global.TesseractCore = global.TesseractCoreWASM; } else if (check.not.undefined(global.TesseractCoreASM)) {
*} else if (check.not.undefined(global.TesseractCoreASM)) { global.TesseractCore = global.TesseractCoreASM;
* global.TesseractCore = global.TesseractCoreASM; } else {
*} else { throw Error('Failed to load TesseractCore');
* throw Error('Failed to load TesseractCore'); }
*}
*/
TesseractCore = require('tesseract.js-core/tesseract-core.wasm.js');
res.progress({ status: 'loading tesseract core', progress: 1 }); res.progress({ status: 'loading tesseract core', progress: 1 });
} }
return TesseractCore; return global.TesseractCore;
}, },
b64toU8Array: s => new Uint8Array(atob(s).split('').map(c => c.charCodeAt(0))), b64toU8Array: s => new Uint8Array(atob(s).split('').map(c => c.charCodeAt(0))),
writeFile: (path, data, type) => { writeFile: (path, data, type) => {

Loading…
Cancel
Save