Skip to content

Commit

Permalink
feat(angular): add browser-esbuild support (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
chihab authored Feb 22, 2024
1 parent 6f3c3a9 commit 65feb6b
Show file tree
Hide file tree
Showing 16 changed files with 2,824 additions and 1,346 deletions.
98 changes: 98 additions & 0 deletions examples/apps/ng-app-cli/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,104 @@
},
"defaultConfiguration": "production"
},
"build-browser": {
"builder": "@ngx-env/builder:browser",
"options": {
"outputPath": "dist/ng-app-cli",
"index": "src/index.html",
"main": "src/main.ts",
"localize": ["fr"],
"i18nMissingTranslation": "error",
"polyfills": ["zone.js", "src/polyfills.ts"],
"tsConfig": "tsconfig.app.json",
"ngxEnv": {
"prefix": "NGX_",
"unsecure": true,
"files": [".env.app", ".env"]
},
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"build-be": {
"builder": "@ngx-env/builder:browser-esbuild",
"options": {
"outputPath": "dist/ng-app-cli",
"index": "src/index.html",
"main": "src/main.ts",
"localize": ["fr"],
"i18nMissingTranslation": "error",
"polyfills": ["zone.js", "src/polyfills.ts"],
"tsConfig": "tsconfig.app.json",
"ngxEnv": {
"prefix": "NGX_",
"unsecure": true,
"files": [".env.app", ".env"]
},
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve-be": {
"builder": "@ngx-env/builder:dev-server",
"configurations": {
"production": {
"buildTarget": "ng-app-cli:build-be:production"
},
"development": {
"buildTarget": "ng-app-cli:build-be:development"
}
},
"defaultConfiguration": "development"
},
"serve": {
"builder": "@ngx-env/builder:dev-server",
"configurations": {
Expand Down
34 changes: 19 additions & 15 deletions examples/apps/ng-app-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@
"watch": "ng build --watch --configuration development",
"start": "ng serve",
"prebuild": "npx ng config projects.ng-app-cli.architect.build.options.ngxEnv.prefix 'NGX_'",
"build": "NODE_ENV=production ng build",
"build": "npm run build:browser && npm run build:esbuild-browser && npm run build:application",
"build:application": "NODE_ENV=production ng build",
"build:esbuild-browser": "NODE_ENV=production ng run ng-app-cli:build-be",
"build:browser": "NODE_ENV=production ng run ng-app-cli:build-browser",
"pretest": "npx ng config projects.ng-app-cli.architect.test.options.ngxEnv.prefix 'NGX_'",
"test": "NODE_ENV=test NGX_BRANCH_NAME=main ng test --watch=false",
"e2e": "playwright test",
"static": "serve dist/ng-app-cli/browser/fr -p 8081"
},
"private": true,
"dependencies": {
"@angular/animations": "^17.1.0",
"@angular/common": "^17.1.0",
"@angular/compiler": "^17.1.0",
"@angular/core": "^17.1.0",
"@angular/forms": "^17.1.0",
"@angular/platform-browser": "^17.1.0",
"@angular/platform-browser-dynamic": "^17.1.0",
"@angular/platform-server": "^17.1.0",
"@angular/router": "^17.1.0",
"@angular/ssr": "^17.1.0",
"@angular/animations": "^17.2.0",
"@angular/common": "^17.2.0",
"@angular/compiler": "^17.2.0",
"@angular/core": "^17.2.0",
"@angular/forms": "^17.2.0",
"@angular/platform-browser": "^17.2.0",
"@angular/platform-browser-dynamic": "^17.2.0",
"@angular/platform-server": "^17.2.0",
"@angular/router": "^17.2.0",
"@angular/ssr": "^17.2.0",
"express": "^4.18.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.1.0",
"@angular/cli": "^17.1.0",
"@angular/compiler-cli": "^17.1.0",
"@angular/localize": "^17.1.0",
"@angular-devkit/build-angular": "^17.2.0",
"@angular/cli": "^17.2.0",
"@angular/compiler-cli": "^17.2.0",
"@angular/localize": "^17.2.0",
"@ngx-env/builder": "file:../../../packages/angular",
"@types/express": "^4.17.17",
"@types/jasmine": "~5.1.0",
"@types/node": "^18.18.0",
Expand Down
51 changes: 51 additions & 0 deletions examples/apps/ng-app-cli/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interface ImportMeta {
readonly env: ImportMetaEnv;
}

interface ImportMetaEnv {
/**
* Built-in environment variable.
* @see Docs https://github.com/chihab/dotenv-run/packages/angular#node_env.
*/
readonly NODE_ENV: string;
// Add your environment variables below
// readonly NG_APP_API_URL: string;
[key: string]: any;
}

/*
* Remove all the deprecated code below if you're using import.meta.env (recommended)
*/

/****************************** DEPREACTED **************************/
/**
* @deprecated process.env usage
* prefer using import.meta.env
* */
// declare var process: {
// env: {
// NODE_ENV: string;
// [key: string]: any;
// };
// };

// If your project references @types/node directly (in you) or indirectly (as in RxJS < 7.6.0),
// you might need to use the following declaration merging.
// declare namespace NodeJS {
// export interface ProcessEnv {
// readonly NODE_ENV: string;
// // Add your environment variables below
// }
// }

// If you're using Angular Universal and process.env notation, you'll need to add the following to your tsconfig.server.json:
/* In your tsconfig.server.json */
// {
// "extends": "./tsconfig.app.json",
// ...
// "exclude": [
// "src/env.d.ts"
// ]
// }

/*********************************************************************/
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"@dotenv-run/load": "^1.3.4",
"@dotenv-run/webpack": "^1.3.4",
"@dotenv-run/rollup": "^1.3.4",
"webpack": "^5.0.0",
"webpack": "5.90.1",
"serve": "^14.2.1",
"@playwright/test": "^1.37.1",
"webpack-cli": "^5.0.0",
"rollup": "^3.0.0",
"nx": "^16.5.5"
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@changesets/cli": "^2.27.1",
"concurrently": "^8.2.2",
"turbo": "^1.10.16",
"typescript": "^5.2.2",
"turbo": "^1.12.4",
"typescript": "^5.3.3",
"vitest": "^0.33.0"
}
}
7 changes: 6 additions & 1 deletion packages/angular/builders.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../node_modules/@angular-devkit/architect/src/builders-schema.json",
"$schema": "./node_modules/@angular-devkit/architect/src/builders-schema.json",
"builders": {
"browser": {
"implementation": "./dist/builders/browser",
Expand Down Expand Up @@ -30,6 +30,11 @@
"implementation": "./dist/builders/application",
"schema": "./dist/builders/schemas/application.json",
"description": "Build application extended with ngx-env config"
},
"browser-esbuild": {
"implementation": "./dist/builders/browser-esbuild",
"schema": "./dist/builders/schemas/browser-esbuild.json",
"description": "Build browser app extended with ngx-env config using esbuild"
}
}
}
2 changes: 1 addition & 1 deletion packages/angular/collection.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"ng-add": {
"description": "Add ngx-env to your Angular Application",
Expand Down
18 changes: 9 additions & 9 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
"glob": "^10.3.10"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.1.0",
"@angular-devkit/schematics": "^17.1.0",
"@angular-devkit/schematics-cli": "^17.1.0",
"@angular-devkit/architect": "^0.1701.0",
"@angular-devkit/core": "^17.1.0",
"@angular/compiler": "^17.1.0",
"@angular-devkit/build-angular": "^17.2.0",
"@angular-devkit/schematics": "^17.2.0",
"@angular-devkit/schematics-cli": "^17.2.0",
"@angular-devkit/architect": "^0.1702.0",
"@angular-devkit/core": "^17.2.0",
"@angular/compiler": "^17.2.0",
"@dotenv-run/core": "^1.3.4",
"cpy": "^8.1.2",
"karma": "^6.4.2",
"ts-node": "^10.8.0",
"typescript": "~5.2.2",
"rxjs": "^7.0.0",
"webpack": "^5.0.0"
"webpack": "5.90.1"
},
"peerDpendencies": {
"@angular-devkit/architect": "^17.1.0",
"@angular-devkit/architect": "^17.2.0",
"@angular-devkit/schematics-cli": ">=12.0.0",
"rxjs": "^7.0.0",
"webpack": "^5.0.0"
"webpack": "5.90.1"
}
}
Loading

0 comments on commit 65feb6b

Please sign in to comment.