在尝试在 npm 上发布 Angular 组件时,我不太确定哪些文件夹和文件应该包含在版本控制过程中,哪些应该包含在 .gitignore
中。
我使用 Angular CLI 进行发布。主要代码在 ./projects/nls-ngx-module/src/**
中,为了转译,我从内部使用原生 Angular 命令 ng build --prod
项目文件夹。在 dist/
中,出现了一个带有项目标题的新文件夹。很好。
转译后,项目文件夹中会增加一个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
示例取自:
最佳答案
不,不必修改 .gitignore
文件。 ng build
命令在错误的目录中执行。
不要在应用程序的根目录之外运行ng build --prod
或任何类似的ng build
命令。 node_modules 文件夹仅在您在 projects 目录的子文件夹中运行 ng build
命令时在项目目录中创建。
注意
ng build
命令分发 package.json
中列出的所有必要依赖项。因此,必须有一个 node_modules 文件夹才能正确捆绑构建的库。
关于javascript - 用于发布的 Angular Node 模块的版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52099030/