提交 e737540a 编写于 作者: D DCloud_LXH 提交者: qiang

feat(mp-weixin): 支持微信小程序插件

上级 fae0c2f6
......@@ -28,7 +28,8 @@ module.exports = (api, options) => {
'--minimize': 'Tell webpack to minimize the bundle using the TerserPlugin.',
'--auto-host': 'specify automator host',
'--auto-port': 'specify automator port',
'--subpackage': 'specify subpackage'
'--subpackage': 'specify subpackage',
'--plugin': 'specify plugin'
}
}, async (args) => {
for (const key in defaults) {
......@@ -42,6 +43,10 @@ module.exports = (api, options) => {
process.env.UNI_SUBPACKGE = args.subpackage
}
if (args.plugin && platforms.includes(process.env.UNI_PLATFORM)) {
process.env.UNI_MP_PLUGIN = args.plugin
}
require('./util').initAutomator(args)
args.entry = args.entry || args._[0]
......@@ -190,4 +195,4 @@ async function build (args, api, options) {
module.exports.defaultModes = {
'uni-build': process.env.NODE_ENV
}
}
......@@ -197,7 +197,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if (!isAppView) { // app-plus view不需要copy
plugins.push(new CopyWebpackPlugin(getCopyWebpackPluginOptions(manifestPlatformOptions, vueOptions)))
}
if (!process.env.UNI_SUBPACKGE) {
if (!process.env.UNI_SUBPACKGE || !process.env.UNI_MP_PLUGIN) {
try {
const automatorJson = require.resolve('@dcloudio/uni-automator/dist/automator.json')
plugins.push(new CopyWebpackPlugin([{
......
......@@ -38,6 +38,8 @@ function getProvides () {
if (process.env.UNI_USING_COMPONENTS) {
if (process.env.UNI_SUBPACKGE) {
provides.createApp = [uniPath, 'createSubpackageApp']
} else if (process.env.UNI_MP_PLUGIN) {
provides.createApp = [uniPath, 'createPlugin']
} else {
provides.createApp = [uniPath, 'createApp']
}
......@@ -126,11 +128,11 @@ class PreprocessAssetsPlugin {
function initSubpackageConfig (webpackConfig, vueOptions) {
if (process.env.UNI_OUTPUT_DEFAULT_DIR === process.env.UNI_OUTPUT_DIR) { // 未自定义output
process.env.UNI_OUTPUT_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, process.env.UNI_SUBPACKGE)
process.env.UNI_OUTPUT_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN))
}
vueOptions.outputDir = process.env.UNI_OUTPUT_DIR
webpackConfig.output.path(process.env.UNI_OUTPUT_DIR)
webpackConfig.output.jsonpFunction('webpackJsonp_' + process.env.UNI_SUBPACKGE)
webpackConfig.output.jsonpFunction('webpackJsonp_' + (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN))
}
module.exports = {
......@@ -162,7 +164,7 @@ module.exports = {
new webpack.ProvidePlugin(getProvides())
]
if (process.env.UNI_SUBPACKGE && process.env.UNI_SUBPACKGE !== 'main') {
if ((process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) && process.env.UNI_SUBPACKGE !== 'main') {
plugins.push(new PreprocessAssetsPlugin())
}
......@@ -272,7 +274,7 @@ module.exports = {
}))
}
if (process.env.UNI_SUBPACKGE) {
if (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) {
initSubpackageConfig(webpackConfig, vueOptions)
}
......
......@@ -184,7 +184,7 @@ module.exports = function generateJson (compilation) {
delete jsonObj.navigationBarShadow
}
if (process.env.UNI_SUBPACKGE && jsonObj.usingComponents) {
if ((process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) && jsonObj.usingComponents) {
jsonObj.usingComponents = normalizeUsingComponents(name, jsonObj.usingComponents)
}
const source = JSON.stringify(jsonObj, null, 2)
......
......@@ -26,8 +26,9 @@ import {
import createApp from './wrapper/create-app'
import createPage from './wrapper/create-page'
import createComponent from './wrapper/create-component'
import createComponent from './wrapper/create-component'
import createSubpackageApp from './wrapper/create-subpackage-app'
import createPlugin from './wrapper/create-plugin'
todos.forEach(todoApi => {
protocols[todoApi] = false
......@@ -115,13 +116,15 @@ if (__PLATFORM__ === 'app-plus') {
__GLOBAL__.createApp = createApp
__GLOBAL__.createPage = createPage
__GLOBAL__.createComponent = createComponent
__GLOBAL__.createSubpackageApp = createSubpackageApp
__GLOBAL__.createSubpackageApp = createSubpackageApp
__GLOBAL__.createPlugin = createPlugin
export {
createApp,
createPage,
createComponent,
createSubpackageApp
createComponent,
createSubpackageApp,
createPlugin
}
export default uni
export default uni
import 'uni-platform/runtime/index'
import {
isFn
} from 'uni-shared'
import parseApp from 'uni-platform/runtime/wrapper/app-parser'
export default function createPlugin (vm) {
const appOptions = parseApp(vm)
if (isFn(appOptions.onShow) && __GLOBAL__.onAppShow) {
__GLOBAL__.onAppShow((...args) => {
appOptions.onShow.apply(vm, args)
})
}
if (isFn(appOptions.onHide) && __GLOBAL__.onAppHide) {
__GLOBAL__.onAppHide((...args) => {
appOptions.onHide.apply(vm, args)
})
}
if (isFn(appOptions.onLaunch)) {
const args = __GLOBAL__.getLaunchOptionsSync && __GLOBAL__.getLaunchOptionsSync()
appOptions.onLaunch.call(vm, args)
}
return vm
}
......@@ -14,7 +14,7 @@ const customize = cached((str) => {
function initTriggerEvent (mpInstance) {
if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'app-plus') {
if (!wx.canIUse('nextTick')) {
if (!wx.canIUse || !wx.canIUse('nextTick')) {
return
}
}
......@@ -49,4 +49,4 @@ if (!MPPage.__$wrappered) {
initHook('created', options)
return MPComponent(options)
}
}
}
......@@ -69,7 +69,7 @@ export default function parseBaseApp (vm, {
delete this.$options.mpType
delete this.$options.mpInstance
if (this.mpType === 'page') { // hack vue-i18n
if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
const app = getApp()
if (app.$vm && app.$vm.$i18n) {
this._i18n = app.$vm.$i18n
......@@ -88,7 +88,7 @@ export default function parseBaseApp (vm, {
return
}
if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq') {
if (!wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
if (wx.canIUse && !wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上')
}
}
......@@ -123,4 +123,4 @@ export default function parseBaseApp (vm, {
initHooks(appOptions, hooks)
return appOptions
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册