tianyunperfect 3 年之前
父節點
當前提交
68ceab80dd
共有 5 個文件被更改,包括 40 次插入3 次删除
  1. 4 0
      package.json
  2. 6 1
      src/index.js
  3. 1 0
      src/public/index.html
  4. 21 0
      src/vue/App.vue
  5. 8 2
      webpack.config.js

+ 4 - 0
package.json

@@ -14,6 +14,10 @@
     "html-webpack-plugin": "^5.5.0",
     "style-loader": "^3.3.1",
     "url-loader": "^4.1.1",
+    "vue": "^2.6.14",
+    "vue-loader": "^15.9.8",
+    "vue-style-loader": "^4.1.3",
+    "vue-template-compiler": "^2.6.14",
     "webpack": "^5.64.0",
     "webpack-cli": "^4.9.1",
     "webpack-dev-server": "^4.5.0"

+ 6 - 1
src/index.js

@@ -1 +1,6 @@
-console.log(123);
+import Vue from 'vue';
+import App from './vue/App.vue';
+
+new Vue({
+    render: h => h(App)
+}).$mount("#root")

+ 1 - 0
src/public/index.html

@@ -5,5 +5,6 @@
     <title>Title</title>
 </head>
 <body>
+<div id="root"></div>
 </body>
 </html>

+ 21 - 0
src/vue/App.vue

@@ -0,0 +1,21 @@
+<template>
+  <div>
+    <p class="root">{{ text }}</p>
+  </div>
+</template>
+
+<script>
+export default {
+  data() {
+    return {
+      text: " I am a vue"
+    }
+  }
+}
+</script>
+
+<style scoped>
+.root {
+  color: red;
+}
+</style>

+ 8 - 2
webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const HtmlWebpackPlugin = require("html-webpack-plugin");
 const {CleanWebpackPlugin} = require("clean-webpack-plugin");
+const VueLoaderPlugin = require("vue-loader/lib/plugin");
 
 const config = {
     mode: 'development',
@@ -16,10 +17,15 @@ const config = {
             template: path.resolve(__dirname, './src/public/index.html')
         }),
         // 清除 dist 的插件
-        new CleanWebpackPlugin()
+        new CleanWebpackPlugin(),
+        new VueLoaderPlugin()
     ],
     module: {
         rules: [
+            {
+                test: /\.vue$/,
+                use: ['vue-loader']
+            },
             // 转为 es5 语法,兼容更多浏览器
             {
                 test: /\.js$/,
@@ -36,7 +42,7 @@ const config = {
             // css 打包
             {
                 test: /\.css$/,
-                use: ['style-loader', 'css-loader']
+                use: ['vue-style-loader', 'css-loader']
             },
             // 设置 limit,如果超过限制,使用 file-loader 打包
             {