简体   繁体   English

Nx 工作区:Angular CLI 在迁移到 NX 后找不到文件路径

[英]Nx Workspace: Angular CLI does not find file path after migrate to NX

I'm trying to migrate an Angular CLI app to Nx.我正在尝试将 Angular CLI 应用程序迁移到 Nx。 My main goal is to turn my entire app into a big nx project and after that gradually split it into small remote apps and shared libs我的主要目标是将我的整个应用程序变成一个大型 nx 项目,然后逐渐将其拆分为小型远程应用程序和共享库

A execute the command ng add @nrwl/workspace and it moves my application to the apps//src, created nx.json, created prettier config files... I think everything went well, however, my components into the apps folder don't find any file path.执行命令ng add @nrwl/workspace并将我的应用程序移动到应用程序//src,创建 nx.json,创建更漂亮的配置文件......我认为一切顺利,但是,我的组件进入应用程序文件夹不' t 找到任何文件路径。

I already have created a path into tsconfig.base.json, but components still can not find the file path.我已经创建了一个到 tsconfig.base.json 的路径,但是组件仍然找不到文件路径。 Is there any config that I missed?有没有我错过的配置?

tsconfig.base.json tsconfig.base.json

 "paths": {
      "@bulk-components/*": [
        "apps/portal-alelo-auto/src/app/shared/components/bulk/*"
      ]

Component example app/portal-alelo-auto/src/app/quick-search/card-detail/reissue/reissue.component.ts组件示例app/portal-alelo-auto/src/app/quick-search/card-detail/reissue/reissue.component.ts

import { CustomerType } from 'src/app/shared/enum'; //
import { MessageModule } from '@bulk-components/shared/message/message.module';

Your best bet will be to create a new workspace using the nx version compatible with the angular version you currently have.您最好的选择是使用与您当前拥有的 angular 版本兼容的 nx 版本创建一个新工作区。

First create two work spaces, one for you to use as reference, and one for you to use to migrate you project into.首先创建两个工作空间,一个用作参考,一个用于将项目迁移到其中。

replace "latest" with he intended version, and execute twice (When asked about 'preset', select angular)用他想要的版本替换“最新”,并执行两次(当被问及“预设”时,select 角度)

npx create-nx-workspace@latest  

this wil create one app in each workspace (more info in the official docs )这将在每个工作区创建一个应用程序(官方文档中的更多信息)

Install the cli for a better experience with nx:安装 cli 以获得更好的 nx 体验:

npm install -g nx

Using as a base folder <workspace-base>/apps/<your app>/src i will call this base用作基础文件夹<workspace-base>/apps/<your app>/src我将调用此base

  1. move the following files to the base folder overwriting the existing ones:将以下文件移动到覆盖现有文件的基本文件夹:
  • index.html索引.html
  • main.ts main.ts
  • styles.scss styles.scss
  • favicon.ico (if yours is there) favicon.ico (如果你有的话)
  1. ignore all the other files from the base level忽略基础级别的所有其他文件

  2. copy all the remainder app folders into <workspace-base>/apps/<your app>/src/app将所有剩余的应用程序文件夹复制到<workspace-base>/apps/<your app>/src/app

  3. add to <workspace-base>/package.json the libs your app uses (apart from angular dependencies).添加到<workspace-base>/package.json您的应用程序使用的库(除了 angular 依赖项)。

  4. run npm i运行npm i

now let us try to run your app with nx.现在让我们尝试使用 nx 运行您的应用程序。

run

nx serve <your app>

There probably will be some imports to adjust in your app files, but nothing that a few replace all commands in your IDE of choice wouldn't fix.在您的应用程序文件中可能会有一些需要调整的导入,但只有少数替换您选择的 IDE 中的所有命令都无法修复。

Make sure you consult your reference workspace to verify if you changed too much on the nx base files (when you need to).确保您查阅参考工作区以验证您是否对 nx 基础文件进行了太多更改(当您需要时)。

It is fairly hard to provide any more instructions than this, as each app has its peculiarities, but this is the path to glory!提供比这更多的说明是相当困难的,因为每个应用程序都有其特点,但这是通往荣耀的道路!

The alternative to this manual migration to nx is to run the instructions from nx official documentation .此手动迁移到 nx 的替代方法是运行nx 官方文档中的说明。 To be honest, I was never successful just using the instructions there, and I have migrated quite a few angular projects to nx.老实说,仅使用那里的说明我从来没有成功过,我已经将很多 angular 项目迁移到 nx。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM