2016-08-19 54 views
0

我的代碼是:出口是空的,browserify

的src/index.js

const myObject = { 
    name : "Object", 
    fun : function() { 
     console.log('Do some simple stuff'); 
    }, 
    data: "some data" 

}; 

export default myObject; 

與browserify結果很簡單:

(function e(t,n,r){function s(o,u) ... 
"use strict"; 

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

function _classCallCheck(instance, Constructor) ..... 


var myObject = { 
    name: "Object", 
    fun: function fun() { 
     console.log('Do some simple stuff'); 
    }, 
    data: "some data" 

}; 

var X = function X() { 
    _classCallCheck(this, X); 
}; 

exports.default = myObject; 

//export default exposed; 
},{}]},{},[1]); 

在main.js,使用瀏覽爲模塊:

var x = require('./index'); 
console.log(x); // <--- empty object 

必須有一些愚蠢的事我已經錯過:(

回答

2

我猜你正在尋找下列選項:

--standalone -s Generate a UMD bundle for the supplied export name. 
        This bundle works with other module systems and sets the name 
        given as a window global if no module system is found. 

這使得束導入的爲CommonJS的模塊(除其他事項外)。更多信息可以在documentation找到。