简体   繁体   中英

Ember-cli get relative path of a dependency

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

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"
                });

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.

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 ?

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

Thanks.

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.

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

  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.

  2. Use the broccoli-funnel and broccoli-merge-trees plugin.

Use npm to install both the packages.

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

In you 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]);

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.

Now the util file should be accessible to ur plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM