提交 8395a83b 编写于 作者: fxy060608's avatar fxy060608

wip(mp): custom chunk

上级 6b0586dc
......@@ -1769,21 +1769,30 @@ var serviceContext = (function (vue) {
});
const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.setClipboardData.';
const keys = ['success'];
const keys = ['success', 'fail'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Content copied']), false);
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, [
'Content copied',
'Copy failed, please copy manually',
]), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Contenido copiado']), false);
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
'Contenido copiado',
'Error al copiar, copie manualmente',
]), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Contenu copié']), false);
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
'Contenu copié',
'Échec de la copie, copiez manuellement',
]), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['内容已复制']), false);
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['内容已复制', '复制失败,请手动复制']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['內容已復制']), false);
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['內容已復制', '復制失敗,請手動復製']), false);
}
});
const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
......
......@@ -8,6 +8,14 @@ const jsonPagesCache = new Map<string, PageWindowOptions>()
const jsonComponentsCache = new Map<string, ComponentJson>()
const jsonUsingComponentsCache = new Map<string, UsingComponents>()
export function hasJsonFile(filename: string) {
return (
filename === 'app' ||
jsonPagesCache.has(filename) ||
jsonComponentsCache.has(filename)
)
}
export function normalizeJsonFilename(filename: string) {
return normalizeNodeModules(filename)
}
......
此差异已折叠。
......@@ -51,7 +51,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
options.hashId = genHashId(options)
if (options.filename) {
if (options.filters && options.miniProgram?.filter) {
if (!options.filters && options.miniProgram?.filter) {
options.filters = parseFilters(
options.miniProgram.filter.lang,
options.filename
......
import fs from 'fs'
import path from 'path'
import debug from 'debug'
import { UserConfig } from 'vite'
import {
emptyDir,
EXTNAME_JS_RE,
isCSSRequest,
normalizePath,
hasJsonFile,
removeExt,
resolveMainPathOnce,
} from '@dcloudio/uni-cli-shared'
import { GetManualChunk, GetModuleInfo } from 'rollup'
......@@ -16,6 +20,8 @@ import {
parseVirtualPagePath,
} from '../plugins/entry'
const debugChunk = debug('vite:uni:chunk')
export function buildOptions(): UserConfig['build'] {
const inputDir = process.env.UNI_INPUT_DIR
const outputDir = process.env.UNI_OUTPUT_DIR
......@@ -25,6 +31,7 @@ export function buildOptions(): UserConfig['build'] {
}
return {
// sourcemap: 'inline', // TODO
target: ['chrome53'],
emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
assetsInlineLimit: 0, // TODO
lib: {
......@@ -62,16 +69,47 @@ export function buildOptions(): UserConfig['build'] {
}
}
function isVueJs(id: string) {
return (
id.includes('plugin-vue:export-helper') ||
(id.includes('/@vue/') && id.endsWith('.js'))
)
}
function isDCloudJs(id: string) {
return id.includes('/@dcloudio/') && id.endsWith('.js')
}
const chunkFileNameBlackList = ['main', 'pages.json', 'manifest.json']
function createMoveToVendorChunkFn(): GetManualChunk {
const cache = new Map<string, boolean>()
const inputDir = normalizePath(process.env.UNI_INPUT_DIR)
return (id, { getModuleInfo }) => {
id = normalizePath(id)
if (
(id.includes('node_modules') ||
id.includes('plugin-vue:export-helper')) &&
!isCSSRequest(id) &&
staticImportedByEntry(id, getModuleInfo, cache)
isVueJs(id) ||
isDCloudJs(id) ||
(id.includes('node_modules') &&
!isCSSRequest(id) &&
staticImportedByEntry(id, getModuleInfo, cache))
) {
return 'vendor'
debugChunk('common/vendor', id)
return 'common/vendor'
}
const filename = id.split('?')[0]
// 处理项目内的js,ts文件
if (EXTNAME_JS_RE.test(filename) && filename.startsWith(inputDir)) {
const chunkFileName = removeExt(
normalizePath(path.relative(inputDir, filename))
)
if (
!chunkFileNameBlackList.includes(chunkFileName) &&
!hasJsonFile(chunkFileName) // 无同名的page,component
) {
debugChunk(chunkFileName, id)
return chunkFileName
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册