提交 4c3c76c5 编写于 作者: fxy060608's avatar fxy060608

refactor(v3): Build complete

上级 f4175f62
......@@ -41,7 +41,7 @@ service.run('build', {
entry,
clean: !process.env.UNI_VIEW,
mode: process.env.NODE_ENV
}).then(function() {
}).then(function () {
if (
process.env.UNI_WATCH !== 'true' &&
process.env.UNI_UI !== 'true' &&
......@@ -62,7 +62,7 @@ if (process.env.UNI_PLATFORM === 'h5' && process.env.UNI_WATCH === 'false') {
const packageJsonPath = path.join(packagePath, 'package.json')
del(path.join(packagePath, '{lib,src}'))
.then(() => {
copy([path.join(__dirname, '../{lib,src}/**/*')], packagePath, function(err, file) {
copy([path.join(__dirname, '../{lib,src}/**/*')], packagePath, function (err, file) {
if (err) {
throw err
}
......
......@@ -3577,10 +3577,12 @@ var serviceContext = (function () {
}
}
const ANI_SHOW = plus.os.name === 'Android' && parseInt(plus.os.version) < 6 ? 'slide-in-right' : 'pop-in';
const ANI_DURATION = 300;
const ANI_CLOSE = 'pop-out';
const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version) < 6;
const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in';
const ANI_DURATION = 300;
const ANI_CLOSE = downgrade ? 'slide-out-right' : 'pop-out';
const TITLEBAR_HEIGHT = 44;
......
......@@ -1952,7 +1952,7 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
};
} else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
// Fallback to setImmediate.
// Techinically it leverages the (macro) task queue,
// Technically it leverages the (macro) task queue,
// but it is still a better choice than setTimeout.
timerFunc = function () {
setImmediate(flushCallbacks);
......
此差异已折叠。
......@@ -5,53 +5,73 @@ const {
log,
done
} = require('@vue/cli-shared-utils')
let serviceCompiled = true
let viewCompiled = true
class WebpackAppPlusPlugin {
apply(compiler) {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
if (process.env.UNI_USING_V3) {
const isAppService = compiler.options.entry['app-service']
const isAppView = compiler.options.entry['app-view']
compiler.hooks.beforeCompile.tapAsync('WebpackAppPlusPlugin', (params, callback) => {
isAppService && (serviceCompiled = false)
isAppView && (viewCompiled = false)
callback()
})
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
isAppService && (serviceCompiled = true)
isAppView && (viewCompiled = true)
if (process.env.UNI_USING_NATIVE) {
return resolve()
}
if (process.env.UNI_USING_V3) {
log()
if (process.env.NODE_ENV === 'development') {
done(`Build complete. Watching for changes...`)
} else {
done(`Build complete. `)
if (serviceCompiled && viewCompiled) {
if (process.env.NODE_ENV === 'development') {
done(`Build complete. Watching for changes...`)
} else {
done(`Build complete. `)
}
}
return resolve()
}
const callback = function() {
fs.copyFileSync(path.resolve(process.env.UNI_OUTPUT_TMP_DIR,
'manifest.json'),
path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'))
log()
if (process.env.NODE_ENV === 'development') {
done(`Build complete. Watching for changes...`)
} else {
done(`Build complete. `)
}
resolve()
}
// Copy manifest.json
const wxmp = require(path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/lib'))
try {
wxmp(
process.env.UNI_OUTPUT_TMP_DIR,
process.env.UNI_OUTPUT_DIR,
path.basename(process.env.UNI_INPUT_DIR),
callback
)
} catch (e) {
resolve()
console.error(e.message)
}
})
})
} else {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
if (process.env.UNI_USING_NATIVE) {
return resolve()
}
const callback = function() {
fs.copyFileSync(path.resolve(process.env.UNI_OUTPUT_TMP_DIR,
'manifest.json'),
path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'))
log()
if (process.env.NODE_ENV === 'development') {
done(`Build complete. Watching for changes...`)
} else {
done(`Build complete. `)
}
resolve()
}
// Copy manifest.json
const wxmp = require(path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/lib'))
try {
wxmp(
process.env.UNI_OUTPUT_TMP_DIR,
process.env.UNI_OUTPUT_DIR,
path.basename(process.env.UNI_INPUT_DIR),
callback
)
} catch (e) {
resolve()
console.error(e.message)
}
})
})
})
}
}
}
......
......@@ -56,6 +56,13 @@ const v3 = {
'../../packages/webpack-uni-app-loader/view/script')
}]
})
}
const entry = {}
if (isAppService) {
entry['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
} else if (isAppView) {
entry['app-view'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
}
return {
......@@ -64,15 +71,7 @@ const v3 = {
externals: {
vue: 'Vue'
},
entry () {
const entry = {}
if (isAppService) {
entry['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
} else if (isAppView) {
entry['app-view'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
}
return entry
},
entry,
output: {
filename: '[name].js',
chunkFilename: '[id].js',
......
......@@ -16,17 +16,17 @@ import {
diff
} from './diff'
export function initData(Vue) {
export function initData (Vue) {
Vue.prototype._$s = setData
Vue.prototype._$i = setIfData
Vue.prototype._$f = setForData
Vue.prototype._$e = setElseIfData
Vue.prototype._$setData = function setData(type, data) {
Vue.prototype._$setData = function setData (type, data) {
this._$vd.push(type, this._$id, data)
}
Vue.prototype._$mounted = function mounted() {
Vue.prototype._$mounted = function mounted () {
if (!this._$vd) {
return
}
......@@ -39,7 +39,7 @@ export function initData(Vue) {
}
}
Vue.prototype._$updated = function updated() {
Vue.prototype._$updated = function updated () {
if (!this._$vd) {
return
}
......@@ -50,13 +50,13 @@ export function initData(Vue) {
}
Object.defineProperty(Vue.prototype, '_$vd', {
get() {
get () {
return this.$root._$vdomSync
}
})
Vue.mixin({
beforeCreate() {
beforeCreate () {
if (this.$options.mpType) {
this.mpType = this.$options.mpType
}
......@@ -77,7 +77,7 @@ export function initData(Vue) {
this._$newData = Object.create(null)
}
},
beforeUpdate() {
beforeUpdate () {
if (!this._$vd) {
return
}
......@@ -86,7 +86,7 @@ export function initData(Vue) {
console.log(`[${this._$id}] beforeUpdate ` + Date.now())
this._$newData = Object.create(null)
},
beforeDestroy() {
beforeDestroy () {
if (!this._$vd) {
return
}
......@@ -96,7 +96,7 @@ export function initData(Vue) {
})
}
function setData(id, name, value) {
function setData (id, name, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {})
if (typeof name !== 'string') {
......@@ -112,7 +112,7 @@ function setData(id, name, value) {
return (diffData[name] = value)
}
function setForData(id, value) {
function setForData (id, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {})
const vForData = diffData['v-for'] || (diffData['v-for'] = [])
......@@ -133,10 +133,10 @@ function setForData(id, value) {
return key
}
function setIfData(id, value) {
function setIfData (id, value) {
return ((this._$newData[id] || (this._$newData[id] = {}))['v-if'] = value)
}
function setElseIfData(id, value) {
function setElseIfData (id, value) {
return ((this._$newData[id] || (this._$newData[id] = {}))['v-else-if'] = value)
}
......@@ -12,12 +12,12 @@ import {
registerWebviewUIEvent
} from '../subscribe-handlers'
function noop() {}
function noop () {}
const callbacks = [] // 数据同步 callback
export class VDomSync {
constructor(pageId, pagePath) {
constructor (pageId, pagePath) {
this.pageId = pageId
this.pagePath = pagePath
this.batchData = []
......@@ -29,7 +29,7 @@ export class VDomSync {
this._init()
}
_init() {
_init () {
UniServiceJSBridge.subscribe(VD_SYNC_CALLBACK, () => {
const copies = callbacks.slice(0)
callbacks.length = 0
......@@ -56,43 +56,43 @@ export class VDomSync {
})
}
addMountedVm(vm) {
addMountedVm (vm) {
vm._$mounted() // 触发vd数据同步
this.addCallback(function mounted() {
this.addCallback(function mounted () {
vm.__call_hook('mounted')
})
}
addUpdatedVm(vm) {
addUpdatedVm (vm) {
vm._$updated() // 触发vd数据同步
this.addCallback(function mounted() {
this.addCallback(function mounted () {
vm.__call_hook('updated')
})
}
addCallback(callback) {
addCallback (callback) {
isFn(callback) && callbacks.push(callback)
}
getVm(id) {
getVm (id) {
return this.vms[id]
}
addVm(vm) {
addVm (vm) {
this.vms[vm._$id] = vm
}
removeVm(vm) {
removeVm (vm) {
delete this.vms[vm._$id]
}
addEvent(cid, nid, name, handler) {
addEvent (cid, nid, name, handler) {
const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null))
const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null));
(nHandlers[name] || (nHandlers[name] = [])).push(handler)
}
removeEvent(cid, nid, name, handler) {
removeEvent (cid, nid, name, handler) {
const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null))
const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null))
const eHandlers = nHandlers[name]
......@@ -104,11 +104,11 @@ export class VDomSync {
}
}
push(type, nodeId, data) {
push (type, nodeId, data) {
this.batchData.push([type, [nodeId, data]])
}
flush() {
flush () {
if (!this.initialized) {
this.initialized = true
this.batchData.push([PAGE_CREATED, [this.pageId, this.pagePath]])
......@@ -124,7 +124,7 @@ export class VDomSync {
}
}
destroy() {
destroy () {
this.batchData.length = 0
this.vms = Object.create(null)
this.initialized = false
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册