提交 2b4a84ac 编写于 作者: Q qiang

Merge commit '97426838'

......@@ -3,3 +3,5 @@ src/platforms/app-plus-nvue/runtime
build/rollup-plugin-require-context
packages/*/packages
packages/*/template/**/*
qh-api.js
touch-emulator.js
......@@ -4,3 +4,4 @@ unpackage/
.vscode/
.idea
.DS_Store
!packages/uni-app-plus/dist
......@@ -5,7 +5,7 @@ const request = require('request')
const registry = 'https://registry.npmjs.org/@dcloudio/'
const pkgs = fs.readdirSync(path.resolve(__dirname, 'packages'))
const pkgs = fs.readdirSync(path.resolve(__dirname, 'packages')).filter(pkg => pkg.indexOf('.') !== 0)
const tag = process.argv[2] || 'alpha'
......
......@@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path')
const shellExec = require('shell-exec')
const pkgs = fs.readdirSync(path.resolve(__dirname, 'packages'))
const pkgs = fs.readdirSync(path.resolve(__dirname, 'packages')).filter(pkg => pkg.indexOf('.') !== 0)
const version = process.argv[2]
if (!version) {
......
......@@ -11,7 +11,7 @@
|versionCode|String||版本号,例如:36||
|transformPx|Boolean|true|是否转换项目的px,为true时将px转换为rpx,为false时,px为传统的实际像素||
|networkTimeout|Object||网络超时时间,[详见](/collocation/manifest?id=networktimeout)||
|debug|Boolean|false|是否开启 debug 模式,开启后调试信息以 ``info`` 的形式给出,其信息有页面的注册,页面路由,数据更新,事件触发等||
|debug|Boolean|false|是否开启 debug 模式,开启后调试信息以 ``info`` 的形式给出,其信息有页面的注册,页面路由,数据更新,事件触发等||
|uniStatistics|Object||[是否开启 uni 统计,全局配置](/collocation/manifest?id=uniStatistics)|2.2.3+|
|app-plus|Object||[App 特有配置](/collocation/manifest?id=app-plus)||
|h5|Object||[H5 特有配置](/collocation/manifest?id=h5)||
......@@ -38,13 +38,13 @@
|connectSocket|Number|否|60000|uni.connectSocket 的超时时间,单位毫秒。|
|uploadFile|Number|否|60000|uni.uploadFile 的超时时间,单位毫秒。|
|downloadFile|Number|否|60000|uni.downloadFile 的超时时间,单位毫秒。|
`HBuilderX 2.5.10`起,上述默认超时时间由6秒改为60秒,对齐微信小程序平台。
### uniStatistics
uni 统计配置项
`HBuilderX 2.5.10`起,上述默认超时时间由6秒改为60秒,对齐微信小程序平台。
### uniStatistics
uni 统计配置项
|属性|类型|必填|默认值|说明|
|--|--|--|--|--|
|enable|Boolean|是|true|是否开启uni统计|
......@@ -61,8 +61,8 @@ uni 统计配置项
|renderer|String|可不加载基于 webview 的运行框架,减少包体积、提升启动速度。可选值 `native`| App-nvue 2.2.0+|
|compilerVersion|Number|编译器版本,可选值:2、3 默认 2 [详见](https://ask.dcloud.net.cn/article/36599)|HBuilderX alpha 2.4.4+或HBuilderX 2.5.0+|
|nvueLaunchMode|Number|Nvue 首页启动模式,在 compilerVersion 值为 3 时生效,可选值:normal、fast 默认 normal(HBuilderX alpha 2.4.4-2.4.9 固定为 fast) [详见](https://ask.dcloud.net.cn/article/36749)|2.5.0+|
|nvue|Object|nvue 页面布局初始配置,[详见](/collocation/manifest?id=nvue)|2.0.3+|
|uniStatistics|Object|[App 是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)|2.2.3+|
|nvue|Object|nvue 页面布局初始配置,[详见](/collocation/manifest?id=nvue)|2.0.3+|
|uniStatistics|Object|[App 是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)|2.2.3+|
PS:这里只列出了核心部分,更多内容请参考 [完整的 manifest.json](/collocation/manifest?id=完整-manifestjson)
......@@ -223,7 +223,7 @@ H5平台是SPA单页应用,普通的SEO信息即加meta字段只能在,自
|loading|String|AsyncLoading|页面 js 加载时使用的组件(需注册为全局组件)|
|error|String|AsyncError|页面 js 加载失败时使用的组件(需注册为全局组件)|
|delay|Number|200|展示 loading 加载组件的延时时间(页面 js 若在 delay 时间内加载完成,则不会显示 loading 组件)|
|timeout|Number|3000|页面 js 加载超时时间(超时后展示 error 对应的组件)|
|timeout|Number|60000|页面 js 加载超时时间(超时后展示 error 对应的组件)|
#### devServer
|属性|类型|默认值|说明|
......@@ -317,7 +317,7 @@ Tips:关于摇树优化(treeShaking)原理及优化结果,参考:[http
|workers|String|Worker 代码放置的目录。 [详见](https://developers.weixin.qq.com/miniprogram/dev/framework/workers.html)|
|optimization|Object| 对微信小程序的优化配置 |
|cloudfunctionRoot|String| 配置云开发目录,参考[setting](/collocation/manifest?id=cloudfunctionRoot)|
|uniStatistics|Object|[微信小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)||
|uniStatistics|Object|[微信小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)||
#### setting
......@@ -372,12 +372,12 @@ Tips:关于摇树优化(treeShaking)原理及优化结果,参考:[http
|属性 |类型 |说明 |
|:- |:- |:- |
|usingComponents |Boolean| 是否启用自定义组件模式,`v2.0+`,默认为false,[编译模式区别详情](https://ask.dcloud.net.cn/article/35843) |
|usingComponents |Boolean| 是否启用自定义组件模式,`v2.0+`,默认为false,[编译模式区别详情](https://ask.dcloud.net.cn/article/35843) |
|plugins |Object |使用到的插件,[详见](https://opendocs.alipay.com/mini/plugin/plugin-usage) |
|component2 |Boolean| 是否启用 `component2` 编译,默认为false,[查看详情](https://docs.alipay.com/mini/framework/custom-component-overview) |
|axmlStrictCheck |Boolean| 是否启用 `axml` 严格语法检查,默认为false |
|enableParallelLoader |Boolean| 是否启用多进程编译,默认为false |
|enableDistFileMinify |Boolean| 是否压缩编译产物(仅在真机预览/真机调试时生效),默认为false |
|enableDistFileMinify |Boolean| 是否压缩编译产物(仅在真机预览/真机调试时生效),默认为false |
|uniStatistics |Object |[支付宝小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics) |
**注意**
......@@ -392,7 +392,7 @@ Tips:关于摇树优化(treeShaking)原理及优化结果,参考:[http
|usingComponents|Boolean| 是否启用自定义组件模式,`v2.0+`,默认为false,[编译模式区别详情](https://ask.dcloud.net.cn/article/35843)|
|requiredBackgroundModes|Array|小程序需要在后台使用的能力,目前支持背景音频播放,"requiredBackgroundModes": ["audio"],[详见](https://smartprogram.baidu.com/docs/develop/tutorial/process/#requiredBackgroundModes) |
|prefetches|Array|预请求的所有url的列表,[详见](https://smartprogram.baidu.com/docs/develop/tutorial/process/#prefetches) |
|optimization|Object| 对百度小程序的优化配置 |
|optimization|Object| 对百度小程序的优化配置 |
|uniStatistics|Object|[百度小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)|
#### optimization
......@@ -410,7 +410,7 @@ Tips:关于摇树优化(treeShaking)原理及优化结果,参考:[http
|appid|String|头条小程序的 AppID,登录 [https://developer.toutiao.com/](https://developer.toutiao.com/) 申请|
|setting|Object|头条小程序项目设置,参考[头条小程序项目设置](/collocation/manifest?id=mp-toutiao-setting)|
|usingComponents|Boolean| 是否启用自定义组件模式,`v2.0+`,默认为false,[编译模式区别详情](https://ask.dcloud.net.cn/article/35843)|
|navigateToMiniProgramAppIdList |Array|需要跳转的小程序列表,[详见](https://developer.toutiao.com/dev/cn/mini-app/develop/framework/basic-reference/general-configuration) |
|navigateToMiniProgramAppIdList |Array|需要跳转的小程序列表,[详见](https://developer.toutiao.com/dev/cn/mini-app/develop/framework/basic-reference/general-configuration) |
|uniStatistics|Object|[头条小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)|
#### 头条小程序项目设置@mp-toutiao-setting
......@@ -432,7 +432,7 @@ Tips:关于摇树优化(treeShaking)原理及优化结果,参考:[http
|permission |Object |小程序接口权限相关设置,比如申请位置权限必须填此处[详见](https://q.qq.com/wiki/develop/miniprogram/frame/dispose.html#permission) |
|workers |String |Worker 代码放置的目录。 [详见](https://q.qq.com/wiki/develop/miniprogram/frame/dispose.html#workers) |
|groupIdList |String Array |需要打开群资料卡的群号列表,详见button的open-type |
|optimization|Object| 对QQ小程序的优化配置 |
|optimization|Object| 对QQ小程序的优化配置 |
|uniStatistics|Object|[QQ小程序是否开启 uni 统计,配置方法同全局配置](/collocation/manifest?id=uniStatistics)|
#### optimization
......@@ -475,10 +475,10 @@ mp-qq只支持自定义组件模式,不存在usingComponents配置
"name": "应用名称,如uni-app",
"description": "应用描述",
"versionName": "1.0.0",
"versionCode": "100",
// 是否全局关闭uni统计
"uniStatistics": {
"enable": false//全局关闭
"versionCode": "100",
// 是否全局关闭uni统计
"uniStatistics": {
"enable": false//全局关闭
},
// app-plus 节点是 App 特有配置,推荐在 HBuilderX 的 manifest.json 可视化界面操作完成配置。
"app-plus": {
......@@ -759,9 +759,9 @@ mp-qq只支持自定义组件模式,不存在usingComponents配置
"quickapp": {},
// 微信小程序特有配置
"mp-weixin": {
"appid": "wx开头的微信小程序appid",
"uniStatistics": {
"enable": false//仅微信小程序关闭uni统计
"appid": "wx开头的微信小程序appid",
"uniStatistics": {
"enable": false//仅微信小程序关闭uni统计
},
},
// 百度小程序特有配置
......
......@@ -12,5 +12,5 @@
"message": "chore(release): publish %s"
}
},
"version": "2.0.0-alpha-25720200116004"
"version": "2.0.0-alpha-26420200309002"
}
......@@ -59,7 +59,8 @@ const media = [
'saveVideoToPhotosAlbum',
'createVideoContext',
'createCameraContext',
'createLivePlayerContext'
'createLivePlayerContext',
'createLivePusherContext'
]
const device = [
......@@ -186,6 +187,7 @@ const third = [
'checkSession',
'getUserInfo',
'share',
'shareWithSystem',
'showShareMenu',
'hideShareMenu',
'requestPayment',
......@@ -201,6 +203,10 @@ const third = [
'setPageMeta'
]
const ad = [
'createRewardedVideoAd'
]
const apis = [
...base,
...network,
......@@ -214,7 +220,8 @@ const apis = [
...event,
...file,
...canvas,
...third
...third,
...ad
]
module.exports = apis
......@@ -66,7 +66,8 @@
"uni.saveVideoToPhotosAlbum": true,
"uni.createVideoContext": true,
"uni.createCameraContext": true,
"uni.createLivePlayerContext": true
"uni.createLivePlayerContext": true,
"uni.createLivePusherContext": true
}
}, {
"name": "device",
......@@ -206,4 +207,10 @@
"uni.base64ToArrayBuffer": true,
"uni.arrayBufferToBase64": true
}
}, {
"name": "ad",
"title": "广告",
"apiList": {
"uni.createRewardedVideoAd": true
}
}]
......@@ -20,8 +20,8 @@
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.mp.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.mp.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "npm run lint && cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "npm run lint && cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-weixin:wxs": "rollup -c build/rollup.config.wxs.js",
"build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:app-plus",
"build:stat": "npm run lint && rollup -c build/rollup.config.stat.js",
......@@ -30,7 +30,7 @@
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js",
"release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
},
"dependencies": {
......@@ -105,6 +105,7 @@
"my": true,
"swan": true,
"tt": true,
"qh": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
......
{
"name": "@dcloudio/uni-app-plus-nvue",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app app-plus-nvue",
"main": "dist/index.js",
"repository": {
......
......@@ -1314,7 +1314,8 @@ function parseBaseComponent (vueComponentOptions, {
const options = {
multipleSlots: true,
addGlobalClass: true
addGlobalClass: true,
...(vueOptions.options || {})
};
const componentOptions = {
......@@ -1359,7 +1360,7 @@ function parseBaseComponent (vueComponentOptions, {
}
},
detached () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
}
},
pageLifetimes: {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
{
"name": "@dcloudio/uni-app-plus",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app app-plus",
"main": "dist/index.js",
"repository": {
......
......@@ -14,14 +14,14 @@ const defaultAsync = {
loading: 'AsyncLoading',
error: 'AsyncError',
delay: 200,
timeout: 3000
timeout: 60000
}
const networkTimeout = {
request: 6000,
connectSocket: 6000,
uploadFile: 6000,
downloadFile: 6000
request: 60000,
connectSocket: 60000,
uploadFile: 60000,
downloadFile: 60000
}
function getManifestJson () {
......@@ -50,7 +50,11 @@ function getH5Options (manifestJson) {
h5.title = h5.title || manifestJson.name || ''
h5.router = Object.assign({}, defaultRouter, h5.router || {})
if (process.env.UNI_SUB_PLATFORM === 'mp-360') { // 360 小程序仅支持 hash 模式
h5.router = Object.assign({}, defaultRouter)
} else {
h5.router = Object.assign({}, defaultRouter, h5.router || {})
}
h5['async'] = Object.assign({}, defaultAsync, h5['async'] || {})
......@@ -59,7 +63,6 @@ function getH5Options (manifestJson) {
if (base.indexOf('/') !== 0) {
base = '/' + base
}
if (base.substr(-1) !== '/') {
base = base + '/'
}
......@@ -76,6 +79,11 @@ function getH5Options (manifestJson) {
h5.publicPath = base
}
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
h5.router.base = '/'
h5.publicPath = '/'
}
/* eslint-disable no-mixed-operators */
h5.template = h5.template && path.resolve(process.env.UNI_INPUT_DIR, h5.template) || path.resolve(__dirname,
'../../../../public/index.html')
......@@ -90,4 +98,4 @@ module.exports = {
parseManifestJson,
getNetworkTimeout,
getH5Options
}
}
......@@ -30,7 +30,7 @@ module.exports = {
}
if (PLATFORMS.indexOf(scriptOptions.env.UNI_PLATFORM) === -1) {
console.error(`UNI_PLATFORM 支持下平台 ${JSON.stringify(PLATFORMS)}`)
console.error(`UNI_PLATFORM 支持下平台 ${JSON.stringify(PLATFORMS)}`)
process.exit(0)
}
......@@ -41,4 +41,4 @@ module.exports = {
return scriptOptions
}
}
}
......@@ -340,6 +340,10 @@ const PLATFORMS = {
}
}
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
if (process.env.UNI_PLATFORM === 'mp-360') {
process.env.UNI_PLATFORM = 'h5'
process.env.UNI_SUB_PLATFORM = 'mp-360'
}
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
const platform = PLATFORMS[process.env.UNI_PLATFORM]
......@@ -375,6 +379,14 @@ if (process.env.UNI_PLATFORM.indexOf('app-') === 0) {
preprocessContext['APP'] = true
}
preprocessContext['MP-360'] = false
preprocessContext['MP_360'] = false
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
preprocessContext['H5'] = false
preprocessContext['MP-360'] = true
preprocessContext['MP_360'] = true
}
if (process.UNI_SCRIPT_DEFINE && Object.keys(process.UNI_SCRIPT_DEFINE).length) {
Object.keys(process.UNI_SCRIPT_DEFINE).forEach(name => {
preprocessContext[name] = process.UNI_SCRIPT_DEFINE[name]
......@@ -566,8 +578,9 @@ module.exports = {
orderedValues: false,
mergeLonghand: false,
mergeRules: false,
cssDeclarationSorter: false,
uniqueSelectors: false, // 标签排序影响头条小程序
cssDeclarationSorter: false,
uniqueSelectors: false, // 标签排序影响头条小程序
minifySelectors: false, // 标签排序影响头条小程序
discardComments: false,
discardDuplicates: false // 条件编译会导致重复
}
......
{
"name": "@dcloudio/uni-cli-shared",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-cli-shared",
"main": "lib/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-h5-ui",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app h5 ui",
"main": "dist/index.umd.min.js",
"repository": {
......
此差异已折叠。
{
"name": "@dcloudio/uni-h5",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"repository": {
......
{
"name": "@dcloudio/uni-migration",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app migration",
"main": "lib/index.js",
"repository": {
......
......@@ -442,19 +442,32 @@ const protocols = { // 需要做转换的 API 列表
if (!fromArgs.header) { // 默认增加 header 参数,方便格式化 content-type
fromArgs.header = {};
}
const headers = {
'content-type': 'application/json'
};
Object.keys(fromArgs.header).forEach(key => {
headers[key.toLocaleLowerCase()] = fromArgs.header[key];
});
return {
header (header = {}, toArgs) {
const headers = {
'content-type': 'application/json'
};
Object.keys(header).forEach(key => {
headers[key.toLocaleLowerCase()] = header[key];
});
return {
name: 'headers',
value: headers
}
},
data (data) {
// 钉钉在content-type为application/json时,不会自动序列化
if (my.dd && headers['content-type'].indexOf('application/json') === 0) {
return {
name: 'data',
value: JSON.stringify(data)
}
}
return {
name: 'data',
value: data
}
},
method: 'method', // TODO 支付宝小程序仅支持 get,post
responseType: false
}
......@@ -551,12 +564,12 @@ const protocols = { // 需要做转换的 API 列表
returnValue: {
apFilePath: 'tempFilePath'
}
},
chooseVideo: {
// 支付宝小程序文档中未找到(仅在getSetting处提及),但实际可用
returnValue: {
apFilePath: 'tempFilePath'
}
},
chooseVideo: {
// 支付宝小程序文档中未找到(仅在getSetting处提及),但实际可用
returnValue: {
apFilePath: 'tempFilePath'
}
},
connectSocket: {
args: {
......@@ -640,22 +653,22 @@ const protocols = { // 需要做转换的 API 列表
},
scanCode: {
name: 'scan',
args (fromArgs) {
if (fromArgs.scanType === 'qrCode') {
fromArgs.type = 'qr';
args (fromArgs) {
if (fromArgs.scanType === 'qrCode') {
fromArgs.type = 'qr';
return {
onlyFromCamera: 'hideAlbum'
}
} else if (fromArgs.scanType === 'barCode') {
fromArgs.type = 'bar';
return {
onlyFromCamera: 'hideAlbum'
}
} else if (fromArgs.scanType === 'barCode') {
fromArgs.type = 'bar';
onlyFromCamera: 'hideAlbum'
}
} else {
return {
onlyFromCamera: 'hideAlbum'
}
} else {
return {
scanType: false,
onlyFromCamera: 'hideAlbum'
}
scanType: false,
onlyFromCamera: 'hideAlbum'
}
}
},
returnValue: {
......@@ -686,8 +699,16 @@ const protocols = { // 需要做转换的 API 列表
}
},
getUserInfo: {
name: 'getAuthUserInfo',
name: my.canIUse('getOpenUserInfo') ? 'getOpenUserInfo' : 'getAuthUserInfo',
returnValue (result) {
if (my.canIUse('getOpenUserInfo')) {
let response = {};
try {
response = JSON.parse(result.response).response;
} catch (e) {}
result.nickName = response.nickName;
result.avatar = response.avatar;
}
result.userInfo = {
nickName: result.nickName,
avatarUrl: result.avatar
......@@ -706,18 +727,18 @@ const protocols = { // 需要做转换的 API 列表
item.uuid = item.serviceId;
});
}
},
createBLEConnection: {
name: 'connectBLEDevice',
args: {
timeout: false
}
},
closeBLEConnection: {
name: 'disconnectBLEDevice'
},
onBLEConnectionStateChange: {
name: 'onBLEConnectionStateChanged'
},
createBLEConnection: {
name: 'connectBLEDevice',
args: {
timeout: false
}
},
closeBLEConnection: {
name: 'disconnectBLEDevice'
},
onBLEConnectionStateChange: {
name: 'onBLEConnectionStateChanged'
},
makePhoneCall: {
args: {
......@@ -749,35 +770,35 @@ const protocols = { // 需要做转换的 API 列表
returnValue: {
brightness: 'value'
}
},
showShareMenu: {
name: 'showSharePanel'
},
hideHomeButton: {
name: 'hideBackHome'
},
saveImageToPhotosAlbum: {
name: 'saveImage',
args: {
filePath: 'url'
}
},
saveVideoToPhotosAlbum: {
args: {
filePath: 'src'
}
},
chooseAddress: {
name: 'getAddress',
returnValue (result) {
let info = result.result || {};
result.userName = info.fullname;
result.provinceName = info.prov;
result.cityName = info.city;
result.detailInfo = info.address;
result.telNumber = info.mobilePhone;
result.errMsg = result.resultStatus;
}
},
showShareMenu: {
name: 'showSharePanel'
},
hideHomeButton: {
name: 'hideBackHome'
},
saveImageToPhotosAlbum: {
name: 'saveImage',
args: {
filePath: 'url'
}
},
saveVideoToPhotosAlbum: {
args: {
filePath: 'src'
}
},
chooseAddress: {
name: 'getAddress',
returnValue (result) {
let info = result.result || {};
result.userName = info.fullname;
result.provinceName = info.prov;
result.cityName = info.city;
result.detailInfo = info.address;
result.telNumber = info.mobilePhone;
result.errMsg = result.resultStatus;
}
}
};
......@@ -2113,7 +2134,7 @@ function parseComponent (vueComponentOptions) {
}
},
didUnmount () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
},
methods: {
__r: handleRef,
......
{
"name": "@dcloudio/uni-mp-alipay",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"repository": {
......
......@@ -1448,7 +1448,8 @@ function parseBaseComponent (vueComponentOptions, {
const options = {
multipleSlots: true,
addGlobalClass: true
addGlobalClass: true,
...(vueOptions.options || {})
};
const componentOptions = {
......@@ -1493,7 +1494,7 @@ function parseBaseComponent (vueComponentOptions, {
}
},
detached () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
}
},
pageLifetimes: {
......
{
"name": "@dcloudio/uni-mp-baidu",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"repository": {
......
......@@ -1366,10 +1366,11 @@ function parseBaseComponent (vueComponentOptions, {
const options = {
multipleSlots: true,
addGlobalClass: true
addGlobalClass: true,
...(vueOptions.options || {})
};
{
{
// 微信 multipleSlots 部分情况有 bug,导致内容顺序错乱 如 u-list,提供覆盖选项
if (vueOptions['mp-weixin'] && vueOptions['mp-weixin']['options']) {
Object.assign(options, vueOptions['mp-weixin']['options']);
......@@ -1418,7 +1419,7 @@ function parseBaseComponent (vueComponentOptions, {
}
},
detached () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
}
},
pageLifetimes: {
......
{
"name": "@dcloudio/uni-mp-qq",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app mp-qq",
"main": "dist/index.js",
"repository": {
......
......@@ -1538,7 +1538,8 @@ function parseBaseComponent (vueComponentOptions, {
const options = {
multipleSlots: true,
addGlobalClass: true
addGlobalClass: true,
...(vueOptions.options || {})
};
const componentOptions = {
......@@ -1583,7 +1584,7 @@ function parseBaseComponent (vueComponentOptions, {
}
},
detached () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
}
},
pageLifetimes: {
......
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"repository": {
......
......@@ -1319,10 +1319,11 @@ function parseBaseComponent (vueComponentOptions, {
const options = {
multipleSlots: true,
addGlobalClass: true
addGlobalClass: true,
...(vueOptions.options || {})
};
{
{
// 微信 multipleSlots 部分情况有 bug,导致内容顺序错乱 如 u-list,提供覆盖选项
if (vueOptions['mp-weixin'] && vueOptions['mp-weixin']['options']) {
Object.assign(options, vueOptions['mp-weixin']['options']);
......@@ -1371,7 +1372,7 @@ function parseBaseComponent (vueComponentOptions, {
}
},
detached () {
this.$vm.$destroy();
this.$vm && this.$vm.$destroy();
}
},
pageLifetimes: {
......
......@@ -2,7 +2,7 @@
* wxs getRegExp
*/
function getRegExp () {
const args = Array.prototype.slice.call(arguments);
var args = Array.prototype.slice.call(arguments);
args.unshift(RegExp);
return new (Function.prototype.bind.apply(RegExp, args))()
}
......@@ -11,7 +11,7 @@ function getRegExp () {
* wxs getDate
*/
function getDate () {
const args = Array.prototype.slice.call(arguments);
var args = Array.prototype.slice.call(arguments);
args.unshift(Date);
return new (Function.prototype.bind.apply(Date, args))()
}
......
{
"name": "@dcloudio/uni-mp-weixin",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-stat",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "",
"main": "dist/index.js",
"repository": {
......
......@@ -28,7 +28,7 @@ describe('codegen', () => {
)
assertCodegen(
'<div><block v-for="(item,index) in list" :key="index"><block><text>{{item}}</text></block></block></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list})),function(item,index,$20,$30){return [[_c('text',{key:_$s(("3-"+$30),'a-key',index+'_0'+'_0')},[_v((_$s(("3-"+$30),'t0',_s(item))))])]]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list,fill:true})),function(item,index,$20,$30){return [[_c('text',{key:_$s(("3-"+$30),'a-key',index+'_0'+'_0')},[_v((_$s(("3-"+$30),'t0-0',_s(item))))])]]})],2)}`
)
})
it('generate directive', () => {
......@@ -48,40 +48,48 @@ describe('codegen', () => {
)
assertCodegen(
'<div><template v-for="item in items">{{text}}</template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0-0',_s(text))))]})],2)}`
)
assertCodegen(
'<div><template v-for="item in items"><span></span>{{text}}</template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_v((_$s(("1-"+$30),'t1-0',_s(text))))]})],2)}`
)
assertCodegen(
'<div><template v-for="item in items">a {{text1}} b {{text2}}</template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text1)))+(_$s(("1-"+$30),'t1',_s(text2))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0-0',_s(text1)))+(_$s(("1-"+$30),'t0-1',_s(text2))))]})],2)}`
)
assertCodegen(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [(_$s(("2-"+$30),'i',item.sub))?_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}):_e()]})],2)}`
)
assertCodegen(
'<view><template v-for="(item, index) in arr">{{item}}</template></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
)
assertCodegen(
'<view><template v-for="(item, index) in arr">{{item}}</template></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0-0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0-0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item,index) in arr" v-bind:key="index"><block v-if="item==3">{{item}}</block></block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [(_$s(("2-"+$30),'i',item==3))?[_v((_$s(("2-"+$30),'t0-0',_s(item))))]:_e()]})],2)}`
)
})
it('generate text with multiple statements', () => {
assertCodegen(
`<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>`,
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id','a'+b),"_i":0}},[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id','a'+b),"_i":0}},[_v((_$s(0,'t0-0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t0-1',_s(text))))])}`
)
assertCodegen(
`<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(obj.param1)))+(_$s(0,'t0-1',_s(obj.param1)))+(_$s(0,'t0-2',_s(obj.param1)))),_c('text',[_v((_$s(1,'t0-0',_s(obj.param3)))+(_$s(1,'t0-1',_s(obj.param3))))]),_v((_$s(0,'t2-0',_s(obj.param2)))+(_$s(0,'t2-1',_s(obj.param2)))+(_$s(0,'t2-2',_s(obj.param2))))])}`
)
})
it('generate v-slot', () => {
assertCodegen(
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$s(("0-"+_si),'t0',_s(user.firstName))))]}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$s(("0-"+_si),'t0-0',_s(user.firstName))))]}}])})}`
)
assertCodegen(
'<current-user>ABCD</current-user>',
......@@ -93,7 +101,7 @@ describe('codegen', () => {
<view v-for="(item,index) in result.list">{{item.name}}</view>
</template>
</current-user>`,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({result}, _svm, _si){return _l((_svm._$s(("2-"+_si),'f',{forItems:result.list})),function(item,index,$20,$30){return _c('view',{key:_svm._$s(("2-"+_si),'f',{forIndex:$20,key:("2-"+_si)+'-'+$30}),attrs:{"_i":(("2-"+_si)+$30)}},[_v((_svm._$s((("2-"+_si)+$30),'t0',_s(item.name))))])})}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({result}, _svm, _si){return _l((_svm._$s(("2-"+_si),'f',{forItems:result.list})),function(item,index,$20,$30){return _c('view',{key:_svm._$s(("2-"+_si),'f',{forIndex:$20,key:("2-"+_si)+'-'+$30}),attrs:{"_i":(("2-"+_si)+$30)}},[_v((_svm._$s((("2-"+_si)+$30),'t0-0',_s(item.name))))])})}}])})}`
)
})
......@@ -132,6 +140,12 @@ describe('codegen', () => {
'<view data-a="1" :data-b="b"></view>',
`with(this){return _c('view',{attrs:{"data-b":_$s(0,'a-data-b',b),"_i":0}})}`
)
})
it('generate v-if directive', () => {
assertCodegen(
'<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>',
`with(this){return (_$s(0,'i',a))?_c('text'):(_$s(1,'e',b))?_c('text'):(_$s(2,'e',c))?_c('text'):_c('text')}`
)
})
})
/* eslint-enable quotes */
......@@ -16,35 +16,41 @@ describe('codegen', () => {
it('generate directive', () => {
assertCodegen(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
`with(this){return _c('p',{attrs:{"_i":0}})}`
)
})
it('generate v-for directive', () => {
assertCodegen(
'<div><template v-for="item in items"><div></div><div></div></template></div>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [_c('v-uni-view',{key:item['k0'],attrs:{"_i":("2-"+$30)}}),_c('v-uni-view',{key:item['k1'],attrs:{"_i":("3-"+$30)}})]})],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [_c('div',{key:item['k0'],attrs:{"_i":("2-"+$30)}}),_c('div',{key:item['k1'],attrs:{"_i":("3-"+$30)}})]})],2)}`
)
assertCodegen(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [(_$g(("2-"+$30),'i'))?_c('v-uni-label',{key:item['k0'],attrs:{"_i":("2-"+$30)}}):_e()]})],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [(_$g(("2-"+$30),'i'))?_c('span',{key:item['k0'],attrs:{"_i":("2-"+$30)}}):_e()]})],2)}`
)
})
it('generate events with multiple statements', () => {
assertCodegen(
'<div>A{{ d | e | f }}B{{text}}C</div>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0'))+"B"+(_$g(0,'t1'))+"C")])}`
`with(this){return _c('div',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0-0'))+"B"+(_$g(0,'t0-1'))+"C")])}`
)
})
it('generate slot fallback content', () => {
assertCodegen(
'<div><slot><div>{{hi}}</div></slot></div>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])],{"_i":1})],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[_t("default",[_c('div',{attrs:{"_i":2}},[_v((_$g(2,'t0-0')))])],{"_i":1})],2)}`
)
})
it('generate text with multiple statements', () => {
assertCodegen(
`<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+"123123"+(_$g(0,'t0-1'))+"123123"+(_$g(0,'t0-2'))),_c('v-uni-text',{attrs:{"_i":1}},[_v("-"+(_$g(1,'t0-0'))+"---"+(_$g(1,'t0-1')))]),_v((_$g(0,'t2-0'))+"aaaa"+(_$g(0,'t2-1'))+"aaaa"+(_$g(0,'t2-2')))],1)}`
)
})
it('generate v-slot', () => {
assertCodegen(
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$g(("0-"+_si),'t0')))]}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$g(("0-"+_si),'t0-0')))]}}])})}`
)
})
it('generate keep-alive', () => {
......@@ -60,14 +66,14 @@ describe('codegen', () => {
it('generate wxs props', () => {
assertCodegen(
'<p :change:prop="swipe.sizeReady" :prop="pos" @touchstart="swipe.touchstart" @touchmove="swipe.touchmove" @touchend="swipe.touchend" @change="change"></p>',
`with(this){return _c('v-uni-view',{wxsProps:{"change:prop":"pos"},attrs:{"change:prop":swipe.sizeReady,"prop":_$gc(0,'change:pos'),"_i":0},on:{"touchstart":function($event){$event = $handleWxsEvent($event);swipe.touchstart($event, $getComponentDescriptor())},"touchmove":function($event){$event = $handleWxsEvent($event);swipe.touchmove($event, $getComponentDescriptor())},"touchend":function($event){$event = $handleWxsEvent($event);swipe.touchend($event, $getComponentDescriptor())},"change":function($event){return $handleViewEvent($event)}}})}`
`with(this){return _c('p',{wxsProps:{"change:prop":"pos"},attrs:{"change:prop":swipe.sizeReady,"prop":_$gc(0,'change:pos'),"_i":0},on:{"touchstart":function($event){$event = $handleWxsEvent($event);swipe.touchstart($event, $getComponentDescriptor())},"touchmove":function($event){$event = $handleWxsEvent($event);swipe.touchmove($event, $getComponentDescriptor())},"touchend":function($event){$event = $handleWxsEvent($event);swipe.touchend($event, $getComponentDescriptor())},"change":function($event){return $handleViewEvent($event)}}})}`
)
})
// TODO 后续优化dataset
// it('generate dataset', () => {
// assertCodegen(
// '<view data-a="1" :data-b="b"></view>',
// `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
// `with(this){return _c('div',{attrs:{"_i":0}})}`
// )
// })
it('generate dataset', () => {
......@@ -75,6 +81,12 @@ describe('codegen', () => {
'<view data-a="1" :data-b="b"></view>',
`with(this){return _c('v-uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}`
)
})
it('generate v-if directive', () => {
assertCodegen(
'<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>',
`with(this){return (_$g(0,'i'))?_c('v-uni-text',{attrs:{"_i":0}},[_v("1")]):(_$g(1,'e'))?_c('v-uni-text',{attrs:{"_i":1}},[_v("2")]):(_$g(2,'e'))?_c('v-uni-text',{attrs:{"_i":2}},[_v("3")]):_c('v-uni-text',{attrs:{"_i":3}},[_v("d")])}`
)
})
})
/* eslint-enable quotes */
......@@ -27,14 +27,14 @@ describe('codegen', () => {
it('generate filters', () => {
assertCodegen(
'<div :id="a | b | c">{{ d | e | f }}</div>',
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id',_f("c")(_f("b")(a))),"_i":0}},[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d))))))])}`
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id',_f("c")(_f("b")(a))),"_i":0}},[_v((_$s(0,'t0-0',_s(_f("f")(_f("e")(d))))))])}`
)
})
it('generate filters with no arguments', () => {
assertCodegen(
'<div>{{ d | e() }}</div>',
`with(this){return _c('div',[_v((_$s(0,'t0',_s(_f("e")(d)))))])}`
`with(this){return _c('div',[_v((_$s(0,'t0-0',_s(_f("e")(d)))))])}`
)
})
......@@ -162,7 +162,7 @@ describe('codegen', () => {
it('generate template tag', () => {
assertCodegen(
'<div><template><p>{{hello}}</p></template></div>',
`with(this){return _c('div',[[_c('p',[_v((_$s(2,'t0',_s(hello))))])]],2)}`
`with(this){return _c('div',[[_c('p',[_v((_$s(2,'t0-0',_s(hello))))])]],2)}`
)
})
......@@ -197,47 +197,47 @@ describe('codegen', () => {
it('generate scoped slot', () => {
assertCodegen(
'<foo><template slot-scope="bar">{{ bar }}</template></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]}}])})}`
)
assertCodegen(
'<foo><div slot-scope="bar">{{ bar }}</div></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))])}}])})}`
)
})
it('generate named scoped slot', () => {
assertCodegen(
'<foo><template slot="foo" slot-scope="bar">{{ bar }}</template></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]}}])})}`
)
assertCodegen(
'<foo><div slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))])}}])})}`
)
})
it('generate dynamic scoped slot', () => {
assertCodegen(
'<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]}}],null,true)})}`
)
})
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar }}</template></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]:undefined}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?[_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]:undefined}}],null,true)})}`
)
assertCodegen(
'<foo><div v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]):_e()}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]):_e()}}],null,true)})}`
)
})
it('generate scoped slot with new slot syntax', () => {
assertCodegen(
'<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>',
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$s(1,'i',show))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}:null],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$s(1,'i',show))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0-0',_s(bar))))]}}:null],null,true)})}`
)
})
......@@ -625,7 +625,7 @@ describe('codegen', () => {
// normalize type: 2
assertCodegen(
'<div><child></child><template v-for="item in list">{{ item }}</template></div>',
`with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0',_s(item))))]})],2)}`
`with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0-0',_s(item))))]})],2)}`
)
})
......
......@@ -194,15 +194,15 @@ describe('mp:compiler-extra', () => {
it('generate default slot', () => {
assertCodegen(
'<component1>text</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}">text</component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}">text</component1>`
)
assertCodegen(
'<component1>text<text>123213</text></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}">text<text>123213</text></component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}">text<text>123213</text></component1>`
)
assertCodegen(
'<component1>text<block slot="right"></block></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default','right']}}">text<view slot="right"></view></component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','right']}}">text<view slot="right"></view></component1>`
)
})
......@@ -221,21 +221,21 @@ describe('mp:compiler-extra', () => {
assertCodegen(
'<component1><template slot="f">f</template><template slot="c">c</template>默认</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default','f','c']}}"><view slot="f">f</view><view slot="c">c</view>默认</component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','f','c']}}"><view slot="f">f</view><view slot="c">c</view>默认</component1>`
)
assertCodegen(
'<component1 v-slot>text</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text</view></component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text</view></component1>`
)
assertCodegen(
'<component1 v-slot:default>text<text>123213</text></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text<text>123213</text></view></component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text<text>123213</text></view></component1>`
)
assertCodegen(
'<component1><template v-slot:left><text></text></template><template v-slot:right><text></text></template></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['left','right']}}"><view slot="left"><text></text></view><view slot="right"><text></text></view></component1>`
`<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['left','right']}}"><view slot="left"><text></text></view><view slot="right"><text></text></view></component1>`
)
assertCodegen(
`<my-component>
......@@ -247,7 +247,7 @@ describe('mp:compiler-extra', () => {
<p>Here's some contact info</p>
</template>
</my-component>`,
`<my-component vue-id="1" bind:__l="__l" vue-slots="{{['default','header','footer']}}"><view slot="header"><view class="_h1">Here might be a page title</view></view><view slot="footer"><view class="_p">Here's some contact info</view></view><view class="_p">A paragraph for the main content.</view></my-component>`
`<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','header','footer']}}"><view slot="header"><view class="_h1">Here might be a page title</view></view><view slot="footer"><view class="_p">Here's some contact info</view></view><view class="_p">A paragraph for the main content.</view></my-component>`
)
})
......@@ -429,41 +429,41 @@ describe('mp:compiler-extra', () => {
it('generate events with v-on directive on custom component', () => {
assertCodegen(
'<my-component @click="handleClick"/>',
`<my-component bind:click="__e" vue-id="1" data-event-opts="{{[['^click',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
`<my-component bind:click="__e" vue-id="551070e6-1" data-event-opts="{{[['^click',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
)
assertCodegen(
'<my-component @click-left="handleClick"/>',
`<my-component bind:clickLeft="__e" vue-id="1" data-event-opts="{{[['^clickLeft',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
`<my-component bind:clickLeft="__e" vue-id="551070e6-1" data-event-opts="{{[['^clickLeft',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
)
})
it('generate v-model directive on custom component', () => {
assertCodegen(
'<my-component v-model="test" @input="handle">1</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l" vue-slots="{{['default']}}">1</my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l" vue-slots="{{['default']}}">1</my-component>`
)
assertCodegen(
'<my-component v-model="test" @click="handle">2</my-component>',
`<my-component bind:click="__e" bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^click',[['handle']]],['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">2</my-component>`
`<my-component bind:click="__e" bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^click',[['handle']]],['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">2</my-component>`
)
assertCodegen(
'<my-component v-model="test.a">3</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test.a}}" data-event-opts="{{[['^input',[['__set_model',['$0','a','$event',[]],['test']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">3</my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test.a}}" data-event-opts="{{[['^input',[['__set_model',['$0','a','$event',[]],['test']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">3</my-component>`
)
assertCodegen(
'<my-component v-model="test.a.b">4</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test.a.b}}" data-event-opts="{{[['^input',[['__set_model',['$0','b','$event',[]],['test.a']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test.a.b}}" data-event-opts="{{[['^input',[['__set_model',['$0','b','$event',[]],['test.a']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
)
assertCodegen(
'<my-component v-model="test[a.b][a.b]">4</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test[a.b][a.b]}}" data-event-opts="{{[['^input',[['__set_model',['$0','$1','$event',[]],['test.'+a.b+'','a.b']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test[a.b][a.b]}}" data-event-opts="{{[['^input',[['__set_model',['$0','$1','$event',[]],['test.'+a.b+'','a.b']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
)
})
it('generate object property on custom component', () => {
assertCodegen(
'<my-component v-model="test" @input="handle" />',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l"></my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l"></my-component>`
)
})
it('generate v-text directive', () => {
......@@ -490,23 +490,23 @@ describe('mp:compiler-extra', () => {
it('generate v-bind directive with sync modifier', () => {
assertCodegen(
'<text-document :title.sync="aaa"></text-document>',
`<text-document vue-id="1" title="{{aaa}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','aaa','$event'],['']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
`<text-document vue-id="551070e6-1" title="{{aaa}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','aaa','$event'],['']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
)
assertCodegen(
'<text-document :title.sync="doc.title"></text-document>',
`<text-document vue-id="1" title="{{doc.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
`<text-document vue-id="551070e6-1" title="{{doc.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
)
assertCodegen(
'<text-document :title.sync="doc.a.title"></text-document>',
`<text-document vue-id="1" title="{{doc.a.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc.a']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
`<text-document vue-id="551070e6-1" title="{{doc.a.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc.a']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
)
assertCodegen(
'<text-document v-for="item in items" :title.sync="item.title"></text-document>',
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'1-'+__i0__}}" title="{{item.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'551070e6-1-'+__i0__}}" title="{{item.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
)
assertCodegen(
'<text-document v-for="item in items" :title.sync="item.meta.title"></text-document>',
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'1-'+__i0__}}" title="{{item.meta.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'meta']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'551070e6-1-'+__i0__}}" title="{{item.meta.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'meta']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
)
})
......
......@@ -31,33 +31,33 @@ describe('mp:compiler-mp-alipay', () => {
it('generate ref', () => {
assertCodegen(
'<component1 ref="c1">text</component1>',
`<component1 vue-id="1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>`
`<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>`
)
assertCodegen(
'<component1 :ref="c2">text<text>123213</text></component1>',
`<component1 vue-id="1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>`
`<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>`
)
assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>`
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>`
)
assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>`
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>`
)
})
it('generate default slot', () => {
assertCodegen(
'<component1>text</component1>',
`<component1 vue-id="1" onVueInit="__l">text</component1>`
`<component1 vue-id="551070e6-1" onVueInit="__l">text</component1>`
)
assertCodegen(
'<component1>text<text>123213</text></component1>',
`<component1 vue-id="1" onVueInit="__l">text<text>123213</text></component1>`
`<component1 vue-id="551070e6-1" onVueInit="__l">text<text>123213</text></component1>`
)
assertCodegen(
'<component1>text<block slot="right"></block></component1>',
`<component1 vue-id="1" onVueInit="__l">text<view slot="right"></view></component1>`
`<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>`
)
})
it('generate class binding', () => {
......@@ -114,7 +114,7 @@ describe('mp:compiler-mp-alipay', () => {
it('generate events with v-on directive', () => {
assertCodegen(
`<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`,
`<uni-list-item vue-id="1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>`,
`<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>`,
`with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}`
)
......
......@@ -24,33 +24,33 @@ describe('mp:compiler-mp-baidu', () => {
it('generate scoped slot', () => {
assertCodegen(
'<foo><template slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default">{{foo}}</view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default">{{foo}}</view></foo>`
)
assertCodegen(
'<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default"><view>{{foo}}</view></view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><view>{{foo}}</view></view></foo>`
)
})
it('generate named scoped slot', () => {
assertCodegen(
'<foo><template slot="foo" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo">{{foo}}</view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo">{{foo}}</view></foo>`
)
assertCodegen(
'<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo"><view>{{foo}}</view></view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><view>{{foo}}</view></view></foo>`
)
})
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>`
)
assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>`
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>`
)
})
......@@ -68,23 +68,23 @@ describe('mp:compiler-mp-baidu', () => {
it('generate vue id', () => {
assertCodegen(
'<Test/>',
`<test vue-id="1"></test>`
`<test vue-id="551070e6-1"></test>`
)
assertCodegen(
'<Test a="a">',
`<test vue-id="1" a="a"></test>`
`<test vue-id="551070e6-1" a="a"></test>`
)
assertCodegen(
'<view><Test v-for="item in items" :key="item"/></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'1-'+__i0__}}"></test></block></view>`
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}"></test></block></view>`
)
assertCodegen(
'<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'1-'+__i0__}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{('2-'+__i0__+'-'+__i1__)+','+('1-'+__i0__)}}"></test></block></test></block></view>`
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{('551070e6-2-'+__i0__+'-'+__i1__)+','+('551070e6-1-'+__i0__)}}"></test></block></test></block></view>`
)
assertCodegen(
'<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{'1-'+index}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{('2-'+index+'-'+index1)+','+('1-'+index)}}"></test></block></test></block></view>`
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{'551070e6-1-'+index}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{('551070e6-2-'+index+'-'+index1)+','+('551070e6-1-'+index)}}"></test></block></test></block></view>`
)
})
......
......@@ -25,7 +25,7 @@ describe('mp:compiler-mp-toutiao', () => {
it('generate ref', () => {
assertCodegen(
'<my-component ref="ref"></my-component>',
`<my-component class="vue-ref" vue-id="1" data-ref="ref" bind:__l="__l"></my-component>`
`<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>`
)
})
......
......@@ -23,14 +23,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot', () => {
assertCodegen(
'<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'<foo><view slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
......@@ -40,14 +40,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate named scoped slot', () => {
assertCodegen(
'<foo><template slot="foo" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
assertCodegen(
'<foo><view slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
......@@ -57,14 +57,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
......@@ -90,7 +90,7 @@ describe('mp:compiler-mp-weixin', () => {
it('generate page-meta', () => {
assertCodegen(// TODO vue-id
'<view><page-meta/><view><button></button></view></view>',
`<page-meta vue-id="1" bind:__l="__l"></page-meta><view><button></button></view>`
`<page-meta vue-id="551070e6-1" bind:__l="__l"></page-meta><view><button></button></view>`
)
})
})
......@@ -159,7 +159,7 @@ describe('mp:compiler', () => {
it('generate multiline v-model directive on custom component', () => {
assertCodegen(
'<my-component v-model="\n test \n" />',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l"></my-component>`
`<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l"></my-component>`
)
})
......@@ -558,7 +558,7 @@ describe('mp:compiler', () => {
it('generate component', () => {
assertCodegen(
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
`<my-component vue-id="1" name="mycomponent1" msg="{{msg}}" data-event-opts="{{[['^notify',[['onNotify']]]]}}" bind:notify="__e" bind:__l="__l" vue-slots="{{['default']}}"><view class="_div">hi</view></my-component>`
`<my-component vue-id="551070e6-1" name="mycomponent1" msg="{{msg}}" data-event-opts="{{[['^notify',[['onNotify']]]]}}" bind:notify="__e" bind:__l="__l" vue-slots="{{['default']}}"><view class="_div">hi</view></my-component>`
// `with(this){if(!$mp.events){$mp.events=__get_event({"e0":{on:{"notify":onNotify},component:true}})}}`
)
})
......@@ -573,7 +573,7 @@ describe('mp:compiler', () => {
it('generate is attribute', () => {
assertCodegen(
'<div is="component1"></div>',
'<component1 vue-id="1" bind:__l="__l"></component1>'
'<component1 vue-id="551070e6-1" bind:__l="__l"></component1>'
)
// assertCodegen(
// '<div :is="component1"></div>',
......@@ -582,7 +582,7 @@ describe('mp:compiler', () => {
// maybe a component and normalize type should be 1
assertCodegen(
'<div><div is="component1"></div></div>',
'<view class="_div"><component1 vue-id="1" bind:__l="__l"></component1></view>'
'<view class="_div"><component1 vue-id="551070e6-1" bind:__l="__l"></component1></view>'
)
})
......@@ -619,7 +619,7 @@ describe('mp:compiler', () => {
// normalize type: 2
assertCodegen(
'<div><child></child><template v-for="item in list">{{ item }}</template></div>',
`<view class="_div"><child vue-id="1" bind:__l="__l"></child><block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__">{{item}}</block></view>`
`<view class="_div"><child vue-id="551070e6-1" bind:__l="__l"></child><block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__">{{item}}</block></view>`
)
})
......@@ -662,7 +662,7 @@ describe('mp:compiler', () => {
it('should compile single v-for component inside template', () => {
assertCodegen(
`<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`,
`<view class="_div"><block wx:if="{{ok}}"><block wx:for="{{1}}" wx:for-item="i" wx:for-index="__i0__" wx:key="*this"><foo vue-id="{{'1-'+__i0__}}" bind:__l="__l"></foo></block></block></view>`
`<view class="_div"><block wx:if="{{ok}}"><block wx:for="{{1}}" wx:for-item="i" wx:for-index="__i0__" wx:key="*this"><foo vue-id="{{'551070e6-1-'+__i0__}}" bind:__l="__l"></foo></block></block></view>`
)
})
})
const path = require('path')
const BuiltinModule = require('module')
// Guard against poorly mocked module constructors
const Module = module.constructor.length > 1
? module.constructor
: BuiltinModule
const oldResolveFilename = Module._resolveFilename
Module._resolveFilename = function (request, parentModule, isMain, options) {
if (request.indexOf('@dcloudio') === 0) {
request = request.replace('@dcloudio', scopedPath)
}
return oldResolveFilename.call(this, request, parentModule, isMain, options)
}
const scopedPath = path.resolve(__dirname, '../../')
const compiler = require('../lib')
const res = compiler.compile(
`
<div><template v-for="item in items">text</template></div>
<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>
`, {
miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml',
......@@ -15,7 +33,7 @@ const res = compiler.compile(
platform: 'mp-weixin'
},
filterModules: ['swipe'],
service: true,
// service: true,
view: true
})
......
......@@ -18,6 +18,10 @@ function parseIs (el, genVar) {
}
}
function isProcessed (exp) {
return String(exp).indexOf('_$') === 0
}
// 当根节点是由if,elseif,else组成,会调用多次parseIf来解析root
function parseIf (el, createGenVar, isScopedSlot) {
if (!el.if) {
return
......@@ -26,11 +30,13 @@ function parseIf (el, createGenVar, isScopedSlot) {
isScopedSlot = false
}
el.ifConditions.forEach(con => {
if (isVar(con.exp)) {
if (!isProcessed(con.exp) && isVar(con.exp)) {
con.exp = createGenVar(con.block.attrsMap[ID], isScopedSlot)(con.block.elseif ? V_ELSE_IF : V_IF, con.exp)
}
})
el.if = createGenVar(el.attrsMap[ID], isScopedSlot)(V_IF, el.if)
if (!isProcessed(el.if)) {
el.if = createGenVar(el.attrsMap[ID], isScopedSlot)(V_IF, el.if)
}
}
function parseFor (el, createGenVar, isScopedSlot, fill = false) {
......
......@@ -43,7 +43,7 @@ module.exports = function parseText (
}
// tag token
const exp = parseFilters(match[1].trim())
tokens.push(`(${state.genVar('t' + (state.index++), '_s(' + exp + ')')})`)
tokens.push(`(${state.genVar('t' + (state.childIndex) + '-' + (state.index++), '_s(' + exp + ')')})`)
rawTokens.push({
'@binding': exp
})
......
......@@ -92,7 +92,11 @@ function checkAutoFill (el) {
el.tag === 'template' ||
el.tag === 'block'
) &&
!el.children.find(child => child.type === 1)
!el.children.find(child =>
child.type === 1 &&
child.tag !== 'template' &&
child.tag !== 'block'
)
) {
return true
}
......@@ -115,6 +119,7 @@ function transformNode (el, parent, state, isScopedSlot) {
pid = getNewId(pid, '_si')
}
return parseText(el, parent, {
childIndex: state.childIndex || 0,
index: 0,
service: true,
// <uni-popup>{{content}}</uni-popup>
......@@ -152,6 +157,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function postTransformNode (el, options) {
if (!el.parent) { // 从根节点开始递归处理
if (options.root) { // 当根节点是由if,elseif,else组成
parseIf(options.root, createGenVar)
} else {
options.root = el
}
traverseNode(el, false, {
forIteratorId: 0,
transformNode,
......
......@@ -105,7 +105,7 @@ function updateForIterator (el, state) {
function updateForEleId (el, state) {
updateForIterator(el, state)
if (el.for) {
const it = el.$parentIterator3 ? (el.$parentIterator3 + '+' + el.iterator3) : el.iterator3
const it = el.$parentIterator3 ? (el.$parentIterator3 + '+' + "'-'" + '+' + el.iterator3) : el.iterator3
updateEleId(el, it, state)
}
}
......@@ -194,11 +194,18 @@ function hasOwn (obj, key) {
function traverseNode (el, parent, state, isScopedSlot) {
state.transformNode(el, parent, state, isScopedSlot)
el.children && el.children.forEach(child => traverseNode(child, el, state, isScopedSlot))
el.children && el.children.forEach((child, index) => {
state.childIndex = index
traverseNode(child, el, state, isScopedSlot)
})
el.ifConditions && el.ifConditions.forEach((con, index) => {
index !== 0 && traverseNode(con.block, el, state, isScopedSlot)
if (index !== 0) {
state.childIndex = index
traverseNode(con.block, el, state, isScopedSlot)
}
})
el.scopedSlots && Object.values(el.scopedSlots).forEach(slot => {
el.scopedSlots && Object.values(el.scopedSlots).forEach((slot, index) => {
state.childIndex = index
slot.slotScope = `${slot.slotScope}, _svm, _si`
traverseNode(slot, el, state, true)
})
......
......@@ -114,7 +114,8 @@ function transformNode (el, parent, state, isScopedSlot) {
if (isScopedSlot && String(pid).indexOf('_si') === -1) {
pid = getNewId(pid, '_si')
}
return parseText(el, parent, {
return parseText(el, parent, {
childIndex: state.childIndex || 0,
index: 0,
view: true,
// <uni-popup>{{content}}</uni-popup>
......@@ -155,6 +156,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function postTransformNode (el, options) {
if (!el.parent) { // 从根节点开始递归处理
if (options.root) { // 当根节点是由if,elseif,else组成
parseIf(options.root, createGenVar)
} else {
options.root = el
}
traverseNode(el, false, {
forIteratorId: 0,
transformNode,
......@@ -209,7 +215,7 @@ function handleViewEvents (events) {
function genVModel (el, isScopedSlot) {
if (el.model) {
el.model.value = createGenVar(el.attrsMap[ID], isScopedSlot)('v-model', el.model.value)
if (el.tag === 'v-uni-input' || el.tag === 'v-uni-textarea') {
if ((el.tag === 'v-uni-input' || el.tag === 'v-uni-textarea') && !(el.events && el.events.input)) {
el.model.callback = `function($$v){$handleVModelEvent(${el.attrsMap[ID]},$$v)}`
} else {
el.model.callback = `function(){}`
......
const path = require('path')
const {
hyphenate,
isComponent
} = require('./util')
......@@ -47,7 +48,8 @@ function updateMPUsingAutoImportComponents (autoComponents, options) {
name,
source
}) => {
usingAutoImportComponents[name] = '/' + formatSource(source)
// 自定义组件统一格式化为 kebab-case
usingAutoImportComponents[hyphenate(name)] = '/' + formatSource(source)
})
updateUsingAutoImportComponents(resourcePath, usingAutoImportComponents) // 更新json
}
......
const path = require('path')
const hash = require('hash-sum')
const parser = require('@babel/parser')
const {
......@@ -95,6 +95,11 @@ module.exports = {
options.mp.scopeId = options.scopeId
options.mp.resourcePath = options.resourcePath
if (options.resourcePath) {
options.mp.hashId = hash(options.resourcePath)
} else {
options.mp.hashId = ''
}
options.mp.globalUsingComponents = options.globalUsingComponents || Object.create(null)
......
......@@ -12,7 +12,7 @@ module.exports = {
warn
}) {
if (process.env.UNI_PLATFORM === 'app-plus' && el.tag === 'ad') {
warn("app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599")
warn('app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599')
}
if (el.tag === 'slot' && !el.attrsMap['name']) {
el.attrsList.push({
......
......@@ -58,7 +58,8 @@ function addVueId (path, state) {
if (!state.options.hasOwnProperty('$vueId')) {
state.options.$vueId = 1
}
const vueId = String(state.options.$vueId++)
const hashId = state.options.hashId
const vueId = (hashId ? (hashId + '-') : '') + (state.options.$vueId++)
let value
......
......@@ -176,7 +176,7 @@ function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
const tags = require('../../uni-cli-shared/lib/tags')
const tags = require('@dcloudio/uni-cli-shared/lib/tags')
const {
getTagName
......
{
"name": "@dcloudio/uni-template-compiler",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-template-compiler",
"main": "lib/index.js",
"repository": {
......
......@@ -12,7 +12,10 @@ const {
getTemplatePath
} = require('@dcloudio/uni-cli-shared')
const WebpackAppPlusNVuePlugin = require('../packages/webpack-app-plus-nvue-plugin')
const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3
? require('../packages/webpack-app-plus-plugin')
: require('../packages/webpack-app-plus-nvue-plugin')
const WebpackErrorsPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-errors-plugin')
const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new')
......@@ -36,7 +39,11 @@ const uniPath = process.env.UNI_USING_V8
? '../packages/uni-app-plus-nvue-v8/dist/index.js'
: '../packages/uni-app-plus-nvue/dist/index.js'
const provide = {}
const uniCloudPath = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js')
const provide = {
'uniCloud': [uniCloudPath, 'default']
}
if (process.env.UNI_USING_V3 || process.env.UNI_USING_NATIVE) {
provide['uni.getCurrentSubNVue'] = [path.resolve(__dirname,
......@@ -68,7 +75,9 @@ const plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM)
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
}
}),
new webpack.BannerPlugin({
......
{
"name": "@dcloudio/vue-cli-plugin-hbuilderx",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "HBuilderX plugin for vue-cli 3",
"main": "index.js",
"repository": {
......
......@@ -6,14 +6,18 @@ const {
done
} = require('@vue/cli-shared-utils')
let nvueCompiled = true
let serviceCompiled = true
let viewCompiled = true
const nvueChangedFiles = []
const serviceChangedFiles = []
const viewChangedFiles = []
let isFirst = true
let compiling = false
class WebpackAppPlusPlugin {
apply(compiler) {
if (process.env.UNI_USING_V3) {
......@@ -21,20 +25,27 @@ class WebpackAppPlusPlugin {
const chunkVersions = {}
const entry = compiler.options.entry()
const isAppService = entry['app-service']
const isAppView = entry['app-view']
const isAppService = !!entry['app-service']
const isAppView = !!entry['app-view']
const isAppNVue = !isAppService && !isAppView
compiler.hooks.invalid.tap('WebpackAppPlusPlugin', (fileName, changeTime) => {
if (!compiling) {
compiling = true
console.log('开始差量编译...')
}
})
compiler.hooks.beforeCompile.tapAsync('WebpackAppPlusPlugin', (params, callback) => {
isAppNVue && (nvueCompiled = false)
isAppService && (serviceCompiled = false)
isAppView && (viewCompiled = false)
callback()
})
compiler.hooks.emit.tapAsync('WebpackAppPlusPlugin', (compilation, callback) => {
isAppService && (serviceChangedFiles.length = 0)
isAppView && (viewChangedFiles.length = 0)
const changedChunks = compilation.chunks.filter(chunk => {
const oldVersion = chunkVersions[chunk.name]
chunkVersions[chunk.name] = chunk.hash
......@@ -47,6 +58,8 @@ class WebpackAppPlusPlugin {
!serviceChangedFiles.includes(file) && (serviceChangedFiles.push(file))
} else if (isAppView) {
!viewChangedFiles.includes(file) && (viewChangedFiles.push(file))
} else if (isAppNVue) {
!nvueChangedFiles.includes(file) && (nvueChangedFiles.push(file))
}
})
}
......@@ -56,14 +69,23 @@ class WebpackAppPlusPlugin {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
isAppNVue && (nvueCompiled = true)
isAppService && (serviceCompiled = true)
isAppView && (viewCompiled = true)
if (serviceCompiled && viewCompiled) {
const changedFiles = [...new Set([...serviceChangedFiles, ...viewChangedFiles])]
if (serviceCompiled && viewCompiled && nvueCompiled) {
if (process.env.NODE_ENV === 'development') {
const changedFiles = [...new Set([
...serviceChangedFiles,
...viewChangedFiles,
...nvueChangedFiles
])]
if (!isFirst && changedFiles.length > 0) {
done(`Build complete. FILES:` + JSON.stringify(changedFiles))
if (serviceChangedFiles.length === 0 && viewChangedFiles.length === 0) {
// 仅 nvue 页面发生变化
done(`Build complete. PAGES:` + JSON.stringify(changedFiles))
} else {
done(`Build complete. FILES:` + JSON.stringify(changedFiles))
}
} else {
done(`Build complete. Watching for changes...`)
}
......@@ -71,8 +93,11 @@ class WebpackAppPlusPlugin {
} else {
done(`Build complete. `)
}
nvueChangedFiles.length = 0
serviceChangedFiles.length = 0
viewChangedFiles.length = 0
compiling = false
}
resolve()
})
})
......
{
"name": "@dcloudio/vue-cli-plugin-uni-optimize",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js",
"repository": {
......
......@@ -64,6 +64,9 @@ function getWebpackConfig (api, args, options) {
})
} else {
modifyConfig(webpackConfig, config => {
if (!config.optimization) {
config.optimization = {}
}
config.optimization.namedModules = false
})
}
......@@ -77,11 +80,11 @@ function getWebpackConfigs (api, args, options) {
const pluginOptions = (options.pluginOptions || (options.pluginOptions = {}))
pluginOptions['uni-app-plus'] = {
service: true
}
}
options.publicPath = '/'
const serviceWebpackConfig = getWebpackConfig(api, args, options)
delete pluginOptions['uni-app-plus']['service']
pluginOptions['uni-app-plus']['view'] = true
pluginOptions['uni-app-plus']['view'] = true
options.publicPath = './'
const viewWebpackConfig = getWebpackConfig(api, args, options)
return [serviceWebpackConfig, viewWebpackConfig]
......@@ -104,7 +107,7 @@ async function build (args, api, options) {
log()
if (!runByHBuilderX && !runByAliIde) {
logWithSpinner(`开始编译当前项目至 ${process.env.UNI_PLATFORM} 平台...`)
logWithSpinner(`开始编译当前项目至 ${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM} 平台...`)
}
const targetDir = api.resolve(options.outputDir)
......
......@@ -101,7 +101,7 @@ module.exports = (api, options) => {
// inject dev & hot-reload middleware entries
if (!isProduction) {
const sockjsUrl = publicUrl
// explicitly configured via devServer.public
// explicitly configured via devServer.public
? `?${publicUrl}/sockjs-node`
: isInContainer
// can't infer public netowrk url if inside a container...
......@@ -163,7 +163,7 @@ module.exports = (api, options) => {
// this works with vue-devtools & @vue/cli-overlay
app.use('/__open-in-editor', launchEditorMiddleware(() => console.log(
`To specify an editor, sepcify the EDITOR env variable or ` +
`add "editor" field to your Vue project config.\n`
`add "editor" field to your Vue project config.\n`
)))
// allow other plugins to register middlewares, e.g. PWA
api.service.devServerConfigFns.forEach(fn => fn(app, server))
......@@ -173,7 +173,7 @@ module.exports = (api, options) => {
}
}))
;
;
['SIGINT', 'SIGTERM'].forEach(signal => {
process.on(signal, () => {
server.close(() => {
......@@ -250,6 +250,11 @@ module.exports = (api, options) => {
isFirstCompile = false
if (!isProduction) {
if (process.UNI_CLOUD) {
console.warn(
`当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5`
)
}
// const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : `npm run build`
// console.log(` Note that the development build is not optimized.`)
// console.log(` To create a production build, run ${chalk.cyan(buildCommand)}.`)
......@@ -289,6 +294,10 @@ module.exports = (api, options) => {
}
})
if (server.showStatus) {
server.showStatus = function () {}
}
server.listen(port, host, err => {
if (err) {
reject(err)
......
......@@ -14,13 +14,15 @@ module.exports = (api, options, rootOptions) => {
'dev:mp-weixin': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch',
'dev:mp-baidu': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch',
'dev:mp-alipay': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch',
'dev:mp-toutiao': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch',
'dev:mp-toutiao': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch',
'dev:mp-360': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch',
'build:h5': 'cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build',
'build:mp-qq': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build',
'build:mp-weixin': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build',
'build:mp-baidu': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build',
'build:mp-alipay': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build',
'build:mp-toutiao': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build',
'build:mp-toutiao': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build',
'build:mp-360': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build',
'dev:custom': 'cross-env NODE_ENV=development uniapp-cli custom',
'build:custom': 'cross-env NODE_ENV=production uniapp-cli custom'
},
......
......@@ -24,6 +24,8 @@ const {
const runtimePath = '@dcloudio/uni-mp-weixin/dist/mp.js'
const wxsPath = '@dcloudio/uni-mp-weixin/dist/wxs.js'
const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/index.js')
const cryptoPath = path.resolve(__dirname, '../crypto.js')
function getProvides (isAppService) {
if (isAppService) {
......@@ -35,7 +37,11 @@ function getProvides (isAppService) {
'Component': [runtimePath, 'Component'],
'Behavior': [runtimePath, 'Behavior'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp']
'getRegExp': [wxsPath, 'getRegExp'],
'uniCloud': [uniCloudPath, 'default'],
'crypto': [cryptoPath, 'default'],
'window.crypto': [cryptoPath, 'default'],
'global.crypto': [cryptoPath, 'default']
}
}
return { // app-view
......@@ -71,12 +77,12 @@ const v3 = {
webpackConfig.optimization.runtimeChunk = {
name: 'app-config'
}
webpackConfig.optimization.splitChunks = require('../split-chunks')()
} else if (isAppView) {
webpackConfig.optimization.runtimeChunk = false
webpackConfig.optimization.splitChunks = false
}
webpackConfig.optimization.splitChunks = false
let devtool = false
if (isAppService && process.env.NODE_ENV !== 'production') {
......@@ -108,6 +114,15 @@ const v3 = {
}]
})
if (isAppService) {
rules.push({
test: [/\.css$/, /\.p(ost)?css$/, /\.scss$/, /\.sass$/, /\.less$/, /\.styl(us)?$/],
use: [{
loader: path.resolve(__dirname, '../../packages/webpack-uni-app-loader/service/style.js')
}]
})
}
const entry = {}
if (isAppService) {
entry['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
......@@ -117,7 +132,7 @@ const v3 = {
return {
devtool,
mode: process.env.NODE_ENV,
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
externals: {
vue: 'Vue'
},
......@@ -279,6 +294,12 @@ const v3 = {
}
}
if (isAppService) { // service 层移除 css 相关
['css', 'postcss', 'scss', 'sass', 'less', 'stylus'].forEach(cssLang => {
webpackConfig.module.rules.delete(cssLang)
})
}
webpackConfig.plugins.delete('hmr')
webpackConfig.plugins.delete('html')
webpackConfig.plugins.delete('copy')
......
......@@ -19,16 +19,16 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
} = require('@dcloudio/uni-cli-shared')
return function (webpackConfig) {
// 处理静态资源 limit
const staticTypes = ['images', 'media', 'fonts']
staticTypes.forEach(staticType => {
webpackConfig.module
.rule(staticType)
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, {
limit: 40960
}))
// 处理静态资源 limit
const staticTypes = ['images', 'media', 'fonts']
staticTypes.forEach(staticType => {
webpackConfig.module
.rule(staticType)
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, {
limit: 40960
}))
})
// 条件编译 vue 文件统一直接过滤html,js,css三种类型,单独资源文件引用各自过滤
......@@ -94,7 +94,9 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
webpackConfig
.plugin('uni-define')
.use(require.resolve('webpack/lib/DefinePlugin'), [{
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM)
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
}])
if (runByHBuilderX) { // 由 HBuilderX 运行时,移除进度,错误
......
......@@ -159,7 +159,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
// js preprocess
updateJsLoader(rawRules, 'foo.js', /^babel-loader/, {
updateJsLoader(rawRules, 'foo.js', /^(.*[/\\])?babel-loader/, {
loader: resolve('packages/webpack-preprocess-loader'),
options: jsPreprocessOptions
})
......@@ -264,4 +264,4 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
}, platformWebpackConfig)
}
}
}
......@@ -12,7 +12,7 @@ export default function formatLog () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key]
}
const type = args.shift()
var type = args.shift()
if (isDebugMode()) {
args.push(args.pop().replace('at ', 'uni-app:///'))
return console[type]['apply'](console, args)
......
......@@ -30,9 +30,11 @@ const {
const runtimePath = '@dcloudio/uni-mp-weixin/dist/mp.js'
const wxsPath = '@dcloudio/uni-mp-weixin/dist/wxs.js'
const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/index.js')
function getProvides () {
return {
'uniCloud': [uniCloudPath, 'default'],
'wx.nextTick': [runtimePath, 'nextTick'],
'Page': [runtimePath, 'Page'],
'Component': [runtimePath, 'Component'],
......@@ -102,13 +104,23 @@ module.exports = {
const beforeCode = (useBuiltIns === 'entry' ? `import '@babel/polyfill';` : '') +
`import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
const qihooCode = process.env.UNI_SUB_PLATFORM === 'mp-360'
? `
import 'uni-touch-emulator';
import qh from 'uni-qh';
global.qh = qh;
global.onAppShow = function(){};
` : ''
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
devtool: process.env.NODE_ENV === 'production' ? false : 'cheap-module-eval-source-map',
resolve: {
extensions: ['.nvue'],
alias: {
'vue-router': resolve('packages/h5-vue-router'),
'uni-h5': require.resolve('@dcloudio/uni-h5')
'uni-h5': require.resolve('@dcloudio/uni-h5'),
'uni-qh': path.resolve(__dirname, 'qh-api.js'),
'uni-touch-emulator': path.resolve(__dirname, 'touch-emulator.js')
}
},
module: {
......@@ -118,7 +130,7 @@ module.exports = {
loader: 'wrap-loader',
options: {
before: [
beforeCode + statCode + getGlobalUsingComponentsCode()
qihooCode + beforeCode + statCode + getGlobalUsingComponentsCode()
]
}
}]
......
此差异已折叠。
此差异已折叠。
......@@ -44,7 +44,9 @@ module.exports = function parseCustomBlocks(descriptor, options) {
block.type === 'renderjs' ||
block.attrs.lang === 'renderjs'
)
) {
) {
block.type = 'renderjs'
block.attrs.lang = 'js'
descriptor.renderjs = preprocessBlock(block)
modules[block.attrs.module] = Object.assign({}, block, {
content: ''
......
module.exports = function(source, map) {
console.warn(
`App平台 v3 模式暂不支持在 js 文件中引用"${this._module && this._module.rawRequest || this.resourcePath}"`
)
return ''
}
{
"name": "@dcloudio/webpack-uni-mp-loader",
"version": "2.0.0-alpha-25720200116004",
"version": "2.0.0-alpha-26420200309002",
"description": "webpack-uni-mp-loader",
"main": "index.js",
"repository": {
......
......@@ -62,14 +62,20 @@ module.exports = function (pagesJson, manifestJson) {
app.subPackages.push(subPackages[root])
})
copyToJson(app, pagesJson, pagesJson2AppJson)
copyToJson(app, pagesJson, pagesJson2AppJson)
const platformJson = manifestJson['mp-alipay'] || {}
if (hasOwn(platformJson, 'plugins')) {
app.plugins = platformJson.plugins
}
if (app.usingComponents) {
updateAppJsonUsingComponents(app.usingComponents)
}
const project = Object.assign({}, manifestJson['mp-alipay'] || {})
delete project.usingComponents
delete project.usingComponents
delete project.plugins
return [{
name: 'app',
......
此差异已折叠。
此差异已折叠。
......@@ -119,7 +119,7 @@ class BackgroundAudioManager {
this._operate('stop')
}
seek (position) {
this._operate('play', {
this._operate('seek', {
currentTime: position
})
}
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册