go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Installation
 
Subject: Installation
Author: WebSpider
In response to: What's the problem?
Posted on: 04/22/2021 11:31:57 PM

c:\tmp\webpack\hello-w-webpack>npm init -y
c:\tmp\webpack\hello-w-webpack>npm install --save-dev webpack webpack-cli


package.json:
{
  "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"
  }
}


 

> On 04/22/2021 10:42:01 PM WebSpider wrote:

Let's take a look at the dependence problem:
[+] hello-wo-webpack
 |.. [+] src
 |....... game.js
 |....... main.js
 |.. [+] public
 |....... index.html
 |....... style.css


game.js:
 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();
  }


main.js
const button = document.getElementById('button');

button.addEventListener('click', function() {
  click();
});


index.html
<!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>


Here, main.js depends on game.js for click function which is not available -- resulting in Uncaught TypeError.




References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.