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

feat: auto import uniCloud once

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