Ver código fonte

配置webpack.config.js中的mode、entry和output

machen 1 ano atrás
pai
commit
79d33948ad

+ 1 - 5
.gitignore

@@ -1,5 +1 @@
-# 忽略所有同学的node_modules
-**/node_modules/
-# Editor directories and files
-.idea
-.vscode
+ChenMa/node_modules/

+ 1 - 0
ChenMa/dist/hello1-358-4e84e9edc1f7fcb2826a.js

@@ -0,0 +1 @@
+(()=>{"use strict";sayHello()})();

+ 1 - 0
ChenMa/dist/hello2-367-4e84e9edc1f7fcb2826a.js

@@ -0,0 +1 @@
+(()=>{"use strict";sayHello()})();

+ 0 - 11
ChenMa/dist/index.html

@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-  <meta charset="UTF-8">
-  <meta name="viewport" content="width=device-width, initial-scale=1.0">
-  <title>Document</title>
-</head>
-<body>
-  <script defer src="./main.js"></script>
-</body>
-</html>

+ 0 - 1
ChenMa/dist/main.js

@@ -1 +0,0 @@
-(()=>{"use strict";const e={sayHello(){document.body.insertAdjacentHTML("beforeend","<h1>今天天气异常得好</h1>")}};({sayHello(){console.log("hello")}}).sayHello(),e.sayHello()})();

+ 1 - 0
ChenMa/hello/file5.js

@@ -0,0 +1 @@
+(()=>{"use strict";sayHello(),sayHello()})();

+ 3 - 0
ChenMa/package.json

@@ -6,5 +6,8 @@
   "devDependencies": {
     "webpack": "^5.89.0",
     "webpack-cli": "^5.1.4"
+  },
+  "scripts": {
+    "build": "webpack"
   }
 }

+ 2 - 1
ChenMa/src/a1.js

@@ -2,4 +2,5 @@ export default({
   sayHello() {
     console.log('hello')
   }
-})
+})
+sayHello()

+ 2 - 1
ChenMa/src/a2.js

@@ -2,4 +2,5 @@ export default({
   sayHello() {
     document.body.insertAdjacentHTML('beforeend', '<h1>今天天气异常得好</h1>')
   }
-})
+})
+sayHello()

+ 1 - 0
ChenMa/src/aaa.js

@@ -0,0 +1 @@
+console.log('hello aaa')

+ 18 - 0
ChenMa/webpack.config.js

@@ -0,0 +1,18 @@
+const path = require('path')
+module.exports = {
+  mode: 'production',
+  // entry: [
+  //   './src/a1.js',
+  //   './src/a2.js'
+  // ],
+  entry: {
+    hello1: './src/a1.js',
+    hello2: './src/a2.js'
+  },
+  output: {
+    filename: '[name]-[id]-[hash].js',
+    // filename: 'file5.js',
+    clean: true,
+    // path: path.resolve(__dirname, 'hello')
+  }
+}