Skip to content
Permalink
Browse files

init project

  • Loading branch information...
anchengjian committed Mar 8, 2018
1 parent 381b485 commit 2a947d0baff4b7b1c1dfb72ad66ebcce048f6f1f
Showing with 15,365 additions and 651 deletions.
  1. +2 −0 .gitignore
  2. +2 −2 LICENSE
  3. +52 −122 README.md
  4. +1 −0 build/alias.js
  5. +3 −1 build/build.js
  6. +32 −1 build/config.js
  7. +2 −1 dist/vue.common.js
  8. +2 −1 dist/vue.esm.js
  9. +2 −1 dist/vue.js
  10. +2 −2 dist/vue.min.js
  11. +2 −1 dist/vue.runtime.common.js
  12. +2 −1 dist/vue.runtime.esm.js
  13. +2 −1 dist/vue.runtime.js
  14. +2 −2 dist/vue.runtime.min.js
  15. +19 −7 package.json
  16. +3 −0 packages/mpvue-template-compiler/README.md
  17. +4,785 −0 packages/mpvue-template-compiler/build.js
  18. +17 −0 packages/mpvue-template-compiler/index.js
  19. +27 −0 packages/mpvue-template-compiler/package.json
  20. +3 −0 packages/mpvue/README.md
  21. +5,461 −0 packages/mpvue/index.js
  22. +23 −0 packages/mpvue/package.json
  23. +1 −0 packages/vue-server-renderer/basic.js
  24. +1 −0 packages/vue-server-renderer/build.js
  25. +929 −218 packages/weex-template-compiler/build.js
  26. +471 −177 packages/weex-vue-framework/factory.js
  27. +174 −113 packages/weex-vue-framework/index.js
  28. +1 −0 src/core/vdom/create-component.js
  29. +7 −0 src/platforms/mp/compiler/codegen/config/astMap.js
  30. +3 −0 src/platforms/mp/compiler/codegen/config/config.js
  31. +78 −0 src/platforms/mp/compiler/codegen/config/wxmlDirectiveMap.js
  32. +149 −0 src/platforms/mp/compiler/codegen/config/wxmlTagMap.js
  33. +160 −0 src/platforms/mp/compiler/codegen/convert/attrs.js
  34. +27 −0 src/platforms/mp/compiler/codegen/convert/component.js
  35. +22 −0 src/platforms/mp/compiler/codegen/convert/for.js
  36. +105 −0 src/platforms/mp/compiler/codegen/convert/index.js
  37. +49 −0 src/platforms/mp/compiler/codegen/convert/tag.js
  38. +30 −0 src/platforms/mp/compiler/codegen/generate.js
  39. +24 −0 src/platforms/mp/compiler/codegen/index.js
  40. +22 −0 src/platforms/mp/compiler/codegen/utils.js
  41. +27 −0 src/platforms/mp/compiler/create-compiler.js
  42. +9 −0 src/platforms/mp/compiler/directives/html.js
  43. +9 −0 src/platforms/mp/compiler/directives/index.js
  44. +164 −0 src/platforms/mp/compiler/directives/model.js
  45. +9 −0 src/platforms/mp/compiler/directives/text.js
  46. +10 −0 src/platforms/mp/compiler/index.js
  47. +103 −0 src/platforms/mp/compiler/mark-component.js
  48. +48 −0 src/platforms/mp/compiler/modules/class.js
  49. +7 −0 src/platforms/mp/compiler/modules/index.js
  50. +51 −0 src/platforms/mp/compiler/modules/style.js
  51. +26 −0 src/platforms/mp/compiler/options.js
  52. +24 −0 src/platforms/mp/compiler/util.js
  53. +4 −0 src/platforms/mp/entry-compiler.js
  54. +5 −0 src/platforms/mp/entry-runtime.js
  55. +26 −0 src/platforms/mp/join-code-in-build.js
  56. +94 −0 src/platforms/mp/runtime/events.js
  57. +56 −0 src/platforms/mp/runtime/index.js
  58. +224 −0 src/platforms/mp/runtime/lifecycle.js
  59. +47 −0 src/platforms/mp/runtime/node-ops.js
  60. +18 −0 src/platforms/mp/runtime/patch.js
  61. +149 −0 src/platforms/mp/runtime/render.js
  62. +64 −0 src/platforms/mp/util/index.js
  63. +27 −0 test/mp/.eslintrc
  64. +455 −0 test/mp/compiler/index.spec.js
  65. +22 −0 test/mp/helpers/index.js
  66. +91 −0 test/mp/helpers/mp.runtime.js
  67. +11 −0 test/mp/jasmine.json
  68. +280 −0 test/mp/runtime/events.spec.js
  69. +374 −0 test/mp/runtime/instance.spec.js
  70. +232 −0 test/mp/runtime/lifecycle.spec.js
