npm 仅链接 dist 文件夹 [英] npm link only dist folder

查看:93
本文介绍了npm 仅链接 dist 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法限制 npm link 创建符号链接只指向 ./dist?

Is there a way to restrict npm link to create the symlink only to point at ./dist?

我很挣扎,因为我想在发布之前在本地测试我的库(反应组件).

I am struggling so far as I want to test my library (react component) locally before publishing.

在我的 package.json 中,我包含了主要(入口点):

In my package.json I have included the main (entry point):

"main": "./dist/index.js"

但是当我运行 npm link 时,它仍然链接到具有 node_modules 等的父文件夹.这导致了问题,因为现在我安装了 2 个 React 应用程序.

But still when I run npm link it links to the parent folder which has node_modules and so on. This is causing problems cause now I have 2 react apps installed.

我想到了一种排除 node_modules 的方法,但我什至找不到这样做的方法.

I thought of a way to exclude node_modules but I couldn't even find a way to do that.

推荐答案

这实际上比预期的要简单.首先运行 ng build 来构建你的库项目,然后进入 dist 文件夹并从那里运行 npm link 而不是库根项目.将创建指向 dist 文件夹的符号链接.

This is actually simpler than expected. First run ng build to build your library project, then go under the dist folder and run npm link from there instead of the library root project. The symlink will be created pointing to the dist folder instead.

这篇关于npm 仅链接 dist 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