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

refactor(v3): Build complete

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