Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit d53f25f

Browse files
committed
refactor(configuration): don't expose constants as configuration
don't expose constants as configuration
1 parent 085c897 commit d53f25f

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ npm run build --rollup ./config/rollup.config.js
9393
|-------------|---------------------|-----------------------|
9494
| CleanCss | `ionic_cleancss` | `--cleancss` or `-e` |
9595
| Copy | `ionic_copy` | `--copy` or `-y` |
96+
| Closure | `ionic_closure` | `--closure` or `-l` |
9697
| Generator | `ionic_generator` | `--generator` or `-g` |
9798
| NGC | `ionic_ngc` | `--ngc` or `-n` |
9899
| Rollup | `ionic_rollup` | `--rollup` or `-r` |
@@ -107,13 +108,24 @@ npm run build --rollup ./config/rollup.config.js
107108

108109
| Config Values | package.json Config | Cmd-line Flag | Defaults | Details |
109110
|-----------------|---------------------|---------------|-----------------|----------------|
110-
| bundler | `ionic_bundler` | `--bundler` | `webpack` | Chooses which bundler to use: `webpack` or `rollup` |
111-
| source map type | `ionic_source_map` | `--sourceMap` | `eval` | Chooses the webpack `devtool` option. We only support `eval` or `source-map` for now |
112111
| root directory | `ionic_root_dir` | `--rootDir` | `process.cwd()` | The directory path of the Ionic app |
113-
| tmp directory | `ionic_tmp_dir` | `--tmpDir` | `.tmp` | A temporary directory for codegen'd files using the Angular `ngc` AoT compiler |
114112
| src directory | `ionic_src_dir` | `--srcDir` | `src` | The directory holding the Ionic src code |
115113
| www directory | `ionic_www_dir` | `--wwwDir` | `www` | The deployable directory containing everything needed to run the app |
116114
| build directory | `ionic_build_dir` | `--buildDir` | `build` | The build process uses this directory to store generated files, etc |
115+
| bundler | `ionic_bundler` | `--bundler` | `webpack` | Chooses which bundler to use: `webpack` or `rollup` |
116+
| source map type | `ionic_source_map_type` | `--sourceMapType` | `source-map` | Chooses the webpack `devtool` option. `eval` and `source-map` are supported |
117+
| generate source map | `ionic_generate_source_map` | `--generateSourceMap` | `true` | Determines whether to generate a source map or not |
118+
| tsconfig path | `ionic_ts_config` | `--tsconfig` | `{{rootDir}}/tsconfig.json` | absolute path to tsconfig.json |
119+
| app entry point | `ionic_app_entry_point` | `--appEntryPoint` | `{{srcDir}}/app/main.ts` | absolute path to app's entrypoint bootstrap file |
120+
| clean before copy | `ionic_clean_before_copy` | `--cleanBeforeCopy` | `false` | clean out existing files before copy task runs |
121+
| output js file | `ionic_output_js_file_name` | `--outputJsFileName` | `main.js` | name of js file generated in `buildDir` |
122+
| output js map file | `ionic_output_js_map_file_name` | `--outputJsMapFileName` | `main.js.map` | name of js source map file generated in `buildDir` |
123+
| output css file | `ionic_output_css_file_name` | `--outputCssFileName` | `main.css` | name of css file generated in `buildDir` |
124+
| output css map file | `ionic_output_css_map_file_name` | `--outputCssMapFileName` | `main.css.map` | name of css source map file generated in `buildDir` |
125+
126+
127+
128+
117129

118130

