Skip to content

Commit

Permalink
webpack wasm & meshjs integration
Browse files Browse the repository at this point in the history
  • Loading branch information
saigonbitmaster committed Mar 13, 2023
1 parent 5752c48 commit 3fe1b71
Show file tree
Hide file tree
Showing 9 changed files with 1,040 additions and 19 deletions.
7 changes: 5 additions & 2 deletions api/src/queue/queue.processor.ts
Expand Up @@ -18,7 +18,9 @@ export class QueueProcessor {
@OnQueueActive()
onActive(job: Job) {
console.log(
`Processing job ${job.id} of type ${job.name} with data ${JSON.stringify(job.data)}...`,
`Processing job ${job.id} of type ${job.name} with data ${JSON.stringify(
job.data,
)}...`,
);
}

Expand Down Expand Up @@ -46,7 +48,8 @@ export class QueueProcessor {

@Process('execShell')
execShell(job: Job) {
exec('createWallet.sh', (err, stdout, stderr) => {
const arg = '-1';
exec(`ls ${arg}`, (err, stdout, stderr) => {
if (err) {
console.error(err, job);
} else {
Expand Down
41 changes: 41 additions & 0 deletions emp/craco.config.js
@@ -0,0 +1,41 @@
const webpack = require("webpack");
const buffer = require.resolve("buffer/");

const buffers = ["buffer", "Buffer"];
const wasmRegExp = /\.wasm$/;
const wasmExps = {
layers: true,
asyncWebAssembly: false,
lazyCompilation: true,
syncWebAssembly: true,
topLevelAwait: true,
};

module.exports = {
webpack: {
configure: (webpackConfig) => {
webpackConfig.resolve.extensions.push(".wasm");
webpackConfig.experiments = wasmExps;
webpackConfig.resolve.fallback = {
buffer: buffer,
};

webpackConfig.module.rules.forEach((rule) => {
rule.oneOf?.length
? rule.oneOf.forEach((oneOf) => {
oneOf.type === "asset/resource"
? oneOf.exclude.push(wasmRegExp)
: null;
})
: null;
});
webpackConfig.plugins.push(
new webpack.ProvidePlugin({
Buffer: buffers,
})
);

return webpackConfig;
},
},
};
7 changes: 6 additions & 1 deletion emp/package.json
Expand Up @@ -5,6 +5,8 @@
"dependencies": {
"@apollo/client": "^3.3.19",
"@emurgo/cardano-serialization-lib-asmjs": "^11.1.0",
"@meshsdk/core": "^1.5.1",
"@meshsdk/react": "^1.1.6",
"@mui/icons-material": "^5.0.1",
"@mui/lab": "^5.0.0-alpha.104",
"@mui/material": "^5.0.2",
Expand All @@ -17,6 +19,7 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/recharts": "^1.8.10",
"buffer": "^6.0.3",
"cardano-addresses": "^3.12.0",
"clsx": "^1.1.1",
"data-generator-retail": "^4.0.0",
Expand All @@ -41,11 +44,12 @@
"react-router-dom": "^6.1.0",
"react-scripts": "^5.0.0",
"recharts": "^2.1.5",
"stream": "^0.0.2",
"typescript": "^4.4.2",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "PORT=3002 react-scripts start",
"start": "PORT=3002 craco start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand All @@ -69,6 +73,7 @@
]
},
"devDependencies": {
"@craco/craco": "^7.1.0",
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^26.0.19",
"@types/node": "^12.12.14",
Expand Down
7 changes: 6 additions & 1 deletion emp/src/App.tsx
Expand Up @@ -17,7 +17,10 @@ import Wallet from "./wallet/wallet";
import jobtasks from "./jobtasks";

import ImportExcels from "./tools/importExcels";
import SmartContracts from "./smartcontracts/smartContracts";
import SmartContracts from "./smartcontracts/meshJs";
import { MeshProvider } from "@meshsdk/react";


const loginUrl = process.env.REACT_APP_LOGIN_URL;
const apiUrl = process.env.REACT_APP_API_URL;

Expand All @@ -34,6 +37,7 @@ const i18nProvider = polyglotI18nProvider((locale) => {
const _authProvider = authProvider(loginUrl);
const App = () => {
return (
<MeshProvider>
<Admin
title="bWorks"
dataProvider={restProvider}
Expand All @@ -57,6 +61,7 @@ const App = () => {
<Resource name="jobtasks" {...jobtasks} />

</Admin>
</MeshProvider>
);
};

Expand Down

0 comments on commit 3fe1b71

Please sign in to comment.