Skip to content
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

the worker is located on a path inaccessible to the bundle #51

Open
ravecat opened this issue May 27, 2021 · 3 comments
Open

the worker is located on a path inaccessible to the bundle #51

ravecat opened this issue May 27, 2021 · 3 comments

Comments

@ravecat
Copy link

ravecat commented May 27, 2021

I am a bit confused about building the project from ts example https://github.com/darionco/rollup-typescript-webworkers. how do the bundle will link to the worker if it is located on an inaccessible path and only dist/** send into the published package

Screen Shot 2021-05-27 at 21 07 43

could you clarify that and give an example of rollup config

I've expected similar structure after bundle

dist
├── index.js
├── worker
      ├──worker.js

with current plugins section

import { nodeResolve } from "@rollup/plugin-node-resolve";
import ts from "@wessberg/rollup-plugin-ts";
import webWorkerLoader from "rollup-plugin-web-worker-loader";
...
[
  nodeResolve(),
  webWorkerLoader(),
  ts({
    tsconfig: "tsconfig.build.json",
    hook: {
      declarationStats: (declarationStats) =>
        console.warn(JSON.stringify(declarationStats)),
    },
  }),
  ...
]

I get warning

.../rollup-typescript-webworkers/src/index.ts → dist/next/index.js...
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
web-worker:./Worker.ts (imported by src/index.ts)
@darionco
Copy link
Owner

with your current configuration the worker gets embedded in the index file as a base64 string so there is no need for a standalone worker file. If you want to output an explicit worker file, use the inline option:

...
[
  ...
  webWorkerLoader({ inline: false }).
  ...
]
...

as for the warning, I assume that your worker source file is in the worker folder? if so, your import should be:

import WebWorker from 'web-worker:./worker/Worker.ts';

@ravecat
Copy link
Author

ravecat commented May 28, 2021

@darionco thank you for quick answer and for a little misunderstanding, I am trying to build a project from your example https://github.com/darionco/rollup-typescript-webworkers and get current warning and build structure

So, yes worker exist in right path. How do js resolve web-worker:./worker/Worker.ts? I mean npm-published module. Or maybe I expect impossible from that plugin

@darionco
Copy link
Owner

darionco commented May 31, 2021

I am not sure I understand the question, I'll try to explain how the plugin works by default.:

  • the worker code with all its imports get bundled into a single file
  • the resulting worker bundle gets converted into a base64 string
  • the base64 string gets embedded into the main JavaScript file
  • at runtime the base64 string gets converted to a blob URL
  • each worker instance is loaded from the blob URL

by following those steps, the dist folder doesn't need to ship a worker file because the file is embedded into the main JavaScript file (index.js in the example you linked).

If what you want is for the worker file to not be embedded into the main JavaScript file, that can be done using the option I suggested above:

...
[
 ...
 webWorkerLoader({ inline: false }).
 ...
]
...

Otherwise you could look into using rollup-plugin-off-main-thread since that plugin main functionality is code splitting while this plugin's main functionality is embedding the workers in the main file.

Let me know if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants