Ember-cli获取依赖关系的相对路径 [英] Ember-cli get relative path of a dependency

查看:112
本文介绍了Ember-cli获取依赖关系的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个独特的问题,我无法离开,因为Ember与依赖关系如何工作。
我正在使用此lib检查电话号码: https:/ /github.com/Bluefieldscom/intl-tel-input/#utilities-script

I have a unique issue that I can't get out because of how ember works with the dependencies. I am using this lib to check a phone number : https://github.com/Bluefieldscom/intl-tel-input/#utilities-script

它工作正常,直到我必须设置相对路径的文件调用util.js这样做,使一些选项工作:

And it's working fine, until that I have to set the relative path of a file call util.js like this to make some options works:

 $phoneInput.intlTelInput({
                    allowExtensions: false,
                    autoFormat: true,
                    autoHideDialCode: false,
                    nationalMode: false,
                    utilsScript: "/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"
                });

正如你所看到的,我试图使用 / bower_components / intl-tel-输入/ lib / libphonenumber / build / utils.js 但是找不到它。我还试图添加 assets / ../ bower _... ,但没有任何工作,我我不知道这是不可能的。

As you can see I tried to use /bower_components/intl-tel-input/lib/libphonenumber/build/utils.js but it can't find it. I also tried to add assets/ or ../bower_... but nothing is working, and I'm afraid this is not possible.

我在Brocfile.js中导入了该文件:

I did import the file in my Brocfile.js :

app.import('bower_components / intl-tel-input / lib / libphonenumber / build / utils.js');

我可以在源代码中完美地看到它。

And I can see it perfectly in the source.

有没有办法知道依赖关系的相对路径?

Is there is a way to know the relative path of a dependency ?

我忘了确定我正在从 didInsertElement 中的视图初始化intlTelInput。

I forgot to precise that I am initializing intlTelInput from a view within didInsertElement.

谢谢。

推荐答案

根据我的理解,您无法引用util文件,因为它不会被复制到dev服务器提供的dist文件夹中。

From what I understand you aren't able to refer the util file because it is not getting copied into the dist folder which the dev server serves.

有两种方法可以将文件复制到dist文件夹中。

There are 2 ways to get the file copied into the dist folder.


  1. util.js 放入 public 文件夹。公用文件夹的内容将原样复制到 dist 文件夹中。然后,您应该能够以相同的方式引用图像或字体。

  1. Put the util.js into the public folder. The contents of the public folder are copied as it is into the dist folder. Then you should be able to refer it's path the same way you refer images or fonts.

使用西兰花渠 broccoli-merge-trees 插件。

使用npm安装这两个软件包。

Use npm to install both the packages.

npm install --save-dev broccoli-funnel
npm install --save-dev broccoli-merge-trees 

在你 Brocfile.js

var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var app = new EmberApp();

var funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');

var utilFile = funnel('vendor', {
  srcDir: 'intl-tel-input-master/lib/libphonenumber/build',
  destDir: 'lib/intl-tel-input-master'
});

//module.exports = app.toTree();
module.exports = mergeTrees([app.toTree(), utilFile]);

我已将手机库复制到我的供应商文件夹。所以我使用西兰花漏斗来选择util.js文件和broccoli-merge-trees将文件复制到dist文件夹中。

I have copied the phone library into my vendor folder. So I am using broccoli-funnel to select the util.js file and broccoli-merge-trees to copy the file into the dist folder.

现在,这个util文件应该是可以访问你的插件。

Now the util file should be accessible to ur plugin.

这篇关于Ember-cli获取依赖关系的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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