提交 2e97f8a6 编写于 作者: fxy060608's avatar fxy060608

feat(mp): improve minimize

上级 423b8e46
...@@ -89,7 +89,8 @@ const parseRequirePath = path => path.startsWith('common') ? `./${path}` : path ...@@ -89,7 +89,8 @@ 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(parseRequirePath(path.relative(dirname, 'common/runtime.js')))}');` const runtimeJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/runtime.js')))}');`
const vendorJsCode = hasVendor ? `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/vendor.js')))}');` : '' const vendorJsCode = hasVendor
? `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/vendor.js')))}');` : ''
const mainJsCode = `require('${normalizePath(parseRequirePath(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] = {
...@@ -176,10 +177,12 @@ module.exports = { ...@@ -176,10 +177,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.UNI_MP_PLUGIN_EXPORT)) [].concat(process.env.UNI_MP_PLUGIN ? process.env.UNI_MP_PLUGIN_MAIN : JSON.parse(process.env
.UNI_MP_PLUGIN_EXPORT))
.forEach(fileName => addToUniEntry(fileName)) .forEach(fileName => addToUniEntry(fileName))
beforeCode += `${globalEnv}.__webpack_require_${(process.env.UNI_MP_PLUGIN || 'UNI_MP_PLUGIN').replace(/-/g, '_')}__ = __webpack_require__;` beforeCode +=
`${globalEnv}.__webpack_require_${(process.env.UNI_MP_PLUGIN || 'UNI_MP_PLUGIN').replace(/-/g, '_')}__ = __webpack_require__;`
} }
const alias = { // 仅 mp-weixin const alias = { // 仅 mp-weixin
...@@ -197,9 +200,13 @@ module.exports = { ...@@ -197,9 +200,13 @@ module.exports = {
// 使用外层依赖的版本 // 使用外层依赖的版本
alias['regenerator-runtime'] = require.resolve('regenerator-runtime') alias['regenerator-runtime'] = require.resolve('regenerator-runtime')
const optimization = {}
if (process.env.UNI_MINIMIZE === 'true' && process.env.NODE_ENV === 'development') {
optimization.namedChunks = true
}
return { return {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', mode: process.env.UNI_MINIMIZE === 'true' || process.env.NODE_ENV === 'production' ? 'production'
: 'development',
entry () { entry () {
return process.UNI_ENTRY return process.UNI_ENTRY
}, },
...@@ -256,7 +263,8 @@ module.exports = { ...@@ -256,7 +263,8 @@ module.exports = {
}] }]
}] }]
}, },
plugins plugins,
optimization
} }
}, },
chainWebpack (webpackConfig, vueOptions, api) { chainWebpack (webpackConfig, vueOptions, api) {
...@@ -311,4 +319,4 @@ module.exports = { ...@@ -311,4 +319,4 @@ module.exports = {
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.
先完成此消息的编辑!
想要评论请 注册