webpack 4简单创建vue 自用

pakge.json配置:

   

{
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^3.4.2",
    "ts-loader": "^6.2.2",
    "typescript": "^3.8.3",
    "vue-loader": "^15.9.1",
    "vue-style-loader": "^4.1.2",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^4.42.1",
    "webpack-cli": "^3.3.11"
  },
  "dependencies": {
    "vue": "^2.6.11"
  }
}

webpack.config.js 配置

const vlp = require('vue-loader/lib/plugin')
module.exports =  {
  mode:'development',
  entry:{
    index:'./src/index.js'
  },
  output:{
    filename:'index.js',
    path:__dirname + '/dist'
  },
  module:{
    rules:[
      {
        test:/\.vue$/,
        loader:'vue-loader'
      },
      {
        test:/\.css$/,
        use:[
          'vue-style-loader',
          'css-loader'
        ]
      }
    ]
  },
  plugins:[
    new vlp()
  ]
}

 

webpack.config.js同级新建src 目录,src下新建index.js(webpack.entry) 

写入

import Vue from 'vue'
import app from './pages/app.vue'


new Vue({
  el:'#app',
  render:h=> h(app)
})

src目录下新建pages/app.vue 

随便写点vue代码

<template>
    <div>
      asdasdas
    </div>
</template>

<script>
export default {
    name:'',
    data() {
        return {

        };
    },
    created() {

    },
    mounted() {

    },
    methods: {

    }
};
</script>

<style scoped >

</style>

 

webpack.config.js同级写一个html文件 ,写入

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
</head>
<body>
  <div id="app"></div>
  <script src="./dist/index.js"></script>
</body>
</html>

最后,运行 npx webpack 进行打包编译,编译好后打开index.html

如图所示

 

本教程只适用于 j教程里面所用版本的vue和webpack和各种loader,版本可以前后有一点更新或落后但是差太多可能会出问题,(落后就该挨打)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值