提交 0c7bb1fa 编写于 作者: D DCloud_LXH

feat(mp): 支付宝小程序支持插件编译

上级 2a823a45
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
"pluginUni.runDebugMode": "Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.", "pluginUni.runDebugMode": "Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.",
"pluginUni.runDebugModeNvue": "Especially the sourcemap of app-nvue has a greater impact", "pluginUni.runDebugModeNvue": "Especially the sourcemap of app-nvue has a greater impact",
"pluginUni.runDebugModeMP": "To officially release, please click the release menu or use the cli release command to release", "pluginUni.runDebugModeMP": "To officially release, please click the release menu or use the cli release command to release",
"pluginUni.compileToMpPluginOnlySupportWeChat": "Compile to mini-program plug-in only supports WeChat mini-program", "pluginUni.compileToMpPluginOnlySupportPlatform": "Compile to mini-program plug-in only supports WeChat mini-program and AliPay mini-program",
"pluginUni.startCompileProjectToPlatform": "Start to compile the current project to the {{0}} {{1}}...", "pluginUni.startCompileProjectToPlatform": "Start to compile the current project to the {{0}} {{1}}...",
"pluginUni.fileNoExistsCheckAfterRetry": "{{0}} file does not exist, please check and try again", "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} file does not exist, please check and try again",
"pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} The entry file does not exist, please check and try again", "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} The entry file does not exist, please check and try again",
...@@ -67,4 +67,4 @@ ...@@ -67,4 +67,4 @@
"pagesLoader.needInPagesNode": "{{0}} needs to be in the pages array", "pagesLoader.needInPagesNode": "{{0}} needs to be in the pages array",
"i18n.fallbackLocale.default": "fallbackLocale is missing in manifest.json, use:{{locale}}", "i18n.fallbackLocale.default": "fallbackLocale is missing in manifest.json, use:{{locale}}",
"i18n.fallbackLocale.missing": "./local/{locale}.json is missing" "i18n.fallbackLocale.missing": "./local/{locale}.json is missing"
} }
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
"pluginUni.runDebugMode": "请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。", "pluginUni.runDebugMode": "请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。",
"pluginUni.runDebugModeNvue": "尤其是app-nvue的sourcemap影响较大", "pluginUni.runDebugModeNvue": "尤其是app-nvue的sourcemap影响较大",
"pluginUni.runDebugModeMP": "若要正式发布,请点击发行菜单或使用cli发布命令进行发布", "pluginUni.runDebugModeMP": "若要正式发布,请点击发行菜单或使用cli发布命令进行发布",
"pluginUni.compileToMpPluginOnlySupportWeChat": "编译到小程序插件只支持微信小程序", "pluginUni.compileToMpPluginOnlySupportPlatform": "编译到小程序插件只支持微信小程序和阿里小程序",
"pluginUni.startCompileProjectToPlatform": "开始编译当前项目至 {{0}} {{1}}...", "pluginUni.startCompileProjectToPlatform": "开始编译当前项目至 {{0}} {{1}}...",
"pluginUni.fileNoExistsCheckAfterRetry": "{{0}} 文件不存在,请检查后重试", "pluginUni.fileNoExistsCheckAfterRetry": "{{0}} 文件不存在,请检查后重试",
"pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} 入口文件不存在,请检查后重试", "pluginUni.entryDileNoExistsCheckAfterRetry": "{{0}} 入口文件不存在,请检查后重试",
...@@ -67,4 +67,4 @@ ...@@ -67,4 +67,4 @@
"pagesLoader.needInPagesNode": "{{0}} 需在 pages 数组中", "pagesLoader.needInPagesNode": "{{0}} 需在 pages 数组中",
"i18n.fallbackLocale.default": "当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{{locale}}", "i18n.fallbackLocale.default": "当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{{locale}}",
"i18n.fallbackLocale.missing": "当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件" "i18n.fallbackLocale.missing": "当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件"
} }
const path = require('path')
const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json')
module.exports = { module.exports = {
options: { options: {
global: 'my', global: 'my',
...@@ -21,6 +24,14 @@ module.exports = { ...@@ -21,6 +24,14 @@ module.exports = {
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/mycomponents') copyOptions.push('uni_modules/' + module + '/mycomponents')
}) })
if (process.env.UNI_MP_PLUGIN) {
copyOptions.push({
from: path.resolve(process.env.UNI_INPUT_DIR, 'plugin.json'),
transform: content => JSON.stringify(parseJson(content.toString(), true))
})
}
return copyOptions return copyOptions
} }
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json')
const COMPONENTS_DIR_NAME = 'wxcomponents' const COMPONENTS_DIR_NAME = 'wxcomponents'
...@@ -31,7 +32,12 @@ module.exports = { ...@@ -31,7 +32,12 @@ module.exports = {
'functional-pages' 'functional-pages'
] ]
if (process.env.UNI_MP_PLUGIN) copyOptions.push('plugin.json') if (process.env.UNI_MP_PLUGIN) {
copyOptions.push({
from: path.resolve(process.env.UNI_INPUT_DIR, 'plugin.json'),
transform: content => JSON.stringify(parseJson(content.toString(), true))
})
}
const workers = platformOptions.workers const workers = platformOptions.workers
workers && copyOptions.push(workers) workers && copyOptions.push(workers)
......
...@@ -2,7 +2,8 @@ const path = require('path') ...@@ -2,7 +2,8 @@ const path = require('path')
const { const {
runByHBuilderX, runByHBuilderX,
isInHBuilderX isInHBuilderX,
parseJson
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const uniI18n = require('@dcloudio/uni-cli-i18n') const uniI18n = require('@dcloudio/uni-cli-i18n')
...@@ -45,13 +46,14 @@ module.exports = (api, options) => { ...@@ -45,13 +46,14 @@ module.exports = (api, options) => {
process.env.UNI_SUBPACKGE = args.subpackage process.env.UNI_SUBPACKGE = args.subpackage
} }
const mpPluginPlatforms = ['mp-weixin', 'mp-alipay']
if (args.plugin) { if (args.plugin) {
if (process.env.UNI_PLATFORM === 'mp-weixin') { if (mpPluginPlatforms.includes(process.env.UNI_PLATFORM)) {
process.env.UNI_MP_PLUGIN = args.plugin process.env.UNI_MP_PLUGIN = args.plugin
analysisPluginDir() analysisPluginDir()
} else { } else {
console.log() console.log()
console.error(uniI18n.__('pluginUni.compileToMpPluginOnlySupportWeChat')) console.error(uniI18n.__('pluginUni.compileToMpPluginOnlySupportPlatform'))
console.log() console.log()
process.exit(0) process.exit(0)
} }
...@@ -224,7 +226,7 @@ function analysisPluginDir () { ...@@ -224,7 +226,7 @@ function analysisPluginDir () {
process.exit(0) process.exit(0)
} }
const pluginJson = require(pluginJsonPath) const pluginJson = parseJson(fs.readFileSync(pluginJsonPath, 'utf-8'), true)
// main 入口文件是否存在 // main 入口文件是否存在
process.env.UNI_MP_PLUGIN_MAIN = pluginJson.main process.env.UNI_MP_PLUGIN_MAIN = pluginJson.main
......
...@@ -84,11 +84,13 @@ function processWxss (name, assets) { ...@@ -84,11 +84,13 @@ function processWxss (name, assets) {
} }
} }
const parseRequirePath = path => path.startsWith('common') ? `./${path}` : path
function procssJs (name, assets, hasVendor) { function procssJs (name, assets, hasVendor) {
const dirname = path.dirname(name) const dirname = path.dirname(name)
const runtimeJsCode = `require('${normalizePath(path.relative(dirname, 'common/runtime.js'))}');` const runtimeJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/runtime.js')))}');`
const vendorJsCode = hasVendor ? `require('${normalizePath(path.relative(dirname, 'common/vendor.js'))}');` : '' const vendorJsCode = hasVendor ? `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/vendor.js')))}');` : ''
const mainJsCode = `require('${normalizePath(path.relative(dirname, 'common/main.js'))}');` const mainJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/main.js')))}');`
const code = `${runtimeJsCode}${vendorJsCode}${mainJsCode}` + assets[name].source().toString() const code = `${runtimeJsCode}${vendorJsCode}${mainJsCode}` + assets[name].source().toString()
assets[name] = { assets[name] = {
size () { size () {
...@@ -172,7 +174,7 @@ module.exports = { ...@@ -172,7 +174,7 @@ module.exports = {
if (process.env.UNI_MP_PLUGIN) { if (process.env.UNI_MP_PLUGIN) {
// 小程序插件入口使用 // 小程序插件入口使用
// packages\webpack-uni-mp-loader\lib\plugin\index-new.js -> addMPPluginRequire // packages\webpack-uni-mp-loader\lib\plugin\index-new.js -> addMPPluginRequire
beforeCode += `wx.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__ = __webpack_require__;` beforeCode += `${process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'}.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__ = __webpack_require__;`
const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN
if (UNI_MP_PLUGIN_MAIN) { if (UNI_MP_PLUGIN_MAIN) {
...@@ -309,4 +311,4 @@ module.exports = { ...@@ -309,4 +311,4 @@ module.exports = {
webpackConfig.plugins.delete('preload') webpackConfig.plugins.delete('preload')
webpackConfig.plugins.delete('prefetch') webpackConfig.plugins.delete('prefetch')
} }
} }
...@@ -80,7 +80,7 @@ function addMPPluginRequire (compilation) { ...@@ -80,7 +80,7 @@ function addMPPluginRequire (compilation) {
const newlineIndex = compilation.assets[name].source().lastIndexOf('\n') const newlineIndex = compilation.assets[name].source().lastIndexOf('\n')
const source = compilation.assets[name].source().substring(0, newlineIndex) + const source = compilation.assets[name].source().substring(0, newlineIndex) +
`\nmodule.exports = wx.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__('${uniModuleId}');\n` + `\nmodule.exports = ${process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'}.__webpack_require_${process.env.UNI_MP_PLUGIN.replace(/-/g, '_')}__('${uniModuleId}');\n` +
compilation.assets[name].source().substring(newlineIndex + 1) compilation.assets[name].source().substring(newlineIndex + 1)
compilation.assets[name] = { compilation.assets[name] = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册