项目下载地址 vue-cli多页面多路由项目示例 :vue+webpack+vue-router+vuex+mock+axios
Usage
This is a project template for vue-cli.
github上找到某大神的一个基于vue-cli模板的vueAdmin后台管理的模板,根据项目需求改成一个多页面多路由的vue项目。
踩了无数的坑,终于是初见效果了,随后继续优化更新
Install
serve with hot reload at localhost:8088
npm run dev
build for production with minification
npm run build
使用Nginx服务器进行访问,地址如下:
PC端 http://localhost/modules/index.html
移动APP http://localhost/modules/index.html
多页面配置
vue2.0版本多页面入口,是由webpack配置来完成的,我的项目文件结构如下
原则上这些文件名称都可以随意定,但由于下面entry入口函数的限定,换成其他名字可以会找不到。如果想要起其他文件名,请相应修改getMultiEntry()函数。
until.js
until.js中添加getMultiEntry(),依赖 glob插件,需要提前下载好,until.js开始引入
glob.sync(globPath).forEach(function (entry) {
basename = path.basename(entry,path.extname(entry));
tmp = entry.split('/').splice(-4);
var pathsrc = tmp[0]+'/'+tmp[1];
if( tmp[0] == 'src' ){
pathsrc = tmp[1];
}
//console.log(pathsrc)
pathname = pathsrc + '/' + basename; // 正确输出js和html的路径
entries[pathname] = entry;
//console.log(pathname+'-----------'+entry);
});
return entries;
}
~\build\webpack.base.conf.js
找到entry,添加多入口
运行、编译的时候每一个入口都会对应一个Chunk。 PS:终于明白这个chunk的含义了/(ㄒoㄒ)/~~
~\build\webpack.dev.conf.js
文末添加以下配置:
其中config.moduleName = 'modules'
~\build\webpack.prod.conf.js
//构建生成多页面的HtmlWebpackPlugin配置,主要是循环生成
var pages = utils.getMultiEntry('./src/'+config.moduleName+'/*/.html');
for (var pathname in pages) {
var conf = {
filename: pathname + '.html',// 模板路径
chunks: ['vendor',pathname],// 每个html引用的js模块
inject: true,// js插入位置
hash:true
};
webpackConfig.plugins.push(new HtmlWebpackPlugin(conf));
}
module.exports = webpackConfig
其中config.moduleName = 'modules'
至此,多页面的配置已经完成。访问地址为: index : http://localhost:8088/modules/index.html phone : http://localhost:8088/modules/phone.html
browser Support
Modern browsers and Internet Explorer 10+.
snapshots
imsun; white-space: normal; word-spacing: 0px; text-transform: none; font-weight: normal; color: rgb(0,0); font-style: normal; orphans: 2; widows: 2; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px">
imsun; white-space: normal; word-spacing: 0px; text-transform: none; font-weight: normal; color: rgb(0,0); font-style: normal; orphans: 2; widows: 2; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px">
imsun; white-space: normal; word-spacing: 0px; text-transform: none; font-weight: normal; color: rgb(0,0); font-style: normal; orphans: 2; widows: 2; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px">
License
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。