webpack.config.js 964 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Set the `ENV` global variable to be used in the app.
  2. var path = require('path');
  3. var webpack = require('webpack');
  4. var projectRootDir = process.env.IONIC_ROOT_DIR;
  5. var appScriptsDir = process.env.IONIC_APP_SCRIPTS_DIR;
  6. var env = process.env.NODE_ENV || 'dev';
  7. var config = require(path.join(appScriptsDir, 'config', 'webpack.config.js'));
  8. var envVars;
  9. if(process.env.IONIC_ENV === 'prod'){
  10. config = config["prod"];
  11. } else {
  12. config = config["dev"];
  13. }
  14. try {
  15. envVars = require(path.join(projectRootDir,'src', 'environments', env + '.json'));
  16. } catch(e) {
  17. envVars = {};
  18. }
  19. config.plugins = config.plugins || [];
  20. config.plugins.push(
  21. new webpack.DefinePlugin({
  22. ENV: Object.assign(envVars, {
  23. environment: JSON.stringify(env.trim())
  24. })
  25. })
  26. );
  27. if(env === 'prod') {
  28. // This helps ensure the builds are consistent if source hasn't changed:
  29. config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
  30. }
  31. module.exports = config;