简体   繁体   中英

How to install fastclick with ember-cli?

I've got an ember-cli project. I've used bower to install fastclick and have added it to my brocfile.

Now I'm trying to initialise it. In my app.js file I've added:

import FastClick from 'bower_components/fastclick/lib/fastclick';

But this gives me an error in the console: "Uncaught TypeError: Cannot read property 'default' of undefined". The inspector shows the following generated code:

["ember","ember/resolver","ember/load-initializers","bower_components/fastclick/lib/fastclick","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
"use strict";
 var Ember = __dependency1__["default"];
 var Resolver = __dependency2__["default"];
 var loadInitializers = __dependency3__["default"];
 var FastClick = __dependency4__["default"];      # chrome highlights this line

I assume the problem is that fastclick isn't compatible with the ES6 loader that ember-cli uses. I don't have requirejs, so how can I install fastclick into my project? Docs are at https://github.com/ftlabs/fastclick .

I've also tried adding this to index.html, but it doesn't have any effect when I build an iOS app:

  $(function() {
    FastClick.attach(document.body);
  });

With Ember-cli v0.0.42

Install fastclick with bower

bower install fastclick --save

In your Brocfile.js, add the following above module.exports = app.toTree();

app.import('bower_components/fastclick/lib/fastclick.js');

Then in your app.js you can add

var App = Ember.Application.extend({
  ...
  ready: function(){
    FastClick.attach(document.body);
  }
});

You'll also need to add "FastClick":true to your .jshintrc file's predefs, to prevent it from complaining. More info in the docs about Managing Dependencies .

你也可以使用ember-cli-fastclick :)

OK the jquery version didn't work, but putting the following in my index.html file did:

window.addEventListener('load', function() {
    FastClick.attach(document.body);
}, false);

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