ngx-cookie 项目使用教程
1. 项目的目录结构及介绍
ngx-cookie 项目的目录结构如下:
ngx-cookie/
├── src/
│ ├── lib/
│ │ ├── cookie.service.ts
│ │ ├── cookie.service.spec.ts
│ │ ├── index.ts
│ ├── public_api.ts
├── package.json
├── tsconfig.json
├── tsconfig.spec.json
├── tslint.json
目录结构介绍
src/
: 源代码目录。lib/
: 包含主要的库文件。cookie.service.ts
: 核心的 Cookie 服务文件。cookie.service.spec.ts
: Cookie 服务的测试文件。index.ts
: 库的入口文件。
public_api.ts
: 公共 API 入口文件。
package.json
: 项目的依赖和脚本配置文件。tsconfig.json
: TypeScript 编译配置文件。tsconfig.spec.json
: TypeScript 测试配置文件。tslint.json
: TSLint 配置文件。
2. 项目的启动文件介绍
项目的启动文件主要是 src/public_api.ts
,它是整个库的入口文件,负责导出库的主要功能。
/* src/public_api.ts */
/*
* Public API Surface of ngx-cookie
*/
export * from './lib/cookie.service';
启动文件介绍
public_api.ts
: 导出cookie.service
,使得其他项目可以通过ngx-cookie
包导入CookieService
。
3. 项目的配置文件介绍
package.json
package.json
文件包含了项目的依赖、脚本和其他元数据。
{
"name": "ngx-cookie",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
},
"main": "bundles/ngx-cookie.umd.js",
"module": "fesm5/ngx-cookie.js",
"es2015": "fesm2015/ngx-cookie.js",
"esm5": "esm5/ngx-cookie.js",
"esm2015": "esm2015/ngx-cookie.js",
"fesm5": "fesm5/ngx-cookie.js",
"fesm2015": "fesm2015/ngx-cookie.js",
"typings": "ngx-cookie.d.ts",
"metadata": "ngx-cookie.metadata.json",
"sideEffects": false,
"dependencies": {
"tslib": "^1.9.0"
}
}
tsconfig.json
tsconfig.json
文件定义了 TypeScript 编译的配置。
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
tslint.json
tslint.json
文件定义了代码风格和质量检查的配置。
{
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"