如何导出组件直接导入

时间:2021-04-15 11:33:46

标签: shared-libraries monorepo

我正在制作一个跨平台的 react monorepo,我想单独使用组件,即 import User from 'components/User' 而不是 import { User } from 'components'

这是为了加快构建/重建时间,因为并非我的 monorepo 中的每个应用都需要所有组件。

我该怎么做?

如果我尝试直接从文件夹中导入组件,应用程序会崩溃: enter image description here

我使用 babel 来转译我的组件库:

// packages/components/package.json
{
  "name": "@monorepo/components",
  "version": "0.0.1",
  "private": true,
  "main": "build/index.js",
  "scripts": {
    "dev": "babel src --out-dir build --watch",
    "build": "babel src --out-dir build",
  }
}

0 个答案:

没有答案