Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help on generating environment specific api config #11

Closed
hussaintamboli opened this issue Nov 2, 2016 · 3 comments
Closed

Need help on generating environment specific api config #11

hussaintamboli opened this issue Nov 2, 2016 · 3 comments
Labels

Comments

@hussaintamboli
Copy link

Hey, I have been using generator-angular-webpack-es6 for a week now.

I really like how it's structured in a context of separation of concerns.

I have one problem. My api.config.json

{
    "production": {
        "APIConfig": {
            "ProductService": "jjjjjjjjj",
            "CartService": "kkkkkkk"
        }
    },
    "development": {
        "APIConfig": {
            "ProductService": "lllllllll",
            "CartService": "mmmmm"
        }
    }
}

I want webpack to create angular config for the enviornment specific build.

In gulp I had a task for this

gulp.task('configure-environment', configure);
function configure() {
  return gulp.src('conf/app.env.config.json')
    .pipe(gulpNgConfig('MyMD.config', {
      environment: process.env.NODE_ENV || "development"
    }))
    .pipe(gulp.dest(path.join(conf.paths.src)));
}

How do I do this with Webpack?

@STUkh
Copy link
Owner

STUkh commented Nov 3, 2016

How do I do this with Webpack?

Try webpack.DefinePlugin plugin. There is simple example in global.json webpack config file

@STUkh STUkh added the question label Nov 3, 2016
@hussaintamboli
Copy link
Author

Fixed

new webpack.DefinePlugin({
    'NODE_ENV': JSON.stringify(NODE_ENV),
    'API_CONFIG': JSON.stringify(require(path.join(_path, 'config/apiurls.json'))[NODE_ENV])
})

Thanks!

@basav22
Copy link

basav22 commented Feb 21, 2017

Hi,

One more way - Using Alias like

 `alias: {
    ////////////////////////////////////////////////////////////////
    // Created alias for environment specific configuration for APIs
    ////////////////////////////////////////////////////////////////
    _envConfig: path.join(_path, 'config', 'apis', NODE_ENV)
 }`

Create different modules based on environment like development.js, production.js. And these modules will return config object. This way build will fail if we don't set NODE_ENV to correct value.

Then
import * as envConfig from '_envConfig'; console.log(envConfig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants