Created
March 7, 2019 23:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"paths": { | |
"@src/*": ["./*"], | |
"@app/*": ["./app/*"], | |
"@pages/*": ["./pages/*"], | |
"@env": [ "environments/environment" ] | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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