Exclude development code from build

Certain features in my Meteor app have more than one solutions/implementations for evaluation purpose. All these implementations are supposed to be available in development mode (one to be selected at a time from the UI), but only one of the alternative solutions for a specific feature should be included in the production build (because we also have a need to minimize the size of the app bundle).

So far, I’ve got it work out for the availability of solutions in development or production mode:

In client side:

<template name="template_A">
  {{#if development}}
    <!-- All solutions available -->
  {{else}}
    <!-- A selected solution for production available -->
  {{/if}}
</template>

In server side:

if ( Meteor.isDevelopment) {
  /* Relevant code */
} else {
  /* Relevant code */
}

But I believe all the only-development-relevant code still go to the production app bundle. Is there a way to exclude them from production build?

Hi,

I would use source control to manage this, by using feature branches, instead of putting development / evaluation code in the production branch. That’s what git is very good at!

1 Like

git has been already there for versioning features of the app. But the components I want to exclude from my production build have less to do with versioning. For example: I have some data source that get improved overtime and has been under version control; I want to display this data source using 3 different charts libraries; which chart to be used is selected by a drop-down button which should only be displayed in development mode; in production mode, only one chart library is used and is the only one that should go in the app bundle.

I hope there is some special feature of Meteor that allows build to exclude development code just like it can do with tests?

If you use packages to build your project you can also specify debugonly and that code won’t go into production builds

1 Like

Another way could be by running Meteor in test --full-app mode: Only in this mode are *.app-test[s].* files included. When you run on normal dev-mode, or build for production, there are not included.

e.g., a file my-feature.app-test.js is only loaded when started with meteor test --full-app

https://guide.meteor.com/1.3-migration.html#full-app-testing

1 Like