remove wasm file extension rename workaround

This modifies the webpack config instead of renaming the .wasm file
to workaround default webpack behavior regarding import .wasm files.
This commit is contained in:
David Lechner
2021-01-11 16:47:49 -06:00
parent d04e022e83
commit 69e52be259
6 changed files with 19 additions and 12 deletions
+17 -1
View File
@@ -1,6 +1,11 @@
// https://github.com/gsoft-inc/craco/blob/master/packages/craco/README.md#configuration
const { getLoader, getLoaders, loaderByName } = require('@craco/craco');
const {
addBeforeLoader,
getLoader,
getLoaders,
loaderByName,
} = require('@craco/craco');
module.exports = {
webpack: {
@@ -45,6 +50,17 @@ module.exports = {
/\.json$/,
];
// work around default handling of .wasm files
// https://github.com/webpack/webpack/issues/7352
addBeforeLoader(webpackConfig, loaderByName('file-loader'), {
test: /\.wasm$/,
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: 'static/[name].[hash:8].[ext]',
},
});
return webpackConfig;
},
},
-3
View File
@@ -43,7 +43,6 @@
"zen-push": "^0.2.1"
},
"scripts": {
"prepare": "mkdirp public/static/js && ncp node_modules/@pybricks/mpy-cross-v5/build/mpy-cross.wasm src/sagas/mpy-cross.emcwasm",
"start": "craco start",
"build": "craco build",
"test": "craco test --env=./test/env.js",
@@ -76,8 +75,6 @@
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"jest-mock-extended": "^1.0.9",
"mkdirp": "^1.0.4",
"ncp": "^2.0.0",
"prettier": "^2.2.1"
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ declare module '*.json' {
export default src;
}
declare module '*.emcwasm' {
declare module '*.wasm' {
const src: string;
export default src;
}
-1
View File
@@ -1 +0,0 @@
*.emcwasm
+1 -1
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2020 The Pybricks Authors
import { CompileResult, compile as mpyCrossCompile } from '@pybricks/mpy-cross-v5';
import wasm from '@pybricks/mpy-cross-v5/build/mpy-cross.wasm';
import { call, put, takeEvery } from 'redux-saga/effects';
import {
MpyActionType,
@@ -9,7 +10,6 @@ import {
didCompile,
didFailToCompile,
} from '../actions/mpy';
import wasm from './mpy-cross.emcwasm';
/**
* Compiles a script to .mpy and dispatches either didCompile on success or
-5
View File
@@ -8266,11 +8266,6 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
ncp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=
negotiator@0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"