Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
  });
like image 828
jbrown Avatar asked Sep 17 '14 11:09

jbrown


2 Answers

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.

like image 100
RYFN Avatar answered Nov 09 '22 07:11

RYFN


You can also use ember-cli-fastclick :)

like image 22
Amiel Martin Avatar answered Nov 09 '22 06:11

Amiel Martin