c:\tmp\webpack\hello-w-webpack>npm init -y c:\tmp\webpack\hello-w-webpack>npm install --save-dev webpack webpack-cli
{ "name": "hello-w-webpack", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "webpack": "^5.35.0", "webpack-cli": "^4.6.0" } }
[+] hello-wo-webpack |.. [+] src |....... game.js |....... main.js |.. [+] public |....... index.html |....... style.css
let numTimesClicked = 0; function win() { alert('You win!'); reset(); } function reset() { numTimesClicked = 0; } function click() { numTimesClicked++; console.log(`You've been clicked!`); if (numTimesClicked === 3) win(); }
const button = document.getElementById('button'); button.addEventListener('click', function() { click(); });
<!DOCTYPE html> <html lang="en"> <head> <!-- 'defer' should be present, otherwise Uncaught TypeError --> <script src="../src/main.js"></script> <script src="../src/game.js"></script> </head> <body> <button id="button">Click Me!</button> </body> </html>