119131
### Ionic Environment Variables
@@ -124,14 +136,25 @@ These environment variables are automatically set to [Node's `process.env`](http
124136
|----------------------------|----------------------------------------------------------------------|
125137
| `IONIC_ENV` | Value can be either `prod` or `dev`. |
126138
| `IONIC_ROOT_DIR` | The absolute path to the project's root directory. |
127-
| `IONIC_TMP_DIR` | The absolute path to the project's temporary directory. |
128139
| `IONIC_SRC_DIR` | The absolute path to the app's source directory. |
129140
| `IONIC_WWW_DIR` | The absolute path to the app's public distribution directory. |
130141
| `IONIC_BUILD_DIR` | The absolute path to the app's bundled js and css files. |
131142
| `IONIC_APP_SCRIPTS_DIR` | The absolute path to the `@ionic/app-scripts` node_module directory. |
132-
| `IONIC_SOURCE_MAP` | The Webpack `devtool` setting. We recommend `eval` or `source-map`. |
133-
| `IONIC_PATH_TO_GLOB_UTILS` | The path to Ionic's `glob-util` script. Used within configs. |
143+
| `IONIC_SOURCE_MAP_TYPE` | The Webpack `devtool` setting. `eval` and `source-map` are supported.|
144+
| `IONIC_GENERATE_SOURCE_MAP`| Determines whether to generate a sourcemap or not. |
145+
| `IONIC_TS_CONFIG` | The absolute path to the project's `tsconfig.json` file |
146+
| `IONIC_APP_ENTRY_POINT` | The absolute path to the project's `main.ts` entry point file |
147+
| `IONIC_GLOB_UTIL` | The path to Ionic's `glob-util` script. Used within configs. |
134148
| `IONIC_CLEAN_BEFORE_COPY` | Attempt to clean existing directories before copying files. |
149+
| `IONIC_CLOSURE_JAR` | The absolute path ot the closure compiler jar file |
150+
| `IONIC_OUTPUT_JS_FILE_NAME` | The file name of the generated javascript file |
151+
| `IONIC_OUTPUT_JS_MAP_FILE_NAME` | The file name of the generated javascript source map file |
152+
| `IONIC_OUTPUT_CSS_FILE_NAME` | The file name of the generated css file |
153+
| `IONIC_OUTPUT_CSS_MAP_FILE_NAME` | The file name of the generated css source map file |
154+
| `IONIC_WEBPACK_FACTORY` | The absolute path to Ionic's `webpack-factory` script |
155+
| `IONIC_WEBPACK_LOADER` | The absolute path to Ionic's custom webpack loader |
156+
157+
135158

136159
The `process.env.IONIC_ENV` environment variable can be used to test whether it is a `prod` or `dev` build, which automatically gets set by any command. By default the `build` task is `prod`, and the `watch` and `serve` tasks are `dev`. Additionally, using the `--dev` command line flag will force the build to use `dev`.
137160

src/util/config.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ export function generateContext(context?: BuildContext): BuildContext {
5858
context.rootDir = resolve(context.rootDir || getConfigValue(context, '--rootDir', null, ENV_VAR_ROOT_DIR, ENV_VAR_ROOT_DIR.toLowerCase(), processCwd));
5959
setProcessEnvVar(ENV_VAR_ROOT_DIR, context.rootDir);
6060

61-
context.tmpDir = resolve(context.tmpDir || getConfigValue(context, '--tmpDir', null, ENV_VAR_TMP_DIR, ENV_VAR_TMP_DIR.toLowerCase(), join(context.rootDir, TMP_DIR)));
62-
setProcessEnvVar(ENV_VAR_TMP_DIR, context.tmpDir);
63-
6461
context.srcDir = resolve(context.srcDir || getConfigValue(context, '--srcDir', null, ENV_VAR_SRC_DIR, ENV_VAR_SRC_DIR.toLowerCase(), join(context.rootDir, SRC_DIR)));
6562
setProcessEnvVar(ENV_VAR_SRC_DIR, context.srcDir);
6663

@@ -86,14 +83,12 @@ export function generateContext(context?: BuildContext): BuildContext {
8683
const appEntryPointPathValue = getConfigValue(context, '--appEntryPoint', null, ENV_APP_ENTRY_POINT, ENV_APP_ENTRY_POINT.toLowerCase(), join(context.srcDir, 'app', 'main.ts'));
8784
setProcessEnvVar(ENV_APP_ENTRY_POINT, appEntryPointPathValue);
8885

89-
const pathToGlobUtils = getConfigValue(context, '--pathToGlobUtils', null, ENV_GLOB_UTIL, ENV_GLOB_UTIL.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'util', 'glob-util.js'));
90-
setProcessEnvVar(ENV_GLOB_UTIL, pathToGlobUtils);
86+
setProcessEnvVar(ENV_GLOB_UTIL, join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'util', 'glob-util.js'));
9187

9288
const cleanBeforeCopy = getConfigValue(context, '--cleanBeforeCopy', null, ENV_CLEAN_BEFORE_COPY, ENV_CLEAN_BEFORE_COPY.toLowerCase(), null);
9389
setProcessEnvVar(ENV_CLEAN_BEFORE_COPY, cleanBeforeCopy);
9490

95-
const pathToClosureJar = getConfigValue(context, '--pathToClosureJar', null, ENV_CLOSURE_JAR, ENV_CLOSURE_JAR.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'bin', 'closure-compiler.jar'));
96-
setProcessEnvVar(ENV_CLOSURE_JAR, pathToClosureJar);
91+
setProcessEnvVar(ENV_CLOSURE_JAR, join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'bin', 'closure-compiler.jar'));
9792

