Environment-specific arguments in Ionic 3

ionic build android --prod --device environment-specific arguments are used with an ionic command line interface such as ionic build android --prod --device to distinguish your JavaScript / Typescript code depending on the environment, e.g. production and development ?

Should I use process.env.IONIC_ENV ? Or how can I request this difference?

+9
source share
2 answers

Rob Ferguson’s textbook has three things. Depending on your file structure, which is completely interchangeable ( ./ denotes the root directory of your application).

./tsconfig.json

 { "compilerOptions": { "baseUrl": "./src", "paths": { "@env": [ "env/env" ] }, ... } ... } 

./package.json

 { "config": { "ionic_source_map_type": "source-map", "ionic_webpack": "./config/webpack.config.js" }, ... } 

./config/webpack.config.js (depending on ionic_webpack in package.json )

 /* * The webpack config exports an object that has a valid webpack configuration * For each environment name. By default, there are two Ionic environments: * "dev" and "prod". As such, the webpack.config.js exports a dictionary object * with "keys" for "dev" and "prod", where the value is a valid webpack configuration * For details on configuring webpack, see their documentation here * https://webpack.js.org/configuration/ */ const path = require('path'); // If you start your building process with the flag --prod this will equal "prod" otherwise "dev" const ENV = process.env.IONIC_ENV; const devConfig = { entry: ..., output: {...}, devtool: ..., resolve: { extensions: [...], modules: [...], alias: { // this distincts your specific environment "dev" and "prod" "@env": path.resolve(`./src/env/env.ts`), } }, module: {...}, plugins: [...], node: {...} }; const prodConfig = { entry: ..., output: {...}, devtool: ..., resolve: { extensions: [...], modules: [...], alias: { // this distincts your specific environment "dev" and "prod" "@env": path.resolve(`./src/env/env.prod.ts`), } }, module: {...}, plugins: [...], node: {...} }; module.exports = { dev: devConfig, prod: prodConfig } 

Description

The magic comes with devConfig.resolve.alias and prodConfig.resolve.alias . This line of code creates an imported alias, such as your own modules or node modules. Now it will be possible to enter through import { ENV } from '@env' any module, component, service, pipe or whatever.

Note

Remember to create files specific to your environment. In this example, you will need a file structure like this:

 ./ | package.json β”‚ tsconfig.json β”‚ └── config β”‚ webpack.config.js β”‚ └── src β”‚ └── env env.ts (dev environment variables) env.prod.ts (prod environment variables) 

Sample file

./src/env/env.ts (by default it will be development)

 export const ENV = { production: false, isDebugMode: true }; 

./SRC/ENV/env.prod.ts

 export const ENV = { production: true, isDebugMode: false }; 
+16
source

I am upset by these half-answered (with unspecified assumptions) questions. Can someone just provide valid CLI instructions to run the build?

It:

 ionic cordova platform save ionic cordova platform add ios cd platforms pod install cd .. ionic cordova build ios 
0
source

Source: https://habr.com/ru/post/1275248/


All Articles