├── src └── .gitkeep ├── tpl └── .gitkeep ├── static └── .gitkeep ├── pageConfig ├── entry.js ├── removePage.js └── addPage.js ├── .eslintignore ├── .gitignore ├── config ├── prod.env.js ├── dev.env.js └── index.js ├── .editorconfig ├── .babelrc ├── .eslintrc.js ├── README.md └── package.json /src/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tpl/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pageConfig/entry.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | } -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /config/ 3 | /dist/ 4 | /*.js 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | /dist/ 3 | npm-debug.log* 4 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /pageConfig/removePage.js: -------------------------------------------------------------------------------- 1 | 2 | const fs = require('fs') 3 | const path = require('path') 4 | const cp = require('child_process') 5 | const pathName = path.resolve(__dirname, 'entry.js') 6 | const pageName = process.argv[2] 7 | let entry = require('./entry.js') 8 | 9 | // 删除入口文件配置项 10 | entry[pageName] = null 11 | let res = `module.exports = { \n` 12 | Object.keys(entry).forEach(key => { 13 | if (entry[key]) { 14 | res += `\t${key}: './src/${key}/${key}.js',\n` 15 | } 16 | }) 17 | fs.writeFileSync(pathName, res + '}') 18 | 19 | // 删除页面目录, 包括router、pages、.vue和.js等 20 | cp.spawn('rm', ['-rf', `./src/${pageName}`]) 21 | 22 | // 删除模版html 23 | fs.unlinkSync(`./tpl/${pageName}.html`) -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parserOptions: { 6 | parser: 'babel-eslint' 7 | }, 8 | env: { 9 | browser: true, 10 | }, 11 | extends: [ 12 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention 13 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules. 14 | 'plugin:vue/essential', 15 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md 16 | 'standard' 17 | ], 18 | // required to lint *.vue files 19 | plugins: [ 20 | 'vue' 21 | ], 22 | // add your custom rules here 23 | rules: { 24 | // allow async-await 25 | 'generator-star-spacing': 'off', 26 | // allow debugger during development 27 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 28 | 'semi': 0 //关闭分号检查 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## multiPage-vue-cli 2 | ### 基于vue2和vue-cli2搭建的vue多页面应用脚手架,可自动生成webpack配置、模板html、入口js文件以及根组件、支持自定义中间件。在多页面需求比较多、需要频繁迭代、新增一级页面的场景中可以快速搭建应用雏形。 3 | ------------------- 4 | 5 | ### 1.用法: 6 | 7 | #### 1.安装依赖 8 | > `npm install` 9 | 10 | #### 2.生成一个一级page 11 | > `npm run add ${pageName}` 12 | 13 | #### 3.生成一个一级page并支持vueRouter 14 | > `npm run add ${pageName} y` 15 | 16 | #### 4.移除一个一级page 17 | > `npm run rm ${pageName}` 18 | 19 | #### 5.本地启动 20 | > `npm start` 21 | ##### 或者 22 | > `npm run start` 23 | 24 | #### 6.构建 25 | > `npm run build` 26 | 27 | ----------------------- 28 | 29 | ### 2.本地访问: 30 | 多页面的本地访问需要在webpack的devServer中配置historyApiFallback,目前集成的path路径直接是pageName,访问地址是`localhost:8088/${pathName}`也可以根据需求修改webpack.dev.conf.js中的rewritesConfig函数来自定义。 31 | 32 | ### 3.生成的页面结构 33 | 34 | 1.没有路由 35 | `${pagename}` 36 | `${pagename}.vue` 37 | `${pagename}.js` 38 | 2.有路由 39 | `${pagename}` 40 | `pages` 41 | `router` 42 | `index.js` 43 | `${pagename}.vue` 44 | `${pagename}.js` 45 | 46 | ------------------------- 47 | ### 4.注意 48 | 执行`npm start`之前确保已经存在至少一个一级page,否则报错 49 | 50 | 51 | 52 | 项目集成了postcss-px-to-viewport等插件,解决移动端适配问题,可以参考[如何在Vue项目中使用vw实现移动端适配_vw, Layout, 布局, Vue, mobile 教程](https://www.w3cplus.com/mobile/vw-layout-in-vue.html) 53 | 54 | **建议**:如果是个人项目,config/index.js的host配置建议改成本机ip,便于配合autoOpenBrowser实现浏览器自动打开以及移动端访问,localhost移动端是无法访问的。如果是团队项目,建议改成0.0.0.0,便于团队中每个个人在移动端使用本机ip访问。 55 | -------------------------------------------------------------------------------- /pageConfig/addPage.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | const path = require('path') 4 | 5 | const pathName = path.resolve(__dirname, 'entry.js') 6 | 7 | const pageName = process.argv[2] 8 | 9 | const needRouter = process.argv[3] 10 | 11 | let entry = require('./entry.js') 12 | 13 | entry[pageName] = true 14 | 15 | // 生成入口文件 16 | let res = `module.exports = { \n` 17 | Object.keys(entry).forEach(key => { 18 | res += `\t${key}: './src/${key}/${key}.js',\n` 19 | }) 20 | fs.writeFileSync(pathName, res + '}') 21 | 22 | 23 | // 生成模板文件 24 | fs.writeFileSync(`./tpl/${pageName}.html`, ` 25 | 26 | 27 |
28 | 29 | 30 |