Conditionally include code in JS payload


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 ?


1 Like

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

But it is legal Meteor code:
In any case, I could also do it using a require.