In the Usage section it describes to create a web worker, which needs to import the following:
import { AnalysisWebWorker } from "yoastseo";
In meteor you can put the web worker script in the public folder, then it will be accessible to the client but it wont be able to import the node module.
You should make this worker file available as a dynamic import. To do so, add import(‘your-npm-module/workerfile.js’) somewhere in your code where it doesn’t get executed, for example if (false) {…}. Meteor build system will detect that you may want to use it dynamically and will package it separately.
Write your script where you import the library and then const worker = new Worker( ‘/path/to/worker-script.js’ ) in your client startup.
Alternatively, if you find a CDN version of the library, you can import it in a public/sw.js with importScripts('https://......')
I just tried, but how do I get to know the url for the seperate worker package? Is that even possible?
You need to provide the full url, as per documentation:
// `url` needs to be the full URL to the script for the browser to know where to load the worker script from.
// This should be the script created by the previous code-snippet.
const url = "https://my-site-url.com/path-to-webworker-script.js"
const worker = new AnalysisWorkerWrapper( createWorker( url ) );
I tried looking in chrome devtools sources after implementing the dynamic import, but cant find the script.
Which suggests to bundle the yoast js script into a bundle using webpack. I tried (without any knowledge in webpack) to do that, but more or less with trial and error. I am not able to find any kind of guid for this sort of thing. Anyone might be able to point me in the right direction?
I am also noticing right now, I probably should head to the yoast repository and ask the question there, it doesnt really seem to have much to do with meteor.