Add comlink-loader support in CRA (Typescript) using CRACO

Viewed 322

I'm trying to add the comlink-loader to webpack using CRACO but it's not working. I have this in the craco.config.js

module.exports = {
  webpack: {
    plugins: [],

    configure(webpackConfig) {
      const workerExtenstion = /\.worker\.(js|ts)$/i;

      const comlinkLoaderRule = {
        test: workerExtenstion,
        use: [
          {
            loader: require.resolve('comlink-loader'),
            options: {
              singleton: true,
            },
          },
        ],
      };

      addBeforeLoader(webpackConfig, loaderByName('file-loader'), comlinkLoaderRule);

      return webpackConfig;
    },
  },
};

And my worker is in a file called process-data.worker.ts. This is imported using:

import { processData } from './workers/process-data.worker.ts';

Which I think from the docs should just work. Is there something I'm missing?

Thanks

Adam

0 Answers
Related