Skip to content

Instantly share code, notes, and snippets.

@ptesser
Created March 7, 2019 23:14
Show Gist options
  • Save ptesser/edf1e287a5fa72281fcf559e04a0a85f to your computer and use it in GitHub Desktop.
Save ptesser/edf1e287a5fa72281fcf559e04a0a85f to your computer and use it in GitHub Desktop.
Configure @alias in Ionic 3 with TypeScript. This is done also to configure environments.
{
"compilerOptions": {
"paths": {
"@src/*": ["./*"],
"@app/*": ["./app/*"],
"@pages/*": ["./pages/*"],
"@env": [ "environments/environment" ]
}
},
var chalk = require("chalk");
const path = require('path');
const useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');
const fs = require('fs');
const env = process.env.IONIC_ENV;
console.log('ENV is set to', env);
useDefaultConfig[env].resolve.alias = {
"@src": path.resolve('./src/'),
"@app": path.resolve('./src/app/'),
"@pages": path.resolve('./src/pages/'),
"@env": path.resolve(environmentPath(env))
};
if (env !== 'prod' && env !== 'dev') {
// Default to dev config
useDefaultConfig[env].resolve.alias = {
"@src": path.resolve('./src/'),
"@app": path.resolve('./src/app/'),
"@pages": path.resolve('./src/pages/'),
"@env": path.resolve(environmentPath(env))
};
}
function environmentPath(env) {
var filePath = './src/environments/environment' + (env === 'prod' ? `.${env}` : '') + '.ts';
if (!fs.existsSync(filePath)) {
console.log(chalk.red('\n' + filePath + ' does not exist!'));
} else {
return filePath;
}
}
module.exports = function() {
return useDefaultConfig;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment