All Projects → jarvan4dev → Vue Multi Page

jarvan4dev / Vue Multi Page

Licence: apache-2.0
基于vue-cli脚手架修改而成的多页面(非SPA)项目脚手架

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Multi Page

Vue2 News
基于vue2 + vue-router + vuex 构建的一个新闻类单页面应用 —— 今日头条(移动端)
Stars: ✭ 462 (+32.38%)
Mutual labels:  vue-cli, spa
Blog
一个go、echo、vue 开发的快速、简洁、美观、前后端分离的个人博客系统(blog)、也可方便二次开发为CMS(内容管理系统)和各种企业门户网站
Stars: ✭ 388 (+11.17%)
Mutual labels:  vue-cli, spa
Vue Blog Template
vue-blog 基础模板
Stars: ✭ 31 (-91.12%)
Mutual labels:  vue-cli, spa
Vue2 Echo
基于vue2 + vue-router + vuex 构建的一个音乐类单页面应用 —— echo回声
Stars: ✭ 408 (+16.91%)
Mutual labels:  vue-cli, spa
Blog Admin
blog-admin @react、@typescript、@apollographql
Stars: ✭ 239 (-31.52%)
Mutual labels:  vue-cli, spa
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (-16.33%)
Mutual labels:  spa
Daza Frontend
[DEPRECATED]
Stars: ✭ 326 (-6.59%)
Mutual labels:  vue-cli
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (-17.48%)
Mutual labels:  spa
Angular
UI-Router for Angular: State-based routing for Angular (v2+)
Stars: ✭ 287 (-17.77%)
Mutual labels:  spa
Koa Vue Notes Api
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and async/await.
Stars: ✭ 342 (-2.01%)
Mutual labels:  spa
Vue3 Jd H5
🔥 Based on vue3.0.0, vant3.0.0, vue-router v4.0.0-0, vuex^4.0.0-0, vue-cli3, mockjs, imitating Jingdong Taobao, mobile H5 e-commerce platform! 基于vue3.0.0 ,vant3.0.0,vue-router v4.0.0-0, vuex^4.0.0-0,vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台!
Stars: ✭ 328 (-6.02%)
Mutual labels:  vue-cli
Element Admin
一个支持 vue-cli 的 Element UI 的后台模板
Stars: ✭ 318 (-8.88%)
Mutual labels:  vue-cli
Roastandbrew
Updated content available! We learned a lot since we originally wrote this article. We now have this updated for Laravel 8, Vue, and NuxtJS 👉 https://srvrsi.de/book
Stars: ✭ 300 (-14.04%)
Mutual labels:  spa
Eshoponcontainers
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 6, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor.
Stars: ✭ 19,397 (+5457.88%)
Mutual labels:  spa
Vue Cli Plugin Electron Builder
Easily Build Your Vue.js App For Desktop With Electron
Stars: ✭ 3,549 (+916.91%)
Mutual labels:  vue-cli
Wechat Spa
🎉 微信端单页面应用(SPA)常见问题汇总及解决方案
Stars: ✭ 337 (-3.44%)
Mutual labels:  spa
Space Snake
A Desktop game built with Electron and Vue.js.
Stars: ✭ 289 (-17.19%)
Mutual labels:  vue-cli
Vuefront
VueFront Core. Turn your old-fashioned CMS website in to a SPA & PWA in 5 minutes
Stars: ✭ 316 (-9.46%)
Mutual labels:  spa
Vue Tradingview
This is a tradingview chart using Vue 2, Vuex and TypeScript.
Stars: ✭ 330 (-5.44%)
Mutual labels:  vue-cli
Plantuml Editor
PlantUML online demo client
Stars: ✭ 313 (-10.32%)
Mutual labels:  vue-cli

vue-multi-page

了解了Vue一般都会去用Vue-cli入门,这是一个构建SPA的脚手架,查看其build的项目,可以看到它是将所有的模块都输出到一个build.js中,有时候会看到这个js文件特别大,有好几兆,然而当一个项目足够复杂时,SPA恐怕不再适合使用了,用户不可能访问你的网页的时候一下子下载一个几兆的文件,特别对于手机用户,可能用户只看了网站中的一篇文章,这也会导致网页加载慢,这是不可取的。所以应该将网站划分成若干模块。于是就有了本demo(一个用于构建多页面的脚手架)

如何开始?

假设你已经熟悉了vue-cli了😄

  1. 创建项目

    vue init webpack vue-multi-page
    # 为了简便可以不用jslint等
    
  2. 开始改造

    最主要的一步,将webpack进行改造以满足对多页面需求的支持,其实多页面,即是webpack有多个入口。在此步中,我们主要的操作的对象是 build文件夹下的js文件。

    • 首先,我们对 utils.js进行改造 添加一个方法:getEntries,方法中需要使用到node的globa模块,所以需要引入

       // glob模块,用于读取webpack入口目录文件
      // 看到issue中有人问glob模块,这个是需要npm安装的,[https://github.com/isaacs/node-glob](https://github.com/isaacs/node-glob)
      var glob = require('glob');
      
    	
    	```javascript
    	exports.getEntries = function (globPath) {
      var entries = {}
      /**
       * 读取src目录,并进行路径裁剪
       */
      glob.sync(globPath).forEach(function (entry) {
        /**
         * path.basename 提取出用 ‘/' 隔开的path的最后一部分,除第一个参数外其余是需要过滤的字符串
         * path.extname 获取文件后缀
         */
        var basename = path.basename(entry, path.extname(entry), 'router.js') // 过滤router.js
        // ***************begin***************
        // 当然, 你也可以加上模块名称, 即输出如下: { module/main: './src/module/index/main.js', module/test: './src/module/test/test.js' }
        // 最终编译输出的文件也在module目录下, 访问路径需要时 localhost:8080/module/index.html
        // slice 从已有的数组中返回选定的元素, -3 倒序选择,即选择最后三个
        // var tmp = entry.split('/').splice(-3)
        // var pathname = tmp.splice(0, 1) + '/' + basename; // splice(0, 1)取tmp数组中第一个元素
        // console.log(pathname)
        // entries[pathname] = entry
        // ***************end***************
        entries[basename] = entry
      });
      // console.log(entries);
      // 获取的主入口如下: { main: './src/module/index/main.js', test: './src/module/test/test.js' }
      return entries;
    }
    	```
    + 其次,对webpack.base.conf.js进行改造
    	
    	删除 ~~entry: {app: './src/main.js'},~~,取而代之如下:
    
    	```javascript
    	module.exports = {
    		···
    		entry: utils.getEntries('./src/module/**/*.js'),
    	  ···
    	}
    	```
    + 最后改造webpack.dev.conf.js和webpack.prod.conf.js
    	
    	移除原来的HtmlWebpackPlugin
    	
    	```javascript
    	  var pages = utils.getEntries('./src/module/**/*.html')
      for(var page in pages) {
        // 配置生成的html文件,定义路径等
        var conf = {
          filename: page + '.html',
          template: pages[page], //模板路径
          inject: true,
          // excludeChunks 允许跳过某些chunks, 而chunks告诉插件要引用entry里面的哪几个入口
          // 如何更好的理解这块呢?举个例子:比如本demo中包含两个模块(index和about),最好的当然是各个模块引入自己所需的js,
          // 而不是每个页面都引入所有的js,你可以把下面这个excludeChunks去掉,然后npm run build,然后看编译出来的index.html和about.html就知道了
          // filter:将数据过滤,然后返回符合要求的数据,Object.keys是获取JSON对象中的每个key
          excludeChunks: Object.keys(pages).filter(item => {
            return (item != page)
          })
        }
        // 需要生成几个html文件,就配置几个HtmlWebpackPlugin对象
        module.exports.plugins.push(new HtmlWebpackPlugin(conf))
      }
    	```
    	
    

构建步骤

	``` bash
	# 安装依赖
	npm install
	# 本地测试
	npm run dev
	# 打包
	npm run build
	
	```

在本地调试启动后访问:index(http://localhost:8080) | about(http://localhost:8080/about.html) 即可

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].