9893
const outputJsFileName = getConfigValue(context, '--outputJsFileName', null, ENV_OUTPUT_JS_FILE_NAME, ENV_OUTPUT_JS_FILE_NAME.toLowerCase(), 'main.js');
9994
setProcessEnvVar(ENV_OUTPUT_JS_FILE_NAME, outputJsFileName);
@@ -107,11 +102,9 @@ export function generateContext(context?: BuildContext): BuildContext {
107102
const outputCssMapFileName = getConfigValue(context, '--outputCssMapFileName', null, ENV_OUTPUT_CSS_MAP_FILE_NAME, ENV_OUTPUT_CSS_MAP_FILE_NAME.toLowerCase(), 'main.css.map');
108103
setProcessEnvVar(ENV_OUTPUT_CSS_MAP_FILE_NAME, outputCssMapFileName);
109104

110-
const webpackFactoryPath = getConfigValue(context, '--webpackFactoryPath', null, ENV_WEBPACK_FACTORY, ENV_WEBPACK_FACTORY.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'ionic-webpack-factory.js'));
111-
setProcessEnvVar(ENV_WEBPACK_FACTORY, webpackFactoryPath);
105+
setProcessEnvVar(ENV_WEBPACK_FACTORY, join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'ionic-webpack-factory.js'));
112106

113-
const ionicTypescriptLoaderPath = getConfigValue(context, '--ionicTypescriptLoaderPath', null, ENV_WEBPACK_LOADER, ENV_WEBPACK_LOADER.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'typescript-sourcemap-loader-memory.js'));
114-
setProcessEnvVar(ENV_WEBPACK_LOADER, ionicTypescriptLoaderPath);
107+
setProcessEnvVar(ENV_WEBPACK_LOADER, join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'typescript-sourcemap-loader-memory.js'));
115108

116109
if (!isValidBundler(context.bundler)) {
117110
context.bundler = bundlerStrategy(context);
@@ -421,7 +414,6 @@ const WWW_DIR = 'www';
421414
const WWW_INDEX_FILENAME = 'index.html';
422415

423416
const ENV_VAR_ROOT_DIR = 'IONIC_ROOT_DIR';
424-
const ENV_VAR_TMP_DIR = 'IONIC_TMP_DIR';
425417
const ENV_VAR_SRC_DIR = 'IONIC_SRC_DIR';
426418
const ENV_VAR_WWW_DIR = 'IONIC_WWW_DIR';
427419
const ENV_VAR_BUILD_DIR = 'IONIC_BUILD_DIR';

0 commit comments

Comments
 (0)