我打算用webpack捆绑所有的.js.我试着用一个非常简单的例子如下.
要在test.js文件中捆绑的函数:
function test() {
console.log('hello');
}
Run Code Online (Sandbox Code Playgroud)
Webpack配置:
module.exports = [{
{
output: {
filename: 'test.js',
path: __dirname + '/public/javascript/dist'
},
entry: [
'./public/javascript/test.js'
]
}
]
Run Code Online (Sandbox Code Playgroud)
要测试的代码:
<html>
<head></head>
<body>
<script src="./javascript/dist/test.js"></script>
<script type="text/javascript">
window.onload = function()
{
test();
}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:未捕获的ReferenceError:未定义测试.
问题:为什么?
[编辑]回复是:"导出"丢失.多亏了这一点,我更新如下:
出口代码:
export function Test() {
this.t = 1;
Test.prototype.toto = function()
{
console.log('hello')
}
}
Run Code Online (Sandbox Code Playgroud)
Webpack conf:
{
output: {
filename: 'test.js',
path: __dirname + '/public/javascript/dist',
library: 'test',
libraryTarget: 'window'
},
entry: [
'./public/javascript/poc/test.js' …Run Code Online (Sandbox Code Playgroud)