Skip to content

Get rid of require() in vendor.ts #236

Closed

Description

@antonmoiseev

Currently vendor.ts uses require() to import the enableProdMode function from angular2/core:

if ('production' === process.env.ENV) {
  let ngCore = require('angular2/core');
  ngCore.enableProdMode();
}

Can we combine the function import together with the ES6 import statement below in the file?

//...
import 'angular2/http';
import {enableProdMode} 'angular2/core';

if ('production' === process.env.ENV) {
  enableProdMode();
}

My understanding is that all required objects from angular2/core still will be bundled since the application code explicitly imports everything it needs. However I lack the knowledge of Webpack's bundling process and concerned that some of the objects from angular2/core can leak into the bundle.js file instead of being in vendor.bundle.js.

I did a quick experiment it seems that everything is fine, works as intended, but maybe I'm missing a common case when it won't work. What do you think?

Activity

  1. PatrickJS commented on Jan 20, 2016

    @PatrickJS
    Owner

    this works but I was trying to be more consistent showing that modules where we want to toggle features per enviroment should use require

  2. antonmoiseev commented on Jan 20, 2016

    @antonmoiseev
    ContributorAuthor

    I see. Frankly I'd rather do not mix different module format styles in an app unless there is no way to avoid require(). But please feel free to close the issue if you are not looking into changing this.

  3. PatrickJS commented on Jan 25, 2016

    @PatrickJS
    Owner

    we still have to mix import and require :/ even with webpack2. I'm mixing both to stay consistent in case the devloper deletes the if statement the core will still remained bundled correctly. We also have a problem with typescript not supporting other than TS modules see microsoft/TypeScript#2709 I'm going to close this issue but if you have anymore questions feel free to open an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions