Skip to content

Commit ff69fc0

Browse files
committed
Merge pull request #751 from karlhorky/patch-1
Expand on per-environment build instructions
2 parents ba352f3 + 389822a commit ff69fc0

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed
Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
1-
# How can I have an environment specific build?
1+
# How can I build for a specific environment?
22

3-
## [#460](https://github.com/Swiip/generator-gulp-angular/issues/460)
3+
## [#460](https://github.com/Swiip/generator-gulp-angular/issues/460) [#650](https://github.com/Swiip/generator-gulp-angular/issues/650)
44

5-
Nope we don't have equivalent.
6-
But I think you can choose different Firebase more simply with [gulp-ng-constant](https://www.npmjs.com/package/gulp-ng-constant)
5+
`generator-gulp-angular` does not yet have a way to build for different environments.
76

7+
One way to do this is with [gulp-ng-constant](https://www.npmjs.com/package/gulp-ng-constant):
8+
9+
#### 1) Create a new gulp task called `config`.
10+
11+
This reads in the configuration in either `config.json` or `configDev.json`, based on the `NODE_ENV` environment variable and generates an Angular module with the contents to be included in your application.
812

9-
#### 1) create a new task `config`
1013
```javascript
1114
gulp.task('config', function () {
1215
var configPath = 'config.json';
13-
if (process.env.NODE_ENV === 'test') {
14-
configPath = 'configTest.json';
16+
if (process.env.NODE_ENV === 'dev') {
17+
configPath = 'configDev.json';
1518
}
1619
return gulp.src(configPath)
1720
.pipe($.ngConstant())
1821
.pipe(gulp.dest('src/app/'));
1922
});
2023
```
21-
#### 2) add config as a dependency of scripts
24+
25+
*configDev.json*
26+
```json
27+
{
28+
"name": "myApp.config",
29+
"constants": {
30+
"config": {
31+
"apiBase": "https://localhost/v1"
32+
}
33+
}
34+
}
35+
```
36+
37+
*config.json*
38+
```json
39+
{
40+
"name": "myApp.config",
41+
"constants": {
42+
"config": {
43+
"apiBase": "https://api.example.com/v1"
44+
}
45+
}
46+
}
47+
```
48+
49+
#### 2) Add the `config` gulp task as a dependency of `scripts`.
50+
2251
```javascript
2352
module.exports = function(options) {
2453
gulp.task('scripts', ['config'], function () {
@@ -30,12 +59,19 @@ module.exports = function(options) {
3059
});
3160
};
3261
```
33-
#### 3) use the module constante created in your app
3462

35-
#### 4) run gulp with environnement variable
36-
```
37-
$ NODE_ENV=test gulp serve
38-
$ NODE_ENV=test gulp
63+
#### 3) Use the generated module in your app.
64+
65+
```javascript
66+
angular.module('myApp', ['myApp.config'])
67+
.service('apiService', ['config', function (config) {
68+
this.base = config.apiBase;
69+
});
3970
```
4071

41-
Anyway if you use gulp-preprocess, PR is welcome (to add in advanced option)
72+
#### 4) Run gulp with environment variable to build for the `dev` environment.
73+
74+
```bash
75+
$ NODE_ENV=dev gulp serve
76+
$ NODE_ENV=dev gulp
77+
```

0 commit comments

Comments
 (0)