diff --git a/config/webpack.config.js b/config/webpack.config.js index 386dbe5b..a1c881ec 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -556,16 +556,6 @@ module.exports = function (webpackEnv) { 'sass-loader' ), }, - // Adds support for wasm that runs as an application. - // https://github.com/webpack/webpack/issues/7352 - { - test: /\.wasm$/, - type: 'javascript/auto', - loader: 'file-loader', - options: { - name: 'static/[name].[hash:8].[ext]', - }, - }, // "file" loader makes sure those assets get served by WebpackDevServer. // When you `import` an asset, you get its (virtual) filename. // In production, they would get copied to the `build` folder. diff --git a/src/mpy/sagas.ts b/src/mpy/sagas.ts index a870b25c..7a83b932 100644 --- a/src/mpy/sagas.ts +++ b/src/mpy/sagas.ts @@ -2,9 +2,7 @@ // Copyright (c) 2020-2022 The Pybricks Authors import { compile as mpyCrossCompileV5 } from '@pybricks/mpy-cross-v5'; -import wasmV5 from '@pybricks/mpy-cross-v5/build/mpy-cross.wasm'; import { compile as mpyCrossCompileV6 } from '@pybricks/mpy-cross-v6'; -import wasmV6 from '@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm'; import { call, getContext, put, select, takeEvery } from 'typed-redux-saga/macro'; import { editorGetValue } from '../editor/sagaLib'; import { FileContents, FileStorageDb } from '../fileStorage'; @@ -56,8 +54,12 @@ function* handleCompile(action: ReturnType): Generator { 'main.py', action.script, action.options, - // HACK: testing user agent for jsdom is needed only for getting unit tests to work - navigator.userAgent.includes('jsdom') ? undefined : wasmV5, + process.env.NODE_ENV === 'test' + ? undefined + : new URL( + '@pybricks/mpy-cross-v5/build/mpy-cross.wasm', + import.meta.url, + ).toString(), ), ); if (result.status === 0 && result.mpy) { @@ -75,8 +77,12 @@ function* handleCompile(action: ReturnType): Generator { 'main.py', action.script, action.options, - // HACK: testing user agent for jsdom is needed only for getting unit tests to work - navigator.userAgent.includes('jsdom') ? undefined : wasmV6, + process.env.NODE_ENV === 'test' + ? undefined + : new URL( + '@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm', + import.meta.url, + ).toString(), ), ); if (result.status === 0 && result.mpy) { @@ -182,8 +188,12 @@ function* handleCompileMulti6(): Generator { py.path, py.contents, undefined, - // HACK: testing user agent for jsdom is needed only for getting unit tests to work - navigator.userAgent.includes('jsdom') ? undefined : wasmV6, + process.env.NODE_ENV === 'test' + ? undefined + : new URL( + '@pybricks/mpy-cross-v6/build/mpy-cross-v6.wasm', + import.meta.url, + ).toString(), ), ); diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 3366c193..da28af6a 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -78,11 +78,6 @@ declare module '*.json' { export default src; } -declare module '*.wasm' { - const src: string; - export default src; -} - declare module '*.zip' { const src: string; export default src;