Meteor 1.3: can I import from the meteor shell?

≡放荡痞女 提交于 2019-12-23 19:43:19

问题


I have a file like this.

const device = new Device({
  host: process.env.GALIL_HOST,
  port parseInt(process.env.GALIL_PORT, 10)
});

export default device;

However, I cannot find a way to access this in the shell, other than to expose it as a global variable.

Is there any way to import from the meteor shell?


回答1:


It is possible to import certain symbols from the shell, depending on your Meteor version.


require() - client and server, Meteor v1.3+

As of Meteor v.1.3-beta.12, it is possible to require files from the shell.

Given a file in a source directory other than client (i.e, something that should be available on the server), with the path

my/file/path/the_file.js

You can get an object that contains your exports using

require('./my/file/path/the_file.js');

(note the ./ prefix).

or, for packages:

require("meteor/my-package");

In the browser, you can require files and packages, for example:

const { Match, check } = require('meteor/check');

import statements - server, Meteor v1.3.3+

Starting with Meteor v1.3.3, it is possible to use import statements from the Meteor shell on the server:

import { Match, check } from 'meteor/check';


来源:https://stackoverflow.com/questions/35754852/meteor-1-3-can-i-import-from-the-meteor-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!