The installation
npm install webpack -g
npm install webpack-cli -g
use
Create a new folder named Webpack-Study
With the idea of open
Create a new folder modules
Create a new file hello.js
// Method of exposure
exports.sayhi=function () {
document.write("<h1>hello</h1>");
}
Copy the code
Create a new file main.js
/ / introduction hello. Js
let require1 = require("./hello");
require1.sayhi();
Copy the code
New webpack. Config. Js
module.exports={
// Program entry
entry:"./modules/main.js".output: {// File output address
filename:"./js/bundle.js"}};Copy the code
call
Dist /js/bundle.js is generated when webpack is typed on the terminal
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="./dist/js/bundle.js"></script>
</body>
</html>
Copy the code