InsightSoftwareConsortium / ITK-Wasm

High performance spatial analysis in a web browser and across programming languages and hardware architectures
https://wasm.itk.org
Apache License 2.0
198 stars 52 forks source link

Problem with createWebWorkerPromise #133

Closed katiamar63 closed 6 years ago

katiamar63 commented 6 years ago

I implemented React application which is using ITK Readers for browsing MRI images. Everything was built in Webpack and worked perfectly as long as I was using only one element in url context path (when images where loaded). When I introduced React Router to my application and started to use longer context paths, the IO Image Workers were not visible anymore (HTTP 404 error). The Chrome inspector was showing error in line 23 of createWebWorkerPromise.js where new window.worker(...) is created. The path to the worker contained too many elements, whilst the working one was: '{domain_url}/itk/WebWorkers/ folder, eg. {domain_url} itk/WebWorkers/ImageIO.worker.js {domain_url}/itk/ImageIOs/itkNiftiImageIOJSBindingWasm.js.

I found that if I change itkConfig.js (in /node_modules), the problem is solved and workers are loaded from proper urls, i.e.

var itkConfig = {
  itkModulesPath: 'itk'   //-> if changed to  '/itk' or to absolute path, then it works for any given path
};

Is it possible to 'inject' my own itkConfig.js using Webpack? Can I replace itkConfig with webpack using similar solution to one described for Karma testing?

resolve: {
        alias: {
          './itkConfig$': path.resolve(__dirname, 'test', 'config', 'itkConfigTest.js'),
        },
      },
thewtex commented 6 years ago

Yes, please see the Webpack example documentation:

https://insightsoftwareconsortium.github.io/itk-js/examples/webpack.html

thewtex commented 6 years ago

Also, the Unpkg.com / CDN provides another example using the Webpack publicPath:

https://insightsoftwareconsortium.github.io/itk-js/examples/unpkgio.html

katiamar63 commented 6 years ago

Thank you, I already applied that and it works.