Conditionally include code in JS payload


#1

Hi,

To simplify development, I would like to use the same code base for the client and administration areas of an applications. In each case, much of the code is shared and the required parts are brought in via an import statement. eg.

if (Meteor.settings.adminApp) {
    import adminStuff from '/imports/adminStuff';
}

That’s OK, however Meteor will still include the entire codebase in the deployed application (obviously).

I’d like it to only include that code if it’s really used (since Meteor.settings.adminApp will always be false on the client-facing server).

Uglify can be told about constants in the application so that it can remove dead code:

Is there anyway to get Isobuild to play along ?

Tim


#2

It’s not legal ES6 code to write conditionnal import, which are top level only.


#3

But it is legal Meteor code: http://info.meteor.com/blog/announcing-meteor-1.3.3.
In any case, I could also do it using a require.