vue-cli 多html,vue-cli创建的项目,配置多页面的实现方法

vue官方提供的命令行工具vue-cli,能够快速搭建单页应用。默认一个页面入口index.html,那么,如果我们需要多页面该如何配置,实际上也不复杂

假设要新建的页面是rule,以下以rule为例

创建新的html页面

创建入口文件Rule.vue和rule.js,仿照App.vue和main.js

export default {

name: 'lottery',

data() {

return {

}

},

mounted: function() {

this.$router.replace({

path:'/rule'

});

},

}

body{

margin:0;

padding:0;

}

rule.js

import Vue from 'vue'

import Rule from './Rule.vue'

import router from './router'

import $ from 'jquery'

//import vConsole from 'vconsole'

import fastclick from 'fastclick'

Vue.config.productionTip = false

fastclick.attach(document.body)

Vue.config.productionTip = false;

/* eslint-disable no-new */

new Vue({

el: '#rule',

router,

template: '',

components: { Rule },

})

修改config/index.js

build添加rule地址,即编译后生成的rule.html的地址和名字

build: {

// Template for index.html

index: path.resolve(__dirname, '../dist/index.php'),

rule: path.resolve(__dirname, '../dist/rule.php'),

……

}

rule: path.resolve(__dirname, '../dist/rule.php')表示编译后再dist文件下,rule.html编译后文件名为rule.php

修改build/webpack.base.conf.js

配置entry

entry: {

app: './src/main.js',

rule: './src/rule.js'

},

修改build/webpack.dev.conf.js

在plugins增加

new HtmlWebpackPlugin({

filename: 'rule.html',

template: 'rule.html',

inject: true,

chunks:['rule']

}),

修改build/webpack.prod.conf.js

在plugins增加

new HtmlWebpackPlugin({

filename: config.build.rule,

template: 'rule.html',

inject: true,

minify: {

removeComments: true,

collapseWhitespace: true,

removeAttributeQuotes: true

// more options:

// https://github.com/kangax/html-minifier#options-quick-reference

},

// necessary to consistently work with multiple chunks via CommonsChunkPlugin

chunksSortMode: 'dependency',

chunks: ['manifest','vendor','rule']

}),

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值