These are chat archives for AngularClass/NG6-starter

1st
Mar 2018
Zeeshan Syed
@syedz
Mar 01 2018 03:12
@thematho What's the syntax to check if running in a production environment. Wanted to configure my URLs correctly.
Matias Fernandez Martinez
@thematho
Mar 01 2018 14:39
@syedz Do you mean to make sure that you deployed the correct build on the server, using the browser to check that?
Zeeshan Syed
@syedz
Mar 01 2018 14:56
@thematho basically I want to check if the app is running on the production or staging environment. This will allow me to set my constant variables correctly ( base URLs being one of them). Sorry I should be more clear.
Matias Fernandez Martinez
@thematho
Mar 01 2018 15:14

@syedz for what I know, there is no type of flag on the web app to distinguish between prod or staging, but you can create a script which is only added for production configuration with webpack and adds variables on the client that you need:
on webpack.config.js add app: [] as an entry:

module.exports = {
   devtool: 'source-map',
   entry: { app: [] },
   module: { /* ... */}
}

on gulpfile.bable.js replace:

gulp.task('webpack', ['clean'], (cb) => {
 const config = require('./webpack.dist.config');
 config.entry.app = paths.entry;

For:

gulp.task('webpack', ['clean'], (cb) => {
  const config = require('./webpack.dist.config');
  config.entry.app = paths.entry.concat(config.entry.app);

and Finally replace:

gulp.task('serve', () => {
  const config = require('./webpack.dev.config');
 config.entry.app = [
    'webpack-hot-middleware/client?reload=true',
  ].concat(paths.entry);

For:

gulp.task('browser-sync', () => {
  const config = require('./webpack.dev.config');
  config.entry.app = config.entry.app.concat([
      'webpack-hot-middleware/client?reload=true',
   ], paths.entry);

Now you can add the files on webpack.dist.config.js, overriding the entry.app to add this new file:

/* ... * / 
var config  = require('./webpack.config');
config.entry = {
  app: [
    path.join(__dirname, 'client/app/production.config.js')
  ]
};
config.output = {  /*... */ };
Zeeshan Syed
@syedz
Mar 01 2018 16:37
@thematho Awesome thanks! Will give this a try :)