How to use webpack with a monorepo (yarnpkg workspaces)

后端 未结 3 1445
眼角桃花
眼角桃花 2020-12-30 00:41

I\'m using yarn workspaces where the root directory has a package directory with all my repos. Each repo has its own node_modules directory containing its dependencies. Th

3条回答
  •  清歌不尽
    2020-12-30 01:16

    If using yarn workspaces with webpack-node-externals a better solution than setting modulesFromFile: true is to use the following externals setting in your webpack config:

    externals: [
      nodeExternals(),
      nodeExternals({
        modulesDir: path.resolve(__dirname, 'path/to/root/node_modules'),
      }),
    ],
    

    Essentially using two instances of nodeExternals. 1 for the package node_modules and one for the root node_modules.

提交回复
热议问题