mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
Rework web assembly inclusion
This moves the .wasm file out of the static/js/ folder and into the
source tree. This way we can import it and webpack will pick it up
and version the file with a hash.
This fixes possibly running with an out of date file from the browser
cache and also fixes running offline.
The file extension had to be changed because there is a default rule in
webpack that matches the .wasm extension and causes the following error:
Failed to compile.
./src/sagas/mpy-cross.wasm
Module parse failed: magic header not detected
File was processed with these loaders:
* ./node_modules/file-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
Error: magic header not detected
The webpack configuration cannot be modified without ejecting
create-react-app or using something like react-app-rewired, which we
would like to avoid.
Also using ncp to copy file now which fixes building on Windows.
This commit is contained in:
committed by
David Lechner
parent
9cfc7c5bd1
commit
441d517a52
Vendored
+5
@@ -5,6 +5,11 @@ declare module '*.json' {
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.emcwasm' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.zip' {
|
||||
const src: string;
|
||||
export default src;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
*.emcwasm
|
||||
+8
-1
@@ -9,6 +9,7 @@ import {
|
||||
didCompile,
|
||||
didFailToCompile,
|
||||
} from '../actions/mpy';
|
||||
import wasm from './mpy-cross.emcwasm';
|
||||
|
||||
/**
|
||||
* Compiles a script to .mpy and dispatches either didCompile on success or
|
||||
@@ -17,7 +18,13 @@ import {
|
||||
*/
|
||||
function* compile(action: MpyCompileAction): Generator {
|
||||
const result = (yield call(() =>
|
||||
mpyCrossCompile('main.py', action.script, action.options),
|
||||
mpyCrossCompile(
|
||||
'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 : wasm,
|
||||
),
|
||||
)) as CompileResult;
|
||||
if (result.status === 0 && result.mpy) {
|
||||
yield put(didCompile(result.mpy));
|
||||
|
||||
Reference in New Issue
Block a user