Vue-loader+webpack项目配置

1、新建文件夹
在这里插入图片描述
2、命令行输入

  1. npm init
  2. npm i webpack vue vue-loader
  3. npm i css-loader style-loader vue-template-compiler

3、新建src文件夹 源码放置目录 >app.vue

app.vue

<template>
    <div id="test">{{text}}</div>
</template>
<script>
export default {
    data(){
        return {
            text:'abc'
        }
    }
}
</script>
<style>
#test{
    color: red;
}
</style>

index.js

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

const root = document.createElement('div')
document.body.appendChild(root)

new Vue({
    // h是generate api參數
    render:(h)=>h(App)
}).$mount(root)

4、 新建webpack.config.js

const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    // 打包前端资源 (js css img font) 通過http請求加載 渲染
    // 入口文件 path.join 路徑拼接成絕對路徑
    entry:path.join(__dirname,'src/index.js'),
    // 出口文件
    output:{
        filename:'bundle.js',
        path:path.join(__dirname,'dist')
    },
    plugins: [
        // make sure to include the plugin for the magic
        new VueLoaderPlugin()
    ],
    module:{
        rules:[
            {
                // 使用vue-loader為webpack輸出.vue的文件類型
                test:/.vue$/,
                loader:'vue-loader'
            },{
                test:/.css$/,
                use:['style-loader','css-loader']
            }
        ]
    }
}

5、 在package.json写脚本
如果不配置webpack的话,它将会找到全局的webpack

{
  "name": "vue-ssr-tech",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    **"build": "webpack --config webpack.config.js"**
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "css-loader": "^2.1.0",
    "style-loader": "^0.23.1",
    "vue": "^2.6.8",
    "vue-loader": "^15.7.0",
    "vue-template-compiler": "^2.6.8",
    "webpack": "^4.29.6"
  },
  "devDependencies": {
    "webpack-cli": "^3.2.3"
  }
}

6、npm run build
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值