最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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, 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!

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., 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!

Share Improve this question asked Mar 21, 2015 at 23:26 Jon CursiJon Cursi 3,3814 gold badges28 silver badges53 bronze badges 2
  • 3 Well, in the Package.describe callback (package.js file) you can set debugOnly: true in order to not deploy the package when using meteor deploy, for example to use a collection populating code you don't want to use in prod. Hope it will help! – Kyll Commented Mar 22, 2015 at 10:45
  • Useful. Unfortunately, this is not yet documented. I'm looking for a "productionOnly" but that doesn't seem to exist. – foobarbecue Commented Apr 16, 2015 at 15:04
Add a ment  | 

2 Answers 2

Reset to default 7

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.

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

More info here

发布评论

评论列表(0)

  1. 暂无评论