Getting Started
Basic zero-conf Webpack 4
Create your project directory and cd into it. mkdir webpack-express-demo && cd webpack-express-demo
- Initialize the folder
yarn init
- Then get webpack and webpack-cli
yarn add webpack && yarn add webpack-cli -D
- Create a
distdirectory and addindex.htmlfile to itmkdir dist && touch dist/index.html
dist/index.html
<!DOCTYPE html>
<html>
<head>
<title>Webpack Express Demo</title>
</head>
<body>
<script src="main.js"></script>
</body>
</html>
Create src directory and add index.js inside
mkdir src && touch src/index.js
src/index.jsvar title = document.createElement('div') title.innerText = "Hello Webpack!" document.body.appendChild(title)Now edit your package.json file, adding build script
package.json
{
"name": "webpack-express-demo",
"version": "1.0.0",
"main": "index.js",
"author": "Unicorn Kitty",
"license": "MIT",
"scripts": {
"build": "webpack"
},
"dependencies": {
"webpack": "^4.1.1"
},
"devDependencies": {
"webpack-cli": "^2.0.12"
}
}
Last run
npm run build. You will get a warning about modes but we will fix this later.npm run buildThen open yourindex.htmlfile in your browser and you will see Hello Webpack!