angular - 使用 Angular 构建多个应用程序版本
问题描述
我想创建一个支持多个版本的 Angular 应用程序:“免费版”和“专业版”。假设以下代码结构
app
├───app.module.ts
├───app.component.ts|html|css
├───free-version
│ ├───feature-1
│ └───feature-2
└───pro-version
├───feature-3
└───feature-4
如何让我的 Angular 项目支持:
- 免费版的构建仅包含功能 1 和功能 2
- 专业版的附加版本,包含免费版的所有功能以及功能 3 和功能 4
解决方案
您的一种解决方案是创建 2 个文件夹freemium
:premium
稍后编辑angular.json并设置 2 个项目,确保为相关项目index.html
和main.ts
每个项目定义正确的路径。
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"freemium": {
"root": "src",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/freemium/index.html",
"main": "src/freemium/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico",
"src/manifest.json"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": { ... },
"staging": { ... }
}
}
}
},
"premium": { ... }
}
},
额外的解决方案是为每个项目使用不同的webpack 。webpack.config.js
请注意,您必须在服务器端处理授权层,而不是假设客户端保护足够好。
对您来说最好的解决方案是结合角度路由保护和服务器端授权。
推荐阅读
- html - 危险的setinnerhtml没有在反应中嵌入iframe
- python - AttributeError:“张量”对象没有“读取”属性
- java - java dto中的多部分文件
- godot - set_global_position setting position to the wrong value
- git - 如何清理 git 存储库中损坏的对象?
- javascript - React.JS video player bug
- java - 如何处理 BigDecimal 的错误用户输入
- c++ - 如何在 gcc C++ 编译器中修复 Travis CI 中的错误?
- android - 从 Graph API 返回的 Facebook 链接,但导致某些但不是所有用户的“未找到内容”页面
- swift - 在充满自定义对象的模型中获取第一个不为零的值