nuxt3 + vue + typescript lib 的良好构建设置?

问题描述 投票:0回答:0

我想构建一个小库,其中包含我正在构建的特定 nuxt3 模块的帮助程序。为了集中一些样板文件,我希望我的库导出:

  • helper 函数 - 一些 helper 函数将包装 @nuxt/kit 中的函数,例如我想提供一个功能来创建一个 nuxt 模块,其中包含一些我在所有消费项目中都需要的通用设置和设置功能。该函数本身将调用 defineNuxtModule()
  • Typescript 的类型
  • 共享 Vue 组件

我希望能够像这样消费所有这些东西:

import { helperFunction, VueComponent, Type } from 'my-lib'

我尝试了不同的设置,甚至无法说出我可能已经接近多远,但每次在使用 lib 时都会出现构建问题或运行时或编译时问题。例如我使用了这里的基本设置:https://github.com/agrisom/vue-npm-library-example 但是一旦我添加 @nuxt/kit 作为依赖项并使用它,rollup 将无法像这样正确构建包:

[rpt2] [vite]: Rollup failed to resolve import "#head" from "node_modules/nuxt/dist/app/index.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

现在,如果我真的添加

  build: {
    rollupOptions: {
      external: ['#head']
    }
  }

并修复该类型的更多投诉,构建工作正常,但在使用库时,会发生错误:

Error while requiring module ../src/module: Error: Cannot find module '#head'

这告诉我这不是正确的方法。

我正在寻找解决该问题或任何构建设置的解决方案,让我拥有上述功能。

typescript vuejs3 lib nuxt3
© www.soinside.com 2019 - 2024. All rights reserved.