使用 NPM 工作区,我components与其他人(webapp1和)共享一个包( webapp2)。像这样的东西:
root
apps
webapp1
webapp2
packages
components
一切都运行良好,但文件夹components中的所有内容,包括源代码src正在共享。由于components' 编译输出文件夹是dist,我只想共享该文件夹。这是它在根目录中的样子node_modules:
问题是当我需要导入webapp1orwebapp2时,我的导入路径必须包含该dist文件夹。这是我从 VS Code 获得的智能感知:
这就是我导入webapp1和的方式webapp2:
import Center from '@mycompany/components/dist/Center'
虽然一切正常,但如何设置我的 NPM 工作区,以便仅dist在其根目录中共享文件夹的内容?
我已经尝试过 NPM 的文件并.npmignore在components文件夹中忽略除dist文件夹之外的所有内容,但这似乎不起作用。mainpackage.json 中的属性components也设置为指向dist/index.js:
"main": "dist/index.js"
有趣的是,如果我想导入dist/index.js文件,我可以不用dist:
import foo from '@mycompany/components'
...但是,导入除dist/index.js需要dist包含在路径中之外的任何内容。

