我为自定义 Nx 构建器和原理图设置了一个 repo,以构建应用程序/init。最初我在 tools/schematics 文件夹中开发它,一切正常,但决定它应该放在自己的仓库中。我确保将原理图 (collection.json) 和构建器 (builders.json) 添加到 package.json,并设置这两个文件。到那里的一切似乎都在工作。我使用yarn link将原理图添加到我的nx monorepo(所以我不必在测试时重复推送它),然后尝试添加一个应用程序,nx g nx-name:app
但我一直收到一个错误,它无法找到模块示意图。
在发布这个之前我已经尝试了很多。重命名文件。使用 index.ts。重新安装 node_modules。重新连接纱线。
错误:
Cannot find module 'C:\...\monorepo\node_modules\nx-name\src\schematics\application\application'
Require stack:
- C:\...\monorepo\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\...\monorepo\node_modules\@angular-devkit\schematics\tools\index.js
- C:\...\monorepo\node_modules\@nrwl\workspace\src\command-line\workspace-schematic.js
- C:\...\monorepo\node_modules\@nrwl\workspace\src\command-line\nx-commands.js
- C:\...\monorepo\node_modules\@nrwl\workspace\index.js
- C:\...\monorepo\node_modules\@nrwl\cli\lib\init-local.js
- C:\...\monorepo\node_modules\@nrwl\cli\bin\nx.js
- C:\...\AppData\Roaming\npm\node_modules\@nrwl\cli\bin\nx.js
我的收藏.json:
{
"name": "nx-name",
"version": "0.0.1",
"extends": [
"@nrwl/workspace"
],
"schematics": {
"init": {
"factory": "./src/schematics/init/init",
"schema": "./src/schematics/init/schema.json",
"description": "Initialize the plugin",
"aliases": [
"ng-add"
],
"hidden": true
},
"application": {
"factory": "./src/schematics/application/application",
"schema": "./src/schematics/application/schema.json",
"description": "Create an application",
"aliases": [
"app"
]
}
}
}
我的文件夹结构:
- src
- builders
- build
- build.impl.ts
- schema.json
- schematics
- application
- files
- a bunch of template files
- application.ts
- schema.d.ts
- schema.json
- init
- init.ts
- schema.d.ts
- schema.json
- .gitignore
- builders.json
- collection.json
- package.json
- tsconfig.json
- index.ts
- yarn.lock
更新:
将集合工厂指向 dist 文件夹似乎部分运行它?JSON 文件更新,但构建器不会运行并从模板生成文件。也许我需要设置一些东西才能知道构建打字稿源?
添加 package.json 部门:
"dependencies": {
"@angular-devkit/architect": "^0.803.21",
"@angular-devkit/core": "8.3.14",
"@angular-devkit/schematics": "8.3.14",
"shelljs": "^0.8.3",
"typescript": "~3.5.3"
},
"devDependencies": {
"@nrwl/workspace": "^8.9.0",
"@types/node": "^13.1.4",
"@types/shelljs": "^0.8.6"
}