@@ -1,6 +1,7 @@
.DS_Store
node_modules
*.log
package-lock.json
explorations
TODOs.md
dist/*.gz
@@ -16,3 +17,4 @@ packages/vue-server-renderer/build.js
packages/vue-server-renderer/server-plugin.js
packages/vue-server-renderer/client-plugin.js
packages/vue-template-compiler/build.js
.vscode/
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-present, Yuxi (Evan) You
Copyright (c) 2018-present, 美团点评

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
174 README.md
@@ -1,122 +1,52 @@
<p align="center"><a href="https://vuejs.org" target="_blank"><img width="100"src="https://vuejs.org/images/logo.png"></a></p>
<p align="center">
<a href="https://circleci.com/gh/vuejs/vue/tree/dev"><img src="https://img.shields.io/circleci/project/vuejs/vue/dev.svg" alt="Build Status"></a>
<a href="https://codecov.io/github/vuejs/vue?branch=dev"><img src="https://img.shields.io/codecov/c/github/vuejs/vue/dev.svg" alt="Coverage Status"></a>
<a href="https://www.npmjs.com/package/vue"><img src="https://img.shields.io/npm/dm/vue.svg" alt="Downloads"></a>
<a href="https://www.npmjs.com/package/vue"><img src="https://img.shields.io/npm/v/vue.svg" alt="Version"></a>
<a href="https://www.npmjs.com/package/vue"><img src="https://img.shields.io/npm/l/vue.svg" alt="License"></a>
<a href="https://chat.vuejs.org/"><img src="https://img.shields.io/badge/chat-on%20discord-7289da.svg" alt="Chat">
<br>
<a href="https://saucelabs.com/u/vuejs"><img src="https://saucelabs.com/browser-matrix/vuejs.svg" alt="Sauce Test Status"></a>
</p>
## Supporting Vue.js
Vue.js is an MIT-licensed open source project. Its ongoing development is made possible thanks to the support by these awesome [backers](https://github.com/vuejs/vue/blob/dev/BACKERS.md). If you'd like to join them, check out [Vue.js' Patreon campaign](https://www.patreon.com/evanyou).
<p align="center">
<b>Special thanks to the generous sponsorship by:</b>
<br><br>
<a href="https://stdlib.com">
<img width="240px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/stdlib.png">
</a>
<br><br>
<a href="https://www.upyun.com/?utm_source=vue&utm_medium=ad&utm_content=github">
<img width="160px" src="https://raw.githubusercontent.com/vuejs/cn.vuejs.org/master/themes/vue/source/images/upyun-small.png">
</a>
<br><br>
<a href="https://deepstreamhub.com" target="_blank">
<img width="140px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/deepstream.png">
</a>
<br><br>
<a href="https://jsfiddle.net/">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/jsfiddle.png">
</a>
<br><br>
<a href="https://laravel.com/">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/laravel.png">
</a>
<br><br>
<a href="https://chaitin.cn/">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/chaitin.png">
</a>
<br><br>
<a href="https://htmlburger.com/">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/htmlburger.png">
</a>
<br><br>
<a href="https://starter.someline.com/">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/someline.png">
</a>
<br><br>
<a href="http://monterail.com/" target="_blank">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/monterail.png">
</a>
<br><br>
<a href="https://www.trisoft.ro/" target="_blank">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/trisoft.png">
</a>
<br><br>
<a href="https://www.2mhost.com/" target="_blank">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/2mhost.png">
</a>
<br><br>
<a href="https://vuejsjob.com/?ref=vuejs" target="_blank">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/vuejobs.png">
</a>
<br><br>
<a href="https://leanpub.com/vuejs2" target="_blank">
<img width="120px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/tmvuejs2.png">
</a>
<br><br>
<a href="https://famebroker.com" target="_blank">
<img width="130px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/famebroker.png">
</a>
<br><br>
<a href="https://component.io/" target="_blank">
<img width="130px" src="https://raw.githubusercontent.com/vuejs/vuejs.org/master/themes/vue/source/images/component_io.png">
</a>
</p>
## Intro
Vue.js is a library for building interactive web interfaces. It provides data-reactive components with a simple and flexible API. Core features include:
- [Declarative rendering with a plain JavaScript object based reactivity system](https://vuejs.org/guide/index.html#Declarative-Rendering)
- [Component-oriented development style with tooling support](https://vuejs.org/guide/index.html#Composing-with-Components)
- Lean and extensible core
- [Flexible transition effect system](https://vuejs.org/guide/transitions.html)
- Fast without the need for complex optimization
Note that Vue.js only supports [ES5-compliant browsers](http://kangax.github.io/compat-table/es5/) (IE8 and below are not supported).
## Documentation
To check out live examples and docs, visit [vuejs.org](https://vuejs.org).
## Questions
For questions and support please use the [the official forum](http://forum.vuejs.org) or [community chat](https://chat.vuejs.org/). The issue list of this repo is **exclusively** for bug reports and feature requests.
## Issues
Please make sure to read the [Issue Reporting Checklist](https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#issue-reporting-guidelines) before opening an issue. Issues not conforming to the guidelines may be closed immediately.
## Contribution
Please make sure to read the [Contributing Guide](https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md) before making a pull request. If you have a Vue-related project/component/tool, add it with a pull-request to [this curated list](https://github.com/vuejs/awesome-vue)!
## Changelog
Details changes for each release are documented in the [release notes](https://github.com/vuejs/vue/releases).
## Stay In Touch
For the latest releases and announcements, follow on Twitter: [@vuejs](https://twitter.com/vuejs)
## License
[MIT](http://opensource.org/licenses/MIT)
Copyright (c) 2013-present, Yuxi (Evan) You
# mpvue
> Vue.js in mini program
<img src="http://mpvue.com/assets/logo.png" width="80">

`mpvue` 是一个使用 [Vue.js](https://vuejs.org) 开发小程序的前端框架。框架基于 `Vue.js` 核心,`mpvue` 修改了 `Vue.js` 的 [runtime](http://mpvue.com/mpvue) 和 [compiler](http://mpvue.com/mpvue-template-compiler) 实现,使其可以运行在小程序环境中,从而为小程序开发引入了整套 `Vue.js` 开发体验。

## 实践案例

美团旗下小程序:`美团汽车票``美团充电`,此外,正有一大批小程序正在接入中。

## 快速开始

我们精心准备了一个简单的 [五分钟上手教程](http://mpvue.com/mpvue/quickstart) 方便你快速体验到 `mpvue` 带来的开发乐趣。

## 名称由来
- `mp`:mini program 的缩写
- `mpvue`:Vue.js in mini program

## 主要特性
使用 `mpvue` 开发小程序,你将在小程序技术体系的基础上获取到这样一些能力:

- 彻底的组件化开发能力:提高代码
- 完整的 `Vue.js` 开发体验
- 方便的 `Vuex` 数据管理方案:方便构建复杂应用
- 快捷的 `webpack` 构建机制:自定义构建策略、开发阶段 hotReload
- 支持使用 npm 外部依赖
- 使用 `Vue.js` 命令行工具 vue-cli 快速初始化项目
- H5 代码转换编译成小程序目标代码的能力

其它特性正在等着你去探索。

### H5 和小程序如何复用代码
先来看一段视频:
<video src="http://mpvue.com/assets/20170810-022809-HD.mp4" width="863" height="480" controls="controls"></video>

在左侧为已经上线的 H5 页面,右侧为同代码的小程序页面,其中只需要更改小部分平台差异代码和更新下 webpack 的建构配置就可以直接运行。

在未来最理想的状态是,可以一套代码可以直接跑在多端:WEB、小程序(微信和支付宝)、Native(借助weex)。

当然从产品的层面,我们不建议这么做,各个端有自己的差异性,我们期望的只是开发和调试体验一致。

## 配套设施
`mpvue` 作为小程序版本的 `Vue.js`,在框架 SDK 之外,完整的技术体系还包括如下设施。

- [mpvue-loader](http://mpvue.com/build/mpvue-loader) 提供 webpack 版本的加载器
- [mpvue-webpack-target](http://mpvue.com/build/mpvue-webpack-target) webpack 构建目标
- [postcss-mpvue-wxss](http://mpvue.com/build/postcss-mpvue-wxss) 样式代码转换预处理工具
- [px2rpx-loader](http://mpvue.com/build/px2rpx-loader) 样式转化插件
- 其它


@@ -7,6 +7,7 @@ module.exports = {
shared: path.resolve(__dirname, '../src/shared'),
web: path.resolve(__dirname, '../src/platforms/web'),
weex: path.resolve(__dirname, '../src/platforms/weex'),
mp: path.resolve(__dirname, '../src/platforms/mp'),
server: path.resolve(__dirname, '../src/server'),
entries: path.resolve(__dirname, '../src/entries'),
sfc: path.resolve(__dirname, '../src/sfc')
@@ -14,7 +14,9 @@ let builds = require('./config').getAllBuilds()
if (process.argv[2]) {
const filters = process.argv[2].split(',')
builds = builds.filter(b => {
return filters.some(f => b.dest.indexOf(f) > -1)
// fix the project name === floder name
// return filters.some(f => b.dest.indexOf(f) > -1)
return filters.some(f => b.dest.slice(path.resolve(__dirname, '../').length).indexOf(f) > -1)
})
} else {
// filter out weex builds by default
@@ -7,6 +7,7 @@ const node = require('rollup-plugin-node-resolve')
const flow = require('rollup-plugin-flow-no-whitespace')
const version = process.env.VERSION || require('../package.json').version
const weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
const mpVueVersion = process.env.MP_VUE_VERSION || require('../packages/mpvue/package.json').version

const banner =
'/*!\n' +
@@ -15,6 +16,8 @@ const banner =
' * Released under the MIT License.\n' +
' */'

