• Stars
    star
    353
  • Rank 119,896 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⛓️ 集中式页面配置,统一构建入口,支持新增页面热更新

mpvue-entry

自动生成构建入口,避免编写大量重复的 main.js 文件

npm package npm downloads build status codecov codebeat badge license

目录结构

├─build
├─config
├─src
│ ├─components
│ ├─pages
│ │  └─news
│ │     │─list.vue
│ │     └─detail.vue
│ ├─App.vue
│ ├─app.json
│ └─main.js
└─package.json

Quickstart

https://github.com/F-loat/mpvue-quickstart

vue init F-loat/mpvue-quickstart my-project

安装

npm i mpvue-entry@next -D

使用

v2.0 版本仅支持 mpvue-loader@^1.1.0,兼容 megalo

// webpack.base.conf.js
const MpvueEntry = require('mpvue-entry')

module.exports = {
  entry: MpvueEntry.getEntry('src/app.json'),
  ...
  plugins: [
    new MpvueEntry(),
    ...
  ]
}
// app.json - 支持 js 格式,兼容微信小程序官方配置规范
{
  "pages": [
    {
      "path": "pages/news/list", // 页面路径,同时是 vue 文件相对于 src 的路径,必填
      "config": { // 页面配置,即 page.json 的内容,可选
        "navigationBarTitleText": "文章列表",
        "enablePullDownRefresh": true
      }
    }
  ],
  "window": {}
}

参数

  • paths: String/Object

paths 为 String 类型时作为 config 的值,为绝对路径或相对于项目根目录的相对路径

property default describe
config 'src/app.json' 项目配置文件
main 'src/main.js' 主入口文件,作为模板
template 'src/main.js' 入口模板文件,优先级较高
entry 'mpvue-entry/dist/' 各页面入口文件目录
// 示例
MpvueEntry.getEntry({
  config: 'src/app.js',
  main: 'src/index.js'
})
  • pages [String/Object]

pages 元素为 String 类型时作为 path 的值,为绝对路径或相对于项目根目录的相对路径

property type default describe
path String - 文件路径
config Object {} 页面配置
route String - 页面路由
native Boolean false 原生页面
subPackage Boolean false 分包加载
root String - 分包根路径
name String root 分包别名
independent Boolean false 独立分包
// 示例
[
  'pages/index',
  {
    path: 'pages/news/list',
    config: {
      navigationBarTitleText: '页面标题'
    },
    route: 'pages/news/list/main'
  },
  {
    path: 'package/news/detail',
    root: 'package/news',
    subPackage: true,
    independent: true
  }
]

Tips

  • 首页为 pages 数组的第一项

  • 分包配置兼容微信小程序官方写法

  • paths 的相关配置均可在项目 package.json 的 entryOptions 中覆盖

  • 可通过以下形式的注释指定 main.js 特有代码

console.log('hello world') // app-only

/* app-only-begin */
console.log('happy')
console.log('coding')
/* app-only-end */
  • 官方模板生成的项目请务必去除以下配置
// webpack.base.conf.js
module.exports = {
  plugins: [
    new CopyWebpackPlugin([{
      from: '**/*.json',
      to: ''
    }], {
      context: 'src/'
    }),
    ...
  ]
}
  • megalo 官方已对打包入口做了类似的优化,如无迁移需求可直接采用官方方案

Thanks

More Repositories

1

vue-simplemde

📝 Vue SimpleMDE - use simplemde with vue.js
Vue
767
star
2

ithome-lite

🥛 IT之家第三方小程序版客户端(使用 mpvue 开发,兼容 web)
Vue
527
star
3

mpvue-router-patch

🛴在 mpvue 中使用 vue-router 兼容的路由写法
JavaScript
300
star
4

caption2text

📥 PWA 版字幕转换为文本工具,支持 ass 及 srt 格式,可批量导出为 word 及 text 文件
Vue
182
star
5

vue-cli-plugin-qiankun

🚀 qiankun plugin for vue-cli
JavaScript
169
star
6

ChineseBQB-client

🤣 开源表情包小程序
Less
91
star
7

html-i18n-cli

HTML 国际化/翻译 工具
JavaScript
32
star
8

offscreen-canvas-demo

JavaScript
16
star
9

mpvue-packager

🛠 集成构建工具,双端支持
JavaScript
16
star
10

mpvue-config-loader

🏷 单文件页面配置,支持全局组件引用
JavaScript
11
star
11

ncform-maker

🔀 ncform-maker, a very nice visualization way to make ncform schema
JavaScript
7
star
12

unique

🕯 An online shopping platform based on Express & Vue2.
JavaScript
7
star
13

anonchat

👥匿名匹配聊天
Vue
6
star
14

taobao-edu-spider

🕷淘宝教育视频爬虫,基于Nightmare
JavaScript
5
star
15

vscode-plugin-ncform-schema

😘 ncform schema editor plugin for vscode
Vue
5
star
16

vscode-plugin-html-i18n

TypeScript
5
star
17

vue-superagent

⚡A small wrapper for integrating superagent to Vuejs
JavaScript
5
star
18

vod-server

🕯 vod server side
JavaScript
4
star
19

axios-apicloud-adapter

📱 axios 的 apicloud 适配器,以便于在 app 中使用原生网络请求库,避免跨域问题
JavaScript
4
star
20

cards-ahoy

Cards Ahoy! 小账本,提供实时卡牌价格查询、卡牌盈亏统计及卡组配置分享等功能
TypeScript
2
star
21

vscode-extension-mammoth

Word preview and export extension for vscode.
TypeScript
2
star
22

vod-client

🕯 vod client side
Vue
2
star
23

puppet-spider

🕷 赶集网 Puppeteer 命令行爬虫工具
JavaScript
2
star
24

jsonl-converter

One-Click JSON Lines Converter
TypeScript
1
star
25

CasualPlay

✨Some of my small projects
JavaScript
1
star
26

simple-form-binder

JavaScript
1
star
27

university-rankings

油猴脚本,划词查询大学排名
JavaScript
1
star
28

ncform-theme-iview

ncform theme widgets -> iview
Vue
1
star