'Angular build command is not replacing environment files
I am using Angular v6.
My angular.json file has the following configuration
"test": {
"fileReplacements": [
{
"replace": "./src/environments/environment.ts",
"with": "./src/environments/environment.test.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true
},
When i run ng build --configuration=test it is not replacing the environment.ts file with environment.test.ts file.
Here is the configuration it added in the main.js file
/***/ "./src/environments/environment.ts":
/*!*****************************************!*\
!*** ./src/environments/environment.ts ***!
\*****************************************/
/*! exports provided: environment */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "environment", function() { return environment; });
var environment = {
production: false,
buildName: 'development',
}
How to fix this issue?
Solution 1:[1]
Try:
npm run ng build -- --prod
Solution 2:[2]
The issue here is that the actual environment.ts file does not get replaced but if you look at the distribution files, the right values should be in there. You can test that it is doing this by opening main.js and looking for a particular variable name or value.
I myself keep the regular - environment.ts file blank so that if the app pulls up and doesn't throw errors then I know it did it properly.
To be clear, I don't like this small percentage of uncertainty and I'm not sure why it doesn't actually replace the file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeremy Caney |
| Solution 2 | FernandoG |
