ES6模块返回空对象

时间:2016-03-19 08:38:54

标签: javascript gruntjs ecmascript-6 babeljs es6-module-loader

Gruntfile.js

browserify:{
    dist:{
        options:{
            transform:[
                ["babelify"]
            ]
        },
        files:{
            "destination":"source"
        }
    }
}

这是用ES6编写的示例文件

var HomeController={
  initHomeController: function(appModule){
       console.log("Method Executing:HomeController.initHomeController");
       appModule.controller('HomeController',['$scope',function($scope){

       }]);

  }
};
export default HomeController

在转发上述文件时,它会缩减为

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var HomeController = {
  initHomeController: function initHomeController(appModule) {
    console.log("Method Executing:HomeController.initHomeController");
    appModule.controller('HomeController', ['$scope', function ($scope) {}]);
  }
};
//var x = HomeController.initHomeController;
//console.log(x);
exports.default = HomeController;

},{}]},{},[1]);

现在我试图在我的主文件中导入HomeController,但HomeController返回一个空对象。 我不知道我在哪里犯了错误。

import HomeController from './es5/controllers/HomeController.js';
  console.log("------",HomeController);
  HomeController.initHomeController(appModule); //initController is method I want to use.

0 个答案:

没有答案