1、为项目添加多个入口

找到\build\webpack.base.conf.js文件:

 module.exports = {
//...,
//vue的多页面开发:应用程序可以存在多个入口
entry: {
app: './src/main.js',
product: './src/product.js'
},
//...
}

2、为开发环境和生产环境配置入口对应的配置项

打开:\build\webpack.dev.conf.js

 const devWebpackConfig = merge(baseWebpackConfig, {
//...
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
chunks:['app']
}),
new HtmlWebpackPlugin({
filename: 'product.html',
template: 'product.html',
inject: true,
chunks:['product']
}),
//...
]
})

打开:\build\webpack.prod.conf.js,plugins节点下面加:

 //...
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.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', 'app']
}),
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'product.html'
: config.build.product,
template: 'product.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', 'product']
}),
//...

3、配置编译环境

 build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
product: path.resolve(__dirname, '../dist/product.html'),
//...
}

4、根目录添加product.html

后面product关联的页面入口都是这个页面。

5、src目录添加product.js和product.vue

product.js类似于单页面的main.js的作用

import Vue from 'vue'
import product from './product.vue' Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#product',
render: h => h(product)
})

product.vue类似于单页面的App.vue的作用

 <template>
<div id="prodcut">
{{msg}}
</div>
</template> <script>
export default {
name: 'prodcut',
data () {
return {
msg: 'I am prodcut'
}
}
}
</script>

6、添加测试链接

App.vue添加produt.html链接

 <template>
<div id="app">
<img src="./assets/logo.png">
<a href="product.html">product</a><br>
<router-view/>
</div>
</template> <script>
export default {
name: 'App'
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

 7、测试

可以看到编译后的文件index.html和product.html已经分别编译了,各自作为单页面的入口:

编译后的js也是各自的:

下面是演示效果:

8、源码

https://github.com/iprometheus/vue-multipage

9、参考文档

http://blog.csdn.net/Tank_in_the_street/article/details/73732801

vue 2.0多页面开发的更多相关文章

  1. vue.js2.0:如何搭建开发环境及构建项目

    1,安装node.js Node.js官网:https://nodejs.org/en/ 进入Node.js官网,选择下载并安装Node.js.安装过程只需要点击“下一步”即可, 如下图,非常简单. ...

  2. 前端Vue项目——首页/课程页面开发及Axios请求

    一.首页轮播图 1.elementUI走马灯 elementUI中 Carousel 走马灯,可以在有限空间内,循环播放同一类型的图片.文字等内容. 这里使用指示器样式,可以将指示器的显示位置设置在容 ...

  3. vue2.0多页面开发

    我们平常用vue开发的时候总觉得vue好像就是专门为了单页面应用而诞生的,其实不是.因为vue在工程化开发的时候很依赖webpack,而webpack是将所有的资源整合到一块,弄成一个单页面.但是vu ...

  4. vue多页面与单页面开发的区别。

    进入一家新的公司,要开发移动端app项目,前端技术选型时前端组长选的是vue的多页面开发,当时很蒙,vue不是单页面开发吗?咋出来多页面的.接触之后才发现确实存在也挺简单的,省去了路由表的配置.那就给 ...

  5. vue2.0与实战开发

    慕课网实战 百度云 web前端实战: Node.js入门到企业Web开发中的应用 Web前端性能优化 让你的页面飞起来 前端跳槽面试必备技巧 前端JavaScript面试技巧全套 node.JS 线上 ...

  6. 【Alpaca】.Net版开源配置中心 - 技术选型 Vue 3.0

    是否可以用 Vue 3.0 现有的Vue 2.* 不推荐,坐等Vue 3.0出迁移工具吧,手动改的话工作量还是不小的 新项目 考虑下团队内对Vue + TS + VS Code的熟练程度.过程中你会遇 ...

  7. vue搭建多页面开发环境

    自从习惯开发了单页面应用,对多页面的页面间的相互跳转间没有过渡效果.难维护极度反感.但是最近公司技术老大说,当一个应用越来越大的时候单页面模式应付不来,但是没讲怎么应付不来,所以还得自己去复习一遍这两 ...

  8. 每天记录一点:NetCore获得配置文件 appsettings.json vue-router页面传值及接收值 详解webpack + vue + node 打造单页面(入门篇) 30分钟手把手教你学webpack实战 vue.js+webpack模块管理及组件开发

    每天记录一点:NetCore获得配置文件 appsettings.json   用NetCore做项目如果用EF  ORM在网上有很多的配置连接字符串,读取以及使用方法 由于很多朋友用的其他ORM如S ...

  9. vue-calendar 基于 vue 2.0 开发的轻量,高性能日历组件

    vue-calendar-component 基于 vue 2.0 开发的轻量,高性能日历组件 占用内存小,性能好,样式好看,可扩展性强 原生 js 开发,没引入第三方库 Why Github 上很多 ...

随机推荐

  1. onmouseover和onmouseenter区别

    onmouseover和onmouseenter都是鼠标进入时触发,onmouseover在所选元素的子元素间切换的时候也触发! <!doctype html><html lang= ...

  2. django rest framework 与 Vue 整合遇到的坑

    前提是已经有了Django项目与前端Vue打包好的dist文件 好,开始整合!!! 当然还是先设置Django的setting.py 1设置模板路径 2 设置静态文件路径 TEMPLATES = [ ...

  3. git 入门教程之github 教程

    github 教程 github 是一个基于 git 的代码托管平台,是平时工作学习的好帮手,学会如何用好 github 网站能够帮助我们更好分享代码或者与其他开发人员合作. 注册 github 账号 ...

  4. Centos 中无法上网的问题

    我是 Centos 最小化安装的,安装网后 Centos 竟然无法上网...有点奇葩, 应该是网卡没有激活的问题了,下面是解决的过程 查看网卡 ip addr 其中 lo 是 Loop back ad ...

  5. javascript的隐式类型转换

    首先简单了解js的typeof,会返回六种类型 即 number string boolen function object undefined 也就是六种基本数据类型 显示类型转换大概有以下几种: ...

  6. SQL强化练习(面试与学习必备)

    一.经典选课题A 1.1.请同时使用GUI手动与SQL指令的形式创建数据库.表并添加数据. 题目:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教 ...

  7. Scala隐式转换

    package big.data.analyse.scala import java.io.File import scala.io.Source /** * 隐式转换 * Created by zh ...

  8. [20181124]关于降序索引问题2.txt

    [20181124]关于降序索引问题2.txt --//链接:blog.itpub.net/267265/viewspace-2221425/,探讨降序索引中索引的键值.--//实际上使用函数sys_ ...

  9. 洗礼灵魂,修炼python(64)--爬虫篇—re模块/正则表达式(2)

    前面学习了元家军以及其他的字符匹配方法,那得会用啊对吧?本篇博文就简单的解析怎么运用 正则表达式使用 前面说了正则表达式的知识点,本篇博文就是针对常用的正则表达式进行举例解析.相信你知道要用正则表达式 ...

  10. Android重复依赖解决办法

    参考文章:https://blog.csdn.net/qq_24216407/article/details/72842614 在build.gradle引用了Vlc的安卓包:de.mrmaffen: ...