-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importScripts for libflac in React #4
Comments
Could you provide some more details? |
@russaa Thanks, it's all in React being called like this:
WebWorker.js
flacworker.js (libflac is located in the same folder)
I'm using this construction for loading scripts in other workers without issues |
so, I am not a I tried to create a skeleton project with And Anyway, the default configuration of
Although at some point I would like to, I currently do not have the time to further look into the However, in another project, I did use a
|
Thank you for such a thorough answer, will use it on the weekend and report you back! |
OK, I had another look, and found a solution for
first (this makes later updates for after running
where you'd need to modify the {
//this must match the file-name of the worker script:
test: /\bflacworker\.js$/i,
use: {
loader: 'worker-loader',
options: { name: 'worker-[name].[hash].js' }
}
},
//OPTIONALLY if .wasm or .min variant: for including the binary file
{
test: /\.(wasm|mem)$/i,
use: {
loader: 'file-loader',
options: {
//NOTE binary file must be included with its original file name,
// so that libflac.js lib can find it:
name: function(file) {
return path.basename(file)
}
}
},
}, And then you'd need to change, how the Web Worker is included: //import WebWorker from '../../utils/WebWorker';
//import flacworker from '../../utils/flacworker.js';
componentDidMount = async () => {
//this.flacworker = new WebWorker(flacworker);
this.flacworker = require('../../utils/flacworker.js')();
this.flacworker.onmessage = event => {
const { cmd, buf } = event.data;
console.log(cmd, buf);
}
} Then in the worker script itself, include the //flacworker.js
//export default () => {
self.console.log(location)
self.onerror = function(err){ console.log(err) };
//importScripts('libflac4-1.3.2.min.js');
//for including a "single file variant" of libflac.js, e.g. the standard version:
var Flac = require('./libflac4-1.3.2.js');
//or: for including a .wasm variant, e.g standard-wasm (for binary of min-version include its *.mem file):
require.resolve('./libflac4-1.3.2.wasm.wasm') // <- force webpack to include the binary file
var Flac = require('./libflac4-1.3.2.wasm.js')
self.console.log(Flac)
//} |
... if you install
you can use its module ID in the require statements (and don't need to include/copy the files into the source directories): require.resolve('libflacjs/dist/libflac4-1.3.2.wasm.wasm')
var Flac = require('libflacjs/dist/libflac4-1.3.2.wasm.js') |
Trying to import the script into worker and getting this:
Same for all other script versions
Looks like I am missing something here, could you please help?
The text was updated successfully, but these errors were encountered: