提交 2d6b4879 编写于 作者: 雪洛's avatar 雪洛

feat: auto import uniCloud once

上级 2409ca10
...@@ -63,8 +63,11 @@ const v3 = { ...@@ -63,8 +63,11 @@ const v3 = {
const statCode = getPlatformStat() const statCode = getPlatformStat()
const pushCode = getPlatformPush() const pushCode = getPlatformPush()
const beforeCode = 'import \'uni-pages\';' let beforeCode = 'import \'uni-pages\';'
if (JSON.parse(process.env.UNI_CLOUD_PROVIDER || '[]').length) {
const uniCloudLibPath = '@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js'
beforeCode += `import '${uniCloudLibPath}';`
}
if (!webpackConfig.optimization) { if (!webpackConfig.optimization) {
webpackConfig.optimization = {} webpackConfig.optimization = {}
} }
...@@ -270,4 +273,4 @@ if (process.env.UNI_USING_V3) { ...@@ -270,4 +273,4 @@ if (process.env.UNI_USING_V3) {
module.exports = v3 module.exports = v3
} else { } else {
module.exports = require('../mp') module.exports = require('../mp')
} }
...@@ -100,9 +100,12 @@ module.exports = { ...@@ -100,9 +100,12 @@ module.exports = {
useBuiltIns = babelConfig.presets[0][1].useBuiltIns useBuiltIns = babelConfig.presets[0][1].useBuiltIns
} catch (e) {} } catch (e) {}
const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') + let beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') +
`import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';` `import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
if (JSON.parse(process.env.UNI_CLOUD_PROVIDER || '[]').length) {
const uniCloudLibPath = '@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js'
beforeCode += `import '${uniCloudLibPath}';`
}
return { return {
resolve: { resolve: {
extensions: ['.nvue'], extensions: ['.nvue'],
...@@ -188,4 +191,4 @@ module.exports = { ...@@ -188,4 +191,4 @@ module.exports = {
require('./cssnano-options')(webpackConfig) require('./cssnano-options')(webpackConfig)
} }
} }
} }
...@@ -189,11 +189,16 @@ module.exports = { ...@@ -189,11 +189,16 @@ module.exports = {
? process.env.UNI_MP_PLUGIN_MAIN ? process.env.UNI_MP_PLUGIN_MAIN
: JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT) : JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT)
).forEach(fileName => addToUniEntry(fileName)) ).forEach(fileName => addToUniEntry(fileName))
beforeCode += ` beforeCode += `
// @ts-ignore // @ts-ignore
${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;` ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
} }
if (JSON.parse(process.env.UNI_CLOUD_PROVIDER || '[]').length) {
const uniCloudLibPath = '@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js'
beforeCode += `import '${uniCloudLibPath}';`
}
const alias = { // 仅 mp-weixin const alias = { // 仅 mp-weixin
'mpvue-page-factory': require.resolve( 'mpvue-page-factory': require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory') '@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory')
...@@ -327,4 +332,4 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;` ...@@ -327,4 +332,4 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
webpackConfig.plugins.delete('preload') webpackConfig.plugins.delete('preload')
webpackConfig.plugins.delete('prefetch') webpackConfig.plugins.delete('prefetch')
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册