2

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.
4

0 回答 0