优化后端
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import sourcemaps from 'rollup-plugin-sourcemaps';
|
||||
|
||||
export default [
|
||||
{
|
||||
input: 'dist/tesseract.min.js',
|
||||
output: {
|
||||
file: 'dist/tesseract.esm.min.js',
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
banner: '/* eslint-disable */',
|
||||
},
|
||||
plugins: [commonjs(), sourcemaps()],
|
||||
},
|
||||
];
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
const middleware = require('webpack-dev-middleware');
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const cors = require('cors');
|
||||
const webpackConfig = require('./webpack.config.prod');
|
||||
|
||||
const compiler = webpack(webpackConfig);
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
app.use(middleware(compiler, { publicPath: '/dist', writeToDisk: true }));
|
||||
|
||||
// These headers are required to measure memory within the benchmark code.
|
||||
// If they are problematic within other contexts they can be removed.
|
||||
app.use(express.static(path.resolve(__dirname, '..'), {
|
||||
setHeaders: (res) => {
|
||||
res.set('Cross-Origin-Opener-Policy', 'same-origin');
|
||||
res.set('Cross-Origin-Embedder-Policy', 'require-corp');
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = app.listen(3000, () => {
|
||||
console.log('Server is running on the port no. 3000');
|
||||
});
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import expect from 'expect.js';
|
||||
import fs from 'fs';
|
||||
// eslint-disable-next-line import/extensions
|
||||
import Tesseract from '../src/index.js';
|
||||
|
||||
global.Tesseract = Tesseract;
|
||||
global.expect = expect;
|
||||
global.fs = fs;
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
resolve: {
|
||||
fallback: {
|
||||
buffer: require.resolve('buffer/'),
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.m?js$/,
|
||||
// exclude: /(node_modules|bower_components)/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: 'last 2 versions',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const common = require('./webpack.config.common');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const genConfig = ({
|
||||
entry, filename, library, libraryTarget,
|
||||
}) => ({
|
||||
...common,
|
||||
mode: 'production',
|
||||
devtool: 'source-map',
|
||||
entry,
|
||||
output: {
|
||||
path: path.resolve(__dirname, '..', 'dist'),
|
||||
filename,
|
||||
library,
|
||||
libraryTarget,
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = [
|
||||
genConfig({
|
||||
entry: path.resolve(__dirname, '..', 'src', 'index.js'),
|
||||
filename: 'tesseract.min.js',
|
||||
library: 'Tesseract',
|
||||
libraryTarget: 'umd',
|
||||
}),
|
||||
genConfig({
|
||||
entry: path.resolve(__dirname, '..', 'src', 'worker-script', 'browser', 'index.js'),
|
||||
filename: 'worker.min.js',
|
||||
}),
|
||||
];
|
||||
Reference in New Issue
Block a user