在启动Meteor.js时自动加载settings.json

时间:2021-11-20 17:35:07

Rather than starting Meteor with the flag --settings settings.json

而不是用标志--settings settings.json启动Meteor

mrt --settings settings.json

Is it possible to define Meteor.Settings automatically on startup by just running

是否可以通过运行在启动时自动定义Meteor.Settings

mrt

3 个解决方案

#1


11  

Nowadays the command should be meteor (no more mrt):

现在命令应该是流星(不再是mrt):

meteor --settings settings.json

To automatically load settings file, I like the method suggested on "The Meteor Chef" that exploits npm:

要自动加载设置文件,我喜欢利用npm的“The Meteor Chef”建议的方法:

Creating a file package.json in the project root:

在项目根目录中创建文件package.json:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "meteor --settings settings.json"
  }
}

We can start meteor with:

我们可以用以下方法启动流星:

npm start

DEV/PROD

DEV / PROD

Also it is possible to have two or more scripts for two or more settings:

此外,可以为两个或更多设置提供两个或更多脚本:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "meteor:dev": "meteor --settings settings-dev.json",
    "meteor:prod": "meteor --settings settings-prod.json"
  }
}

Then:

然后:

npm run meteor:dev

or

要么

npm run meteor:prod

(note that here we have to add the run command, not required with the "special" script start)

(注意,这里我们要添加run命令,不需要“特殊”脚本启动)

#2


7  

For dev, use an alias

对于dev,请使用别名

alias mrt='mrt --settings settings.json'

or

要么

alias mrts='mrt --settings settings.json'

remove it with unalias mrts

用unalias mrts删除它

When you want it to be permanent, put it in ~/.bashrc or ~/.bash_profile

当你想要它是永久的时,把它放在〜/ .bashrc或〜/ .bash_profile中

Alternatively, meteor accepts an environment variable (useful for production)

或者,meteor接受环境变量(对生产有用)

METEOR_SETTINGS = `cat path/to/settings.json`
export METEOR_SETTINGS

#3


4  

If you don't want to fiddle with aliases, you could create a bash script in the root directory of a specific project, like so:

如果您不想使用别名,可以在特定项目的根目录中创建一个bash脚本,如下所示:

dev.sh:

dev.sh:

#!/bin/bash
meteor --settings ./config/development/settings.json

And just run it from the meteor project directory with:

然后从流星项目目录中运行它:

./dev.sh

If you get -bash: ./dev.sh: Permission denied just do:

如果你得到-bash:./ dev.sh:Permission denied只做:

chmod +x ./dev.sh

If you use other services you could start them before meteor like so:

如果您使用其他服务,您可以在流星之前启动它们,如下所示:

#!/bin/bash
sudo service elasticsearch start
meteor --settings ./config/development/settings.json

#1


11  

Nowadays the command should be meteor (no more mrt):

现在命令应该是流星(不再是mrt):

meteor --settings settings.json

To automatically load settings file, I like the method suggested on "The Meteor Chef" that exploits npm:

要自动加载设置文件,我喜欢利用npm的“The Meteor Chef”建议的方法:

Creating a file package.json in the project root:

在项目根目录中创建文件package.json:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "meteor --settings settings.json"
  }
}

We can start meteor with:

我们可以用以下方法启动流星:

npm start

DEV/PROD

DEV / PROD

Also it is possible to have two or more scripts for two or more settings:

此外,可以为两个或更多设置提供两个或更多脚本:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "meteor:dev": "meteor --settings settings-dev.json",
    "meteor:prod": "meteor --settings settings-prod.json"
  }
}

Then:

然后:

npm run meteor:dev

or

要么

npm run meteor:prod

(note that here we have to add the run command, not required with the "special" script start)

(注意,这里我们要添加run命令,不需要“特殊”脚本启动)

#2


7  

For dev, use an alias

对于dev,请使用别名

alias mrt='mrt --settings settings.json'

or

要么

alias mrts='mrt --settings settings.json'

remove it with unalias mrts

用unalias mrts删除它

When you want it to be permanent, put it in ~/.bashrc or ~/.bash_profile

当你想要它是永久的时,把它放在〜/ .bashrc或〜/ .bash_profile中

Alternatively, meteor accepts an environment variable (useful for production)

或者,meteor接受环境变量(对生产有用)

METEOR_SETTINGS = `cat path/to/settings.json`
export METEOR_SETTINGS

#3


4  

If you don't want to fiddle with aliases, you could create a bash script in the root directory of a specific project, like so:

如果您不想使用别名,可以在特定项目的根目录中创建一个bash脚本,如下所示:

dev.sh:

dev.sh:

#!/bin/bash
meteor --settings ./config/development/settings.json

And just run it from the meteor project directory with:

然后从流星项目目录中运行它:

./dev.sh

If you get -bash: ./dev.sh: Permission denied just do:

如果你得到-bash:./ dev.sh:Permission denied只做:

chmod +x ./dev.sh

If you use other services you could start them before meteor like so:

如果您使用其他服务,您可以在流星之前启动它们,如下所示:

#!/bin/bash
sudo service elasticsearch start
meteor --settings ./config/development/settings.json