I have a basic HTML page with a button:
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
<button id="button" onclick="uclicked()">Click me</button>
<script src="./bundle.js"></script>
</body>
</html>
and an app.js
:
//(function(){
console.log('started up')
function uclicked(){
console.log('You clicked');
}
//})();
webpack is installed and webpack --watch
succeeds. The webpack.config.js is:
module.exports={
entry: './app.js',
output: {
path: __dirname,
filename: 'bundle.js'
}
}
When I load the page console.log
is working but when I push the button I get Uncaught ReferenceError: uclicked is not defined
.
If I replace <script src="./bundle.js"></script>
with <script src="./app.js"></script>
and bypass webpack the button clicks fine. Why doesn't this basic webpack setup work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…