提交 6e82d141 编写于 作者: D DCloud_LXH

fix(mp): 1. 修复 小程序插件编译时入口文件判断错误。移除使用 UNI_MP_PLUGIN 定义变量

上级 858a9f13
...@@ -34,7 +34,7 @@ module.exports = (api, options) => { ...@@ -34,7 +34,7 @@ module.exports = (api, options) => {
'--auto-host': 'specify automator host', '--auto-host': 'specify automator host',
'--auto-port': 'specify automator port', '--auto-port': 'specify automator port',
'--subpackage': 'specify subpackage', '--subpackage': 'specify subpackage',
'--plugin': 'specify plugin', '--plugin': 'specify mp plugin',
'--manifest': 'build manifest.json' '--manifest': 'build manifest.json'
} }
}, async (args) => { }, async (args) => {
...@@ -244,17 +244,19 @@ function analysisPluginDir () { ...@@ -244,17 +244,19 @@ function analysisPluginDir () {
const pluginJson = parseJson(fs.readFileSync(pluginJsonPath, 'utf-8'), true) const pluginJson = parseJson(fs.readFileSync(pluginJsonPath, 'utf-8'), true)
// main 入口文件是否存在 // main 入口文件是否存在
process.env.UNI_MP_PLUGIN_MAIN = pluginJson.main if (pluginJson.main) {
const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN process.env.UNI_MP_PLUGIN_MAIN = pluginJson.main
const mainFilePath = path.resolve(process.env.UNI_INPUT_DIR, UNI_MP_PLUGIN_MAIN) const UNI_MP_PLUGIN_MAIN = process.env.UNI_MP_PLUGIN_MAIN
const mainFilePath = path.resolve(process.env.UNI_INPUT_DIR, UNI_MP_PLUGIN_MAIN)
if (UNI_MP_PLUGIN_MAIN && !fs.pathExistsSync(mainFilePath)) {
console.log() if (UNI_MP_PLUGIN_MAIN && !fs.pathExistsSync(mainFilePath)) {
console.error(uniI18n.__('pluginUni.entryDileNoExistsCheckAfterRetry', { console.log()
0: UNI_MP_PLUGIN_MAIN console.error(uniI18n.__('pluginUni.entryDileNoExistsCheckAfterRetry', {
})) 0: UNI_MP_PLUGIN_MAIN
console.log() }))
process.exit(0) console.log()
process.exit(0)
}
} }
} }
......
...@@ -178,11 +178,12 @@ module.exports = { ...@@ -178,11 +178,12 @@ module.exports = {
{ {
const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'; const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx';
[].concat(process.env.UNI_MP_PLUGIN ? process.env.UNI_MP_PLUGIN_MAIN : JSON.parse(process.env [].concat(
.UNI_MP_PLUGIN_EXPORT)) process.env.UNI_MP_PLUGIN
.forEach(fileName => addToUniEntry(fileName)) ? process.env.UNI_MP_PLUGIN_MAIN
beforeCode += : JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT)
`${globalEnv}.__webpack_require_${(process.env.UNI_MP_PLUGIN || 'UNI_MP_PLUGIN').replace(/-/g, '_')}__ = __webpack_require__;` ).forEach(fileName => addToUniEntry(fileName))
beforeCode += `${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
} }
const alias = { // 仅 mp-weixin const alias = { // 仅 mp-weixin
...@@ -319,4 +320,4 @@ module.exports = { ...@@ -319,4 +320,4 @@ module.exports = {
webpackConfig.plugins.delete('preload') webpackConfig.plugins.delete('preload')
webpackConfig.plugins.delete('prefetch') webpackConfig.plugins.delete('prefetch')
} }
} }
...@@ -76,22 +76,22 @@ function addMPPluginRequire (compilation) { ...@@ -76,22 +76,22 @@ function addMPPluginRequire (compilation) {
const needProcess = process.env.UNI_MP_PLUGIN ? name === UNI_MP_PLUGIN_MAIN : UNI_MP_PLUGIN_EXPORT.includes(name) const needProcess = process.env.UNI_MP_PLUGIN ? name === UNI_MP_PLUGIN_MAIN : UNI_MP_PLUGIN_EXPORT.includes(name)
if (needProcess) { if (needProcess) {
const modules = compilation.modules const modules = compilation.modules
const orignalSource = compilation.assets[name].source()
const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx';
const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name)) const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name))
const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === filePath).id const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === filePath).id
const newlineIndex = orignalSource.lastIndexOf('\n')
const newlineIndex = compilation.assets[name].source().lastIndexOf('\n') const source =
orignalSource.substring(0, newlineIndex)
const source = compilation.assets[name].source().substring(0, newlineIndex) + + `\nmodule.exports = ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__('${uniModuleId}');\n`
`\nmodule.exports = ${process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'}.__webpack_require_${(process.env.UNI_MP_PLUGIN || 'UNI_MP_PLUGIN').replace(/-/g, '_')}__('${uniModuleId}');\n` + + orignalSource.substring(newlineIndex + 1)
compilation.assets[name].source().substring(newlineIndex + 1)
compilation.assets[name] = { compilation.assets[name] = {
size () { size() {
return Buffer.byteLength(source, 'utf8') return Buffer.byteLength(source, 'utf8')
}, },
source () { source() {
return source return source
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册