【问题标题】:Is there a way to include only one module in the bundle?有没有办法在包中只包含一个模块?
【发布时间】:2022-01-05 05:54:33
【问题描述】:

我正在使用lerna、parcel 和 docker 构建微服务后端。我有多个微服务,每个微服务都依赖于 monorepo 中“commons”包中的一些通用代码。

这个公共包永远不会发布到 NPM。因此,它在开发中运行良好,但是一旦我尝试构建 docker 容器,容器内的 commons 模块就无法使用。

有没有办法告诉 parcel 将所有依赖项外部化(就像默认情况下在 nodejs 上所做的那样)除了 commons 包?这可能吗?

【问题讨论】:

    标签: javascript lerna parceljs


    【解决方案1】:

    您可以使用includeNodeModules option 将特定包标记为包含在捆绑包中。例如,在您想要输出包含commons 包而不是简单引用它的项目的package.json 中,您将拥有:

    {
       "main": "dist/index.js" // Or wherever you want to put the bundle.
       "targets": {
        "main": {
          "includeNodeModules": ["commons"]
        }
      }
    }
    

    对于以 nodejs 为目标的包(例如“库”包),对于每个依赖项,此选项默认为 false(例如,所有依赖项都将被“外部化”除了您在此列表中放置的内容- 正是您在上面要求的)。

    (假设您使用的是 Parcel 2+ - 请确保您引用的是 "parcel": "^2.0.1" 不是 parcel-bundler(这是已弃用的 v1 版本)。

    【讨论】:

      猜你喜欢
      • 2022-11-25
      • 2020-08-24
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      相关资源
      最近更新 更多