使用webpack

时间:2016-06-06 06:00:51

标签: javascript webpack

如何使用像这样的webpack从不同的js文件调用函数?

module1.js:

require('./module2.js');
var myObject = {};
myObject.doSomething = function(){
    //some task
    actions.activity();
};

module2.js:

var actions = {};
actions.activity = function(){
    document.getElementsByTagName('p').innerHTML = "Loaded by webpack!"
};
module.exports = actions;

的index.html:

<button onclick="myObject.doSomething();">Click here</button>
<p></p>
<script type="text/javascript" src = 'bin/bundle.js'></script>

webpack.config.js:

module.exports = {
    entry: './src/module1.js',
    output: {
        path: './bin',
        filename: 'bundle.js'
    }
}

运行webpack命令后,它会抛出错误,我无法生成bundle.js

0 个答案:

没有答案