DEV Community 👩‍💻👨‍💻

kthjm
kthjm

Posted on

Workspaces and Rollup

How to resolve modules located in workspaces by rollup.

situation is:
workspace-a and workspace-b that contain modules are set in "workspaces".

// package.json
"private": true,
"workspaces": [
  "workspace-a/*", // workspace-a/[module]/package.json
  "workspace-b/*"
],

To resolve the modules, pass the directories to rollup-plugin-node-resolve via customResolveOptions.moduleDirectory.

// rollup.config.js
import Resolve from 'rollup-plugin-node-resolve'

const resolve = Resolve({
  customResolveOptions: {
    moduleDirectory: [ // as array
      'workspace-a',
      'workspace-b',
    ]
  }
})

And it is necessary that [module]'s dirname equals to its "name" in package.json.


There may be the way more smart, this is just a solution.😗

Top comments (0)

DEV

Thank you.

 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.