🔧 Fixing comlink
This commit is contained in:
@@ -30,7 +30,8 @@
|
|||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
"react-hooks-worker": "^1.0.0",
|
"react-hooks-worker": "^1.0.0",
|
||||||
"sharp": "^0.28.1",
|
"sharp": "^0.28.1",
|
||||||
"worker-loader": "^3.0.8"
|
"worker-loader": "^3.0.8",
|
||||||
|
"worker-plugin": "^5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.13.10",
|
"@babel/cli": "^7.13.10",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import main from "../workers/extractCovers.worker";
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
matches: unknown;
|
matches: unknown;
|
||||||
}
|
}
|
||||||
@@ -26,8 +25,10 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async startFolderWalk() {
|
public async startFolderWalk() {
|
||||||
const foo = await main();
|
const worker = new Worker(
|
||||||
console.log("as", foo);
|
new URL("../workers/extractCovers.worker", import.meta.url),
|
||||||
|
);
|
||||||
|
console.log(worker);
|
||||||
}
|
}
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
import strategy from "clooney";
|
import { expose } from "comlink";
|
||||||
|
|
||||||
class Actor {
|
const foo = (value: string) => {
|
||||||
timeoutThing() {
|
return "rishi" + " " + value;
|
||||||
return new Promise(resolve => setTimeout(_ => resolve('ohai'), 1000));
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = await strategy.spawn(Actor);
|
const bar = (value: number) => {
|
||||||
alert(await instance.timeoutThing()); // Will alert() after 1 second
|
return value + 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
const exported = {
|
||||||
|
foo,
|
||||||
|
bar,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Worker = typeof exported;
|
||||||
|
expose(exported);
|
||||||
|
|||||||
13
src/client/workers/tsconfig.json
Normal file
13
src/client/workers/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"lib": ["webworker", "esnext"],
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"allowJs": false,
|
||||||
|
"baseUrl": "."
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,13 +5,14 @@
|
|||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"target": "es2019",
|
"target": "es2019",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"module": "commonjs",
|
"module": "esnext",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist/",
|
"outDir": "./dist/",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"DOM",
|
"dom",
|
||||||
"webworker"
|
"dom.iterable",
|
||||||
|
"esnext"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||||
|
const WorkerPlugin = require("worker-plugin");
|
||||||
const outputDirectory = "dist";
|
const outputDirectory = "dist";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -17,10 +18,10 @@ module.exports = {
|
|||||||
use: ["babel-loader"],
|
use: ["babel-loader"],
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
test: /\.worker\.ts$/,
|
// test: /\.worker\.ts$/,
|
||||||
use: { loader: "worker-loader" },
|
// use: { loader: "worker-loader" },
|
||||||
},
|
// },
|
||||||
|
|
||||||
{
|
{
|
||||||
enforce: "pre",
|
enforce: "pre",
|
||||||
@@ -61,6 +62,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// new CleanWebpackPlugin([outputDirectory]),
|
// new CleanWebpackPlugin([outputDirectory]),
|
||||||
|
new WorkerPlugin(),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: "./public/index.html",
|
template: "./public/index.html",
|
||||||
favicon: "./public/favicon.ico",
|
favicon: "./public/favicon.ico",
|
||||||
|
|||||||
@@ -12491,6 +12491,13 @@ worker-loader@^3.0.8:
|
|||||||
loader-utils "^2.0.0"
|
loader-utils "^2.0.0"
|
||||||
schema-utils "^3.0.0"
|
schema-utils "^3.0.0"
|
||||||
|
|
||||||
|
worker-plugin@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/worker-plugin/-/worker-plugin-5.0.0.tgz#113b5fe1f4a5d6a957cecd29915bedafd70bb537"
|
||||||
|
integrity sha512-AXMUstURCxDD6yGam2r4E34aJg6kW85IiaeX72hi+I1cxyaMUtrvVY6sbfpGKAj5e7f68Acl62BjQF5aOOx2IQ==
|
||||||
|
dependencies:
|
||||||
|
loader-utils "^1.1.0"
|
||||||
|
|
||||||
wrap-ansi@^2.0.0:
|
wrap-ansi@^2.0.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
|
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
|
||||||
|
|||||||
Reference in New Issue
Block a user