mardi 29 décembre 2015

Using moment.js with Ember, Ember-CLI

I have been trying to get the moment.js library to work with an Ember application using the Ember-cli. Note I am fairly new to ES2015.

Ember 2.2.0 Ember-cli 1.13.13

my ember-cli-build

/*jshint node:true*/
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
    var app = new EmberApp(defaults, {
        //options
    });

    app.import('bower_components/moment/moment.js');

    return app.toTree();
};

and my .jshintrc

"predef": [
    "document",
    "window",
    "-Promise",
      "moment"
  ],

and my controller

/* global moment:true */
import Ember from 'ember';

export default Ember.Controller.extend({
    firstName: null,
    lastName: null,
    day: function () {
        return moment('Dec 25, 1995');
    }.property()
});

I always get an error that 'moment' has not been defined. I read that the latest moment.js has stopped producing a global 'moment' but I'm not sure what to do about it.

The builds work. If I pull up the generated vendor.js I can see the complete contents of the moment.js file in it. However when I look at vendor.js in the chrome debugger the contents are omitted. I wasn't sure if this was due to some optimization.




Aucun commentaire:

Enregistrer un commentaire