Workers and Node

azproduction edited this page Jan 28, 2013 · 1 revision
  • Flags: node, worker

You can use LMD in-package modules (require()) in worker and run it as node script without any config changes. But if you are going to use require.async() or require.js() you should add worker: true or/and node: true config flags. require.css() in node or worker environment acts like require()

  • require.async() in Worker environment works exactly the same as in browser environment
  • require.async() in Node uses fs.readFile() to read file and evals/returns file content depend on file extension
  • require.js() in Worker acts like importScripts() and call back an empty object {}
  • require.js() in Node acts like Node.js GLOBALS.require() and returns module.exports object from node module
  • require.css() in both environments acts like LMD require()

Run tests or see examples/demos/basic/modules/main.js#L60 and examples/demos/basic/modules/workerDepA.js for details