Install NodeJS
- NodeJS (There is 18.16.0 LTS and Installing 20.3.0 Current)
- Create a folder for the application, eg. examples/demo-app
- Open CMD , cd to the folder of the application cd examples/demo-app
- Create project npm init -y (The -y will make it use the defaults withot prompting for answers)
- Install webpack by running npm install --save-dev webpack webpack-cli
- These will install it in the node_modules folder and it will also create the files package.json and package-lock.json
Edit the package.json and add
"scripts": { "build": "webpack --mode development", "watch": "webpack --mode development --watch" }
Then running
``npm run build``
examples/demo-app/dist/index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Getting Started</title> </head> <body> <script src="./main.js"></script> </body> </html>
examples/demo-app/src/index.js
import add from './mymath'; console.log("hello world"); console.log(add(2, 8));
examples/demo-app/src/mymath.js
export default function add(x, y) { return x + y; }
examples/demo-app/package.json
{ "name": "demo-app", "version": "1.0.0", "description": "", "private": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack --mode development", "watch": "webpack --mode development --watch" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "webpack": "^5.86.0", "webpack-cli": "^5.1.4" } }