Ignore File In Development

Is there some way to have meteor ignore a file only in development.

ie. My SSR file.

Right now I’m unable to get client only refresh on development without commenting out my ssr import.

I’ve tried

if (isProduction) {
require('./ssr-init')
}

but it still breaks client only refresh on development.

This becomes a big bummer once you are coordinating deploys.

Was searching this same topic today, but for NOT loading things in production vs development. Found the following type of approach, here is an example of what I think you are shooting for :+1:

if(process.env.NODE_ENV != 'production'){
  require('./ssr-init')
}

When I run process.env.NODE_ENV in the console on my local machine I get development and when I run it on a deployed Galaxy instance I get production

I’m guessing this is the variable that is set by Meteor, but I’ve not really investigated where/when it gets set.

I assume you set isProduction as a variable just not show in your code snippet:

var isProduction = Meteor.isProduction;

if (isProduction) {
require('./ssr-init')
}

When I run Meteor.isProduction on my local machine and then on my Galaxy deployed app, I get false and true as I would expect. I’m not sure why that wouldn’t work for you.

No doubt you’ll get it working :sunglasses:

1 Like

I should have been more clear initially, but yeah I do have isProduction set above. The issue is that this still breaks client only refresh. It works limiting ssr to dev, but Meteor still registers UI changes as server changes.

You could create a meteor package and set https://docs.meteor.com/api/packagejs.html#PackageNamespace-describe prodOnly to true.

1 Like

Hi @stolinski,

We found the same limitation for our projects. We ended creating pre-deploy and post-deploy scripts that comment and un comment those lines, so that we get faster dev speed’s by not including some shared files on the server.

We use sed for that.

Hope this helps.

2 Likes

This sounds super promising.

I like this idea, but you would have to find a way for inputs into the package, like the path to your UI files and Apollo client config.

I’ve written a prebuild package once for a similar purpose. Prebuild allows custom scripts to run before the real build phase starts.

Currently, I use it to compile and minify my service worker.

1 Like

Oh a prebuild is a nice idea. I ended up throwing in a sed replacement into a Github action and it worked wonderfully.

1 Like