NextJS:构建组件以导出并进入另一个项目
当前设置:我有两个NextJS应用程序:一个我们将称为项目A和一个库存储库,我们将称为LIB Project Lib。项目A是一个相当简单的应用程序,具有几个独立的组件,而Project Lib是许多其他应用程序杠杆的类似图书馆的应用程序。
我要做的事情:包装项目A以构建分配包含其所有组件的方式,然后我可以在项目中利用这些组件。我目前正在使用npm install [email  protected] :< anchoment>/>/< project a> gt; git
,并且效果很好。我当前的问题是,使用npm run build build
时,只有页面才能构建页面,并且它也不会生成每个组件的相应.d.t.t.ts
文件/组件
。
我发现设置“声明”:true /*生成相应的'.d.ts'文件。 */
将为我生成组件,但这似乎并没有解决问题。关于如何做到这一点,我也找不到太多在线。也许我只是一个糟糕的谷歌手,他知道。
无论如何,这是我的tsconfig
和package.json
文件看起来像:
package.json
:
{
...,
"files": [
"lib/**/*"
]
}
tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"jsx": "preserve",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./",
"removeComments": true,
"noEmit": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"components/**/*"
],
"exclude": [
"node_modules/*",
"./node_modules",
"./node_modules/*",
"./lib"
]
}
Current Setup: I have two NextJS apps: one we'll call Project A and a library repo that we'll call Project LIB. Project A is a fairly simple app that has a couple independent components whereas Project LIB is a library-like app that many other apps leverage.
What I am trying to do: Package up Project A in a way where the build distribution contains all of its components that I can then leverage in Project LIB. I am currently building/deploying Project A as a private repo and pulling it into Project LIB using npm install [email protected]:<organization>/<Project A>.git
and that is working fine. My current issue is that only the pages are being build when I build Project A using npm run build
and it doesn't also generate each component's corresponding .d.ts
file under /components
.
I figured setting "declaration": true /* Generates corresponding '.d.ts' file. */
would generate the components for me but that didn't seem to do the trick. I'm also not finding much online regarding how to do this. Maybe i'm just a bad googler, who knows.
Anyways, here's what my tsconfig
and package.json
files looks like:
package.json
:
{
...,
"files": [
"lib/**/*"
]
}
tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"jsx": "preserve",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./",
"removeComments": true,
"noEmit": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"components/**/*"
],
"exclude": [
"node_modules/*",
"./node_modules",
"./node_modules/*",
"./lib"
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论