从包中访问流星应用的导入目录? [英] Accessing meteor application's imports directory from a package?

查看:154
本文介绍了从包中访问流星应用的导入目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流星应用目录布局:

  imports / 
api /
collections /
我的收件箱$ b

我可以从包文件导出任何东西,并在应用程序中使用它,没关系。但是如何在包中使用import,就像其他方式一样?

  // mypackageMain.js 
if(Meteor.isServer){
require('/imports/api/collections/MyCollectionFile.js');
};

OR

  import'/imports/api/collections/MyCollectionFile.js'; 

我尝试使用路径'../../ imports / api / collections / MyCollectionFile.js',但它根本不起作用。我无法从包中访问此文件。



我在导入和要求中收到以下错误:

  W20160618-23:25:59.486(3)? (STDERR)错误:找不到模块'../../imports/api/collections/MyCollectionFile.js'
W20160618-23:25:59.487(3)? (STDERR)at require(packages / modules-runtime / .npm / package / node_modules / install / install.js:85:1)


解决方案

认为这是不可能的。



然而,将集合移动到包和导出它们将使集合可用于其他包和应用程序。


Meteor application directory layout:

imports/
  api/
    collections/
      MyCollectionFile.js

packages/
  mypackage/
      mypackageMain.js

I can export anything from the package file and use it inside the application, that's ok. But how can I use "import" in the package, like the other way around?

// mypackageMain.js
if (Meteor.isServer) {
    require ('/imports/api/collections/MyCollectionFile.js');
};

OR

import '/imports/api/collections/MyCollectionFile.js';

I tried using the path '../../imports/api/collections/MyCollectionFile.js' but it simply does not work. I can not access this file from a package.

I get the following Error for both the import and the require:

W20160618-23:25:59.486(3)? (STDERR) Error: Cannot find module '../../imports/api/collections/MyCollectionFile.js'
W20160618-23:25:59.487(3)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:85:1)

解决方案

Figured out that this was not possible.

However, moving the collections to a package and exporting them would make the collections available to other packages and the application.

这篇关于从包中访问流星应用的导入目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