- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在典型的 .NET Core 项目(使用 Visual Studio 2019)中,我们有这样的结构:
Example/
|-- Example.Common/
| |-- FileExample1.cs
| |-- FileExample2.cs
| `-- Example.Common.csproj
|-- Example.WebAPI/
| |-- Controllers/
| |-- Program.cs
| |-- Startup.cs
| `-- Example.WebAPI.csproj
|-- Example.CLI/
| |-- Program.cs
| `-- Example.CLI.csproj
|-- Example.sln
在这个项目中,Example.CLI
和Example.Web.API
都引用了Example.Common
项目。 Example.sln
文件引用了所有三个 *.csproj
并且每个 csproj 都有自己的依赖项,可以是以下 4 种之一:
<!-- It is a NuGet package (similar to Node.js npm packages) that always resolves from the public nuget.org registry -->
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.3" />
<!-- It is local, never resolves from registry -->
<ProjectReference Include="../Example.Common/Example.Common.csproj" />
<!-- Resolves from a machine-wide installed DLL -->
<Reference Include="Global.Dependency.Example" />
<!-- Resolves from a local DLL -->
<Reference Include="Local.Dependency.Example">
<HintPath>path/to/Local.Dependency.Example.dll</HintPath>
</Reference>
在开发期间在本地运行时,如果我在 Common 源代码中更改某些内容并运行 CLI 项目,它会自动重建 Common 并将 DLL 复制到目标位置,以便 CLI 可以运行具有这些最新更改的版本。即使我在解决方案中有更多项目,它也只会重建 CLI 所依赖的项目,以及自上次运行以来是否有任何更改。
部署时,它会重建所有内容并在本地解决本地依赖项。我对 Node.js 和 NPM 包的问题是:
我想在 Node.js 项目中做同样的事情,分享 common
源代码以用于 web-api
和 cli
,并且我想在一个 npm 包中分解项目的每个组件,这样每个包都可以有自己的依赖项。
在一个 Node.js 项目中,我有一个类似的结构:
example/
|-- common/
| |-- file-example1.js
| |-- file-example2.js
| `-- package.json
|-- web-api/
| |-- controllers/
| |-- index.js
| |-- routes.js
| `-- package.json
|-- cli/
| |-- index.js
| `-- package.json
|-- package.json
问题在于 Node.js 和 npm/yarn/pnpm 如何解决依赖关系。我尝试使用 Yarn Workspaces、Lerna、Lerna + Yarn Workspaces,但似乎所有这些工具都是为发布到注册表的包而制作的,而不是为了帮助模块化单个项目。
我想要的是一个简单的方法来做到这一点:
yarn install
或创建npm手动链接
我试过:
link:
协议(protocol),适用于开发,但当我运行 yarn install --production
时,它会尝试使用注册表进行解析。不会工作,因为我的任何包都不会发布到任何注册表。file:
协议(protocol),适合部署,但对于开发,当我在公共(public)包中进行更改时,我需要删除 node_modules
中的公共(public)文件夹,并且再次运行 yarn install
。即使使用 file:
协议(protocol),我仍然需要一种以正确顺序构建的方法,否则,npm/yarn 只会将依赖项的源代码复制到目标 node_modules 文件夹。最佳答案
简答:
lerna bootstrap
lerna run dev
bootstrap
会将依赖项安装到相应的包中。示例:common
应安装在 web-api
中。Lerna 将在 web-api
中安装 common
作为 node_module
。
在 package.json
中添加 private: true
也将确保 lerna publish 不会发布这些项目。
(长答案:)
给定文件夹目录
example/
|-- common/
| |-- file-example1.js
| |-- file-example2.js
| `-- package.json
|-- web-api/
| |-- controllers/
| |-- index.js
| |-- routes.js
| `-- package.json
|-- package.json
<强>1。 yarn 工作区。
示例/package.json
{
"private": true,
"workspaces": ["common", "web-api"]
}
在各自的子文件夹中初始化 yarn 。
终端
~/example $ cd ./common
~/example/common $ yarn init -y
~/example/common $ cd ../web-api
~/example/web-api $ yarn init -y
在示例/common/package.json 中
{
"name": "common",
"version": 1.0.0
...
}
例如/web-api/package.json
{
"name" "web-api",
"dependencies": {
"common": "1.0.0"
}
}
终端 (在 web-api 目录中)
~/example/web-api $ yarn install
在根目录中应该有一个 node_modules
应该包括:
web-api/
common/
yarn
将从在根级别创建的 node_modules 文件夹中创建 common
和 webapi
之间的符号链接(symbolic link)。
但是,yarnpkg
约定是使用
{
"private": true,
"workspaces": ["packages/"]
}
引用:Ben awad tutorial on yarn workspaces
<强>2。勒纳
Lerna 在引擎盖下使用 yarn 工作区 ref但是你需要一个 lerna.json
配置(它可以指定你需要的包管理器 npm, yarn...)
lerna.json
{
"packages": [
"packages/*"
],
"version": "0.0.0"
}
lerna
中有额外的命令,例如:
- lerna diff common
它将为您提供自上次提交以来的 git diff,或者。- lerna run test
将在每个包中运行 test
脚本。 (使用 --scope={common}
只针对 common test
脚本)。
在create-react-app
它们还包括一个“变更日志”字段,我认为人们会如何自动为他们的提交消息添加前缀。
关于javascript - 如何像 Visual Studio 项目一样开发/构建 Javascript monorepo 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61189279/
我想根据我使用的 visual studio 版本编译不同的东西,比如 #if VISUAL_STUDIO_VERSION > 2015 eventH?.Invoke(this, EventArgs.
在 Visual Studio 2010 中调试并将鼠标悬停在变量名称上时,我可以选择使用 3 种不同的内置可视化工具:文本、XML 和 HTML。 这是我所指的示例: 由于我越来越多地使用基于 JS
我将可视化编程语言理解为允许程序员在屏幕上操作图形(而不是文本)对象以构建功能的语言。 我在 C#、VB 等中看到的最接近的东西是 RAD 控件,但这只是组成 UI 和最简单的功能——甚至与语言本身无
我目前正在使用 Visual Studio 2015 来编程 ASP.NET Core 应用程序。我对安装 Visual Studio 2017 有以下疑问: 什么被认为是最佳实践和/或最干净的方法?
尝试从扩展和更新获取 Visual Studio 扩展时,出现以下错误:- 向 visualstudiogallery.msdn.microsoft.com/Services/VStudio/Exte
我已经开发了Windows服务,并且该服务正在我的帐户下在本地计算机上运行。当我尝试通过在Visual Studio 2008中将其作为一个过程附加该服务来调试该服务时,我得到“无法附加到该过程。 V
作为标准安装的一部分,Visual Studio Code 带有一个名为“Monokai Dimmed”的颜色主题。 有没有办法将它移植到 Visual Studio 2015?我检查了社区主题( h
Visual Studio Community Edition是否可以使用Visual Studio Online帐户上的存储库? 我一直为包含在Online帐户中的Visual Studio Onl
我正在使用文本可视化工具在 Visual Studio 中调试字符串变量。然而,似乎字符串中间的大部分不见了。这背后的原因是什么? 最佳答案 Visual Studio 中的 Text Visuali
我正在开始一个涉及使用多个 SDK 的新项目,包括: 英特尔凌动开发者 SDK 文本转语音 SDK(建议?) 某种网络摄像头和增强现实支持(建议?) 我目前有 2008,但我也可以安装 2010。是否
我想知道,如果我发送一个解决方案文件夹(它是用 visual studio C# 编写的),您可以在 visual studio for mac 中打开解决方案吗? 在visual studio 20
有没有办法在 Visual Studio Code 和 Visual Studio 中设置相同的快捷方式(而不必每次都手动更改它们)? 例如,我在 Visual Studio Code 中经常使用 A
我无法启用 实时可视化树 在 Visual Studio 2017 用于 UWP 应用程序 (C#)。这个工具在 VS2015 上工作,但在 VS2017 中从来没有为我工作过。它对我的 WPF 项目
我刚开始了解 Visual Studio Code。我想知道,我可以将 Visual Studio 替换为所有 .NET 开发相关的工作吗? 我可以节省 Visual Studio 许可的成本吗? V
我安装了具有有效许可证(Visual Studio 订阅)的 Visual Studio 2019 企业版(VS 2019 16.1.4),它运行良好。 突然之间,当我尝试打开项目或项目中的任何文件时
Visual Studio 2015 Pro 提供以下 错误 : error BC36716: Visual Basic 9.0 does not support implicit line cont
我正在我的 PC 中使用 .net Framework 2.0 和 Visual C#(Microsoft Visual Studio 2008)开发 Windows 应用程序。 完成我的项目后,我必
有什么方法可以在启动 VS 时禁用 VA X 并仅在需要时将其重新打开?因为它会导致一些滞后。我似乎在 VS 的选项或 VA 的选项中都找不到该选项。 最佳答案 持shift在 Visual Stud
我可以将 Visual Studio 命令提示符 与免费的 Visual C# Express 一起使用吗? Visual Studio 命令提示符 被引用 here : Run 'Visual St
这很容易成为 Visual Studio 历史上最烦人的“功能”之一,我不明白它为什么存在 -- 曾经 . 为什么 CodePlex 项目需要关心我使用的是什么版本的 Visual Studio? 在
我是一名优秀的程序员,十分优秀!