首页 > 解决方案 > 用于发布的 Angular 节点模块的版本控制

问题描述

在尝试在 npm 上发布 Angular 组件时,我不太确定哪些文件夹和文件应该包含在版本控制过程中,哪些应该包含在.gitignore.

我使用 Angular CLI 进行发布。主要代码在其中,为了进行转译,我使用项目文件夹内的./projects/nls-ngx-module/src/**本机 angular 命令。ng build --proddist/一个带有项目标题的新文件夹中。美好的。

转译后,node_modules项目文件夹中又增加了一个文件夹,默认不忽略。它只包含一个.cache带有子文件夹和文件的文件夹。这让我很恼火,因为在其他示例项目中它们没有出现,但它们也没有被手动忽略.gitignore

文件夹结构

├── ...
├── projects
│   └── nls-ngx-module
│       ├── karma.conf.js
│       ├── ng-package.json
│       ├── ng-package.prod.json
│       ├── package.json
│       ├── src
│       │   ├── lib
│       │   │   ├── ...
│       │   ├── public_api.ts
│       │   └── test.ts
│       ├── tsconfig.lib.json
│       ├── tsconfig.spec.json
│       └── tslint.json
├── src
│   ├── app
│   │   ├── ...
│   ├── assets
│   ├── browserslist
│   ├── environments
│   │   ├── ...
│   ├── ...
├── ...

.gitignore

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
package-lock.json

# System Files
.DS_Store
Thumbs.db

示例取自:

标签: javascriptnode.jsangularbashgitignore

解决方案


不,不必修改.gitignore文件。该ng build命令在错误的目录中执行。

不要在应用程序的根目录之外ng build --prod运行或任何类似的ng build命令。只有在项目目录的子文件夹中运行命令时,才会在项目目录中创建node_modules文件夹。ng build

注意
ng build命令分发package.json. 因此,必须有一个node_modules文件夹才能正确捆绑构建的库。


推荐阅读