const { mpBanner, mpLifecycleHooks } = require('../src/platforms/mp/join-code-in-build')

const weexFactoryPlugin = {
intro () {
return 'module.exports = function weexFactory (exports, renderer) {'
@@ -156,6 +159,24 @@ const builds = {
dest: resolve('packages/weex-template-compiler/build.js'),
format: 'cjs',
external: Object.keys(require('../packages/weex-template-compiler/package.json').dependencies)
},
// Runtime only (ES Modules). Used by bundlers that support ES Modules,
// e.g. Rollup & Webpack 2
'mpvue': {
mp: true,
entry: resolve('mp/entry-runtime.js'),
dest: resolve('packages/mpvue/index.js'),
format: 'umd',
env: 'production',
banner: mpBanner
},
// MP compiler (CommonJS). Used by mpvue's Webpack loader.
'mpvue-template-compiler': {
mp: true,
entry: resolve('mp/entry-compiler.js'),
dest: resolve('packages/mpvue-template-compiler/build.js'),
format: 'cjs',
external: Object.keys(require('../packages/mpvue-template-compiler/package.json').dependencies)
}
}

@@ -171,7 +192,7 @@ function genConfig (opts) {
replace({
__WEEX__: !!opts.weex,
__WEEX_VERSION__: weexVersion,
__VERSION__: version
__VERSION__: opts.mp ? mpVueVersion : version
}),
flow(),
buble(),
@@ -185,6 +206,16 @@ function genConfig (opts) {
}))
}

// hack fix MP LIFECYCLE_HOOKS
if (opts.mp) {
config.plugins.push(replace({
"'deactivated'\n]": `'deactivated', ${mpLifecycleHooks}\n]`
}))
config.plugins.push(replace({
'inBrowser && window.navigator.userAgent.toLowerCase': `['mpvue-runtime'].join`
}))
}

return config
}

@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
'use strict';
@@ -3498,6 +3498,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');
@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
/* */
@@ -3496,6 +3496,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');
@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
(function (global, factory) {
@@ -3494,6 +3494,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
'use strict';
@@ -3494,6 +3494,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');
@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
/* */
@@ -3492,6 +3492,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');
@@ -1,6 +1,6 @@
/*!
* Vue.js v2.4.1
* (c) 2014-2017 Evan You
* (c) 2014-2018 Evan You
* Released under the MIT License.
*/
(function (global, factory) {
@@ -3490,6 +3490,7 @@ var componentVNodeHooks = {
insert: function insert (vnode) {
var context = vnode.context;
var componentInstance = vnode.componentInstance;

if (!componentInstance._isMounted) {
componentInstance._isMounted = true;
callHook(componentInstance, 'mounted');

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 2a947d0

Please sign in to comment.
You can’t perform that action at this time.