提交 ef4f0fc4 编写于 作者: S songyu 提交者: 折腾笔记

chore: 代码格式化

上级 1b44dd92
......@@ -104,12 +104,12 @@ function updateComponentJson (name, jsonObj, usingComponents = true, type = 'Com
}
function updateUsingGlobalComponents (name, usingGlobalComponents) {
const manifestConfig = process.UNI_MANIFEST;
const weixinConfig = manifestConfig['mp-weixin'];
const independentSwitch = !!weixinConfig.independent;
const manifestConfig = process.UNI_MANIFEST
const weixinConfig = manifestConfig['mp-weixin']
const independentSwitch = !!weixinConfig.independent
if (!independentSwitch && supportGlobalUsingComponents) {
return;
return
}
const oldJsonStr = getJsonFile(name)
......
......@@ -209,20 +209,19 @@ function parseEntry (pagesJson) {
process.UNI_ENTRY = {
'common/main': mainJsPath
}
const manifestConfig = process.UNI_MANIFEST;
const weixinConfig = manifestConfig['mp-weixin'] || {};
const independentSwitch = !!weixinConfig.independent;
const manifestConfig = process.UNI_MANIFEST
const weixinConfig = manifestConfig['mp-weixin'] || {}
const independentSwitch = !!weixinConfig.independent
if (independentSwitch) {
Object.values(process.UNI_SUBPACKAGES).forEach(({ root, independent = false }) => {
if (root && independent) {
const pkgRootMainJsKey = `${root}/common/main`;
const pkgRootMainJsKey = `${root}/common/main`
// const pkgRootMainJsPath = `${process.env.UNI_INPUT_DIR}/${root}/main.js`;
process.UNI_ENTRY[pkgRootMainJsKey] = mainJsPath;
process.UNI_ENTRY[pkgRootMainJsKey] = mainJsPath
}
});
})
}
process.UNI_SUB_PACKAGES_ROOT = {}
process.UNI_NVUE_ENTRY = {}
......
const AddShareAbilityToRuntimePlugin = require('./independent-plugins/add-share-ability-to-runtime-plugin');
const GenerateIndepndentEntryPlugin = require('./independent-plugins/generate-indepndent-entry-plugin');
const InjectEntryJsToIndependentPlugin = require('./independent-plugins/inject-entry-to-independent-plugin');
const InjectMainCssToIndependentCssPlugin = require('./independent-plugins/inject-main-css-to-independent-plugin');
const RunDefaultAppPlugin = require('./independent-plugins/run-default-app-plugin');
const SplitIndependentChunksPlugin = require('./independent-plugins/split-independent-chunks-plugin');
const ModifyUniAppWebpackConfigPlugin = require('./independent-plugins/modify-uniapp-webpack-config-Plugin');
const AddWxMpRuntimePlugin = require('./independent-plugins/add-weixin-mp-runtime-plugin');
const AppInterceptorPlugin = require('./independent-plugins/app-interceptor-plugin');
const AddShareAbilityToRuntimePlugin = require('./independent-plugins/add-share-ability-to-runtime-plugin')
const GenerateIndepndentEntryPlugin = require('./independent-plugins/generate-indepndent-entry-plugin')
const InjectEntryJsToIndependentPlugin = require('./independent-plugins/inject-entry-to-independent-plugin')
const InjectMainCssToIndependentCssPlugin = require('./independent-plugins/inject-main-css-to-independent-plugin')
const RunDefaultAppPlugin = require('./independent-plugins/run-default-app-plugin')
const SplitIndependentChunksPlugin = require('./independent-plugins/split-independent-chunks-plugin')
const ModifyUniAppWebpackConfigPlugin = require('./independent-plugins/modify-uniapp-webpack-config-Plugin')
const AddWxMpRuntimePlugin = require('./independent-plugins/add-weixin-mp-runtime-plugin')
const AppInterceptorPlugin = require('./independent-plugins/app-interceptor-plugin')
module.exports = function createIndependentPlugins () {
const manifestConfig = process.UNI_MANIFEST;
const weixinConfig = manifestConfig['mp-weixin'];
const independentSwitch = !!weixinConfig.independent;
if (!independentSwitch) return [];
const manifestConfig = process.UNI_MANIFEST
const weixinConfig = manifestConfig['mp-weixin']
const independentSwitch = !!weixinConfig.independent
if (!independentSwitch) return []
// 支持构造微信小程序的独立分包
const independentPlugins = [
new SplitIndependentChunksPlugin(),
new ModifyUniAppWebpackConfigPlugin(), // 修改 webpack配置
new AddShareAbilityToRuntimePlugin(), // 保证独立分包和主包使用的相同的runtime.js
new GenerateIndepndentEntryPlugin(), // 生成独立分包执行入口文件(代替app.js
new InjectEntryJsToIndependentPlugin(), // 为独立分包注入执行入口
new RunDefaultAppPlugin(), // 确保app.js中的App()被执行一次
// 独立分包中 App,getApp 调用拦截
new AddWxMpRuntimePlugin(),
new AppInterceptorPlugin()
];
// 支持构造微信小程序的独立分包
const independentPlugins = [
new SplitIndependentChunksPlugin(),
new ModifyUniAppWebpackConfigPlugin(), // 修改 webpack配置
new AddShareAbilityToRuntimePlugin(), // 保证独立分包和主包使用的相同的runtime.js
new GenerateIndepndentEntryPlugin(), // 生成独立分包执行入口文件(代替app.js
new InjectEntryJsToIndependentPlugin(), // 为独立分包注入执行入口
new RunDefaultAppPlugin(), // 确保app.js中的App()被执行一次
// 独立分包中 App,getApp 调用拦截
new AddWxMpRuntimePlugin(),
new AppInterceptorPlugin()
]
const insertAppCssToIndependentSwitch = !!weixinConfig.insertAppCssToIndependent;
if (insertAppCssToIndependentSwitch) {
// 需要在 cacheSet 后面
independentPlugins.push(new InjectMainCssToIndependentCssPlugin()); // 目前只对页面注入了,组件未注入
}
const insertAppCssToIndependentSwitch = !!weixinConfig.insertAppCssToIndependent
if (insertAppCssToIndependentSwitch) {
// 需要在 cacheSet 后面
independentPlugins.push(new InjectMainCssToIndependentCssPlugin()) // 目前只对页面注入了,组件未注入
}
return independentPlugins;
};
\ No newline at end of file
return independentPlugins
}
......@@ -42,18 +42,18 @@ module.exports = {
const workers = platformOptions.workers
workers && copyOptions.push(workers)
const manifestConfig = process.UNI_MANIFEST;
const weixinConfig = manifestConfig['mp-weixin'] || {};
const copyWxComponentsOnDemandSwitch = !!weixinConfig.copyWxComponentsOnDemand; // 默认值false
const manifestConfig = process.UNI_MANIFEST
const weixinConfig = manifestConfig['mp-weixin'] || {}
const copyWxComponentsOnDemandSwitch = !!weixinConfig.copyWxComponentsOnDemand // 默认值false
if (!copyWxComponentsOnDemandSwitch) {
const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME);
const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME)
if (fs.existsSync(wxcomponentsDir)) {
copyOptions.push({
from: wxcomponentsDir,
to: COMPONENTS_DIR_NAME,
ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
});
})
}
}
global.uniModules.forEach(module => {
......
......@@ -23,7 +23,7 @@ function createUniMPPlugin () {
return new WebpackUniMPPlugin()
}
const createWxMpIndependentPlugins = require('@dcloudio/uni-mp-weixin/lib/createIndependentPlugin');
const createWxMpIndependentPlugins = require('@dcloudio/uni-mp-weixin/lib/createIndependentPlugin')
function getProvides () {
const uniPath = require('@dcloudio/uni-cli-shared/lib/platform').getMPRuntimePath()
......
......@@ -4,12 +4,12 @@ const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const subPkgsInfo = Object.values(process.UNI_SUBPACKAGES);
const normalFilter = ({ independent }) => !independent;
const independentFilter = ({ independent }) => independent;
const map2Root = ({ root }) => root + '/';
const normalSubPackageRoots = subPkgsInfo.filter(normalFilter).map(map2Root);
const independentSubpackageRoots = subPkgsInfo.filter(independentFilter).map(map2Root);
const subPkgsInfo = Object.values(process.UNI_SUBPACKAGES)
const normalFilter = ({ independent }) => !independent
const independentFilter = ({ independent }) => independent
const map2Root = ({ root }) => root + '/'
const normalSubPackageRoots = subPkgsInfo.filter(normalFilter).map(map2Root)
const independentSubpackageRoots = subPkgsInfo.filter(independentFilter).map(map2Root)
function createCacheGroups () {
const cacheGroups = {}
......@@ -187,9 +187,9 @@ module.exports = function getSplitChunks () {
}
// 独立分包除外
const independentRoot = independentSubpackageRoots.find(root => resource.indexOf(root) >= 0);
const independentRoot = independentSubpackageRoots.find(root => resource.indexOf(root) >= 0)
if (!independentRoot) {
return true;
return true
}
}
} else {
......
......@@ -105,11 +105,11 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
}
const origSource = assets[name].source()
if (isVueComponent) {
componentChunkNameMap[name] = moduleId
} else if (isVueOuterComponent) {
const startIndex = name.indexOf(vueOuterComponentSting) + vueOuterComponentSting.length + 1;
const startIndex = name.indexOf(vueOuterComponentSting) + vueOuterComponentSting.length + 1
const rightOriginalComponentName = name.substring(startIndex)
moduleId = componentChunkNameMap[rightOriginalComponentName]
}
......
......@@ -26,7 +26,7 @@ const mpBaiduDynamicLibs = [
'dynamicLib://myDynamicLib/vrvideo'
]
const AnalyzeDependency = require('@dcloudio/uni-mp-weixin/lib/independent-plugins/optimize-components-position/index');
const AnalyzeDependency = require('@dcloudio/uni-mp-weixin/lib/independent-plugins/optimize-components-position/index')
function analyzeUsingComponents () {
if (!process.env.UNI_OPT_SUBPACKAGES) {
......@@ -112,11 +112,11 @@ function normalizeUsingComponents (file, usingComponents) {
return usingComponents
}
const cacheFileMap = new Map();
const cacheFileMap = new Map()
module.exports = function generateJson (compilation) {
analyzeUsingComponents()
const emitFileMap = new Map([...cacheFileMap]);
const emitFileMap = new Map([...cacheFileMap])
const jsonFileMap = getChangedJsonFileMap()
for (const name of jsonFileMap.keys()) {
const jsonObj = JSON.parse(jsonFileMap.get(name))
......@@ -214,24 +214,23 @@ module.exports = function generateJson (compilation) {
jsonObj.usingComponents = normalizeUsingComponents(name, jsonObj.usingComponents)
}
emitFileMap.set(name, jsonObj);
cacheFileMap.set(name, JSON.parse(JSON.stringify(jsonObj))); // 做一次拷贝,emitFileMap中内容在后面会被修改
emitFileMap.set(name, jsonObj)
cacheFileMap.set(name, JSON.parse(JSON.stringify(jsonObj))) // 做一次拷贝,emitFileMap中内容在后面会被修改
}
// 组件依赖分析
(new AnalyzeDependency()).init(emitFileMap, compilation);
for (const [name, jsonObj] of emitFileMap) {
if (name === 'app.json') { // 删除manifest.json携带的配置项
delete jsonObj.insertAppCssToIndependent;
delete jsonObj.independent;
delete jsonObj.copyWxComponentsOnDemand;
} else { // 删除用于临时记录的属性
delete jsonObj.usingGlobalComponents;
}
emit(name, jsonObj, compilation);
(new AnalyzeDependency()).init(emitFileMap, compilation)
for (const [name, jsonObj] of emitFileMap) {
if (name === 'app.json') { // 删除manifest.json携带的配置项
delete jsonObj.insertAppCssToIndependent
delete jsonObj.independent
delete jsonObj.copyWxComponentsOnDemand
} else { // 删除用于临时记录的属性
delete jsonObj.usingGlobalComponents
}
emit(name, jsonObj, compilation)
}
if (process.env.UNI_USING_CACHE && jsonFileMap.size) {
setTimeout(() => {
......@@ -242,42 +241,41 @@ module.exports = function generateJson (compilation) {
function emit (name, jsonObj, compilation) {
if (jsonObj.usingComponents) {
jsonObj.usingComponents = Object.assign({}, jsonObj.usingComponents);
jsonObj.usingComponents = Object.assign({}, jsonObj.usingComponents)
}
const source = JSON.stringify(jsonObj, null, 2)
const jsFile = name.replace('.json', '.js')
if (
![
'app.js',
'manifest.js',
'mini.project.js',
'quickapp.config.js',
'project.config.js',
'project.swan.js'
].includes(
jsFile) &&
const jsFile = name.replace('.json', '.js')
if (
![
'app.js',
'manifest.js',
'mini.project.js',
'quickapp.config.js',
'project.config.js',
'project.swan.js'
].includes(
jsFile) &&
!compilation.assets[jsFile]
) {
const jsFileAsset = {
size () {
return Buffer.byteLength(EMPTY_COMPONENT, 'utf8')
},
source () {
return EMPTY_COMPONENT
}
}
compilation.assets[jsFile] = jsFileAsset
}
const jsonAsset = {
) {
const jsFileAsset = {
size () {
return Buffer.byteLength(source, 'utf8')
return Buffer.byteLength(EMPTY_COMPONENT, 'utf8')
},
source () {
return source
return EMPTY_COMPONENT
}
}
compilation.assets[jsFile] = jsFileAsset
}
const jsonAsset = {
size () {
return Buffer.byteLength(source, 'utf8')
},
source () {
return source
}
}
compilation.assets[name] = jsonAsset
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册