Copy const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
},
watch: true,
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
}
}
Copy {
"name": "abc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --watch",
"start": "webpack-dev-server --port 3000"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
}
}
Copy <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Webpack từ A đến Á cùng kentrung</title>
</head>
<body>
<h1 id="title">Hello Webpack!</h1>
<script src="main.js"></script>
</body>
</html>
Copy const titleElement = document.querySelector('#title');
titleElement.style.color = 'blue';