Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor - How to Use a Package in Dev or Production Only

In Meteor, is there a way to specify a package to be used in the development environment only, or the production environment only? When I add packages via astmospherejs.com, they all get lumped into the .meteor/packages file sorted chronologically by time added. Essentially, I'm looking for what would be a ruby Gemfile, where you can specify different environments. Thanks!

like image 231
Jon Cursi Avatar asked Mar 21 '15 23:03

Jon Cursi


People also ask

How do I use Meteor packages?

To use an Atmosphere Package in your app you can import it with the meteor/ prefix: import { Mongo } from "meteor/mongo"; Typically a package will export one or more symbols, which you'll need to reference with the destructuring syntax. You can find these exported symbols by either looking in that package's package.

What is Meteor NPM?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.


2 Answers

Here's a little trick I've been using to run a package in development only:

  1. from your app root, create a blank package (or add to your PACKAGE_DIRS directory): meteor create --package my-package-manager

  2. In package.js:

    Package.on_use(function(api) {
      // production only
      if (process.env.IS_PRODUCTION) {
        api.use('some:package');
      }
      // dev only
      if (process.env.IS_DEVELOPMENT) {
        api.use('devonly:package');
      }
    });
    
  3. On dev environment: echo "export IS_DEVELOPMENT=true" >> ~/.bash_profile (or ~/.zshrc in my case)

  4. Then obviously do the same thing for IS_PRODUCTION on whatever you use for production server. on heroku for example: heroku config:set IS_PRODUCTION=true

I'm using this for a dev-only package, haven't tried it with production-only but it should work.

like image 172
Cooper Maruyama Avatar answered Nov 09 '22 19:11

Cooper Maruyama


From meteor version 1.3.2, you can simply put the flag prodOnly or debugOnly.

More info here

like image 1
Feki Zied Avatar answered Nov 09 '22 17:11

Feki Zied