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

wip(mp): custom chunk

上级 6b0586dc
...@@ -1769,21 +1769,30 @@ var serviceContext = (function (vue) { ...@@ -1769,21 +1769,30 @@ var serviceContext = (function (vue) {
}); });
const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => { const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.setClipboardData.'; 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(() => { const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
......
...@@ -8,6 +8,14 @@ const jsonPagesCache = new Map<string, PageWindowOptions>() ...@@ -8,6 +8,14 @@ const jsonPagesCache = new Map<string, PageWindowOptions>()
const jsonComponentsCache = new Map<string, ComponentJson>() const jsonComponentsCache = new Map<string, ComponentJson>()
const jsonUsingComponentsCache = new Map<string, UsingComponents>() 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) { export function normalizeJsonFilename(filename: string) {
return normalizeNodeModules(filename) return normalizeNodeModules(filename)
} }
......
此差异已折叠。
...@@ -51,7 +51,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) { ...@@ -51,7 +51,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
options.hashId = genHashId(options) options.hashId = genHashId(options)
if (options.filename) { if (options.filename) {
if (options.filters && options.miniProgram?.filter) { if (!options.filters && options.miniProgram?.filter) {
options.filters = parseFilters( options.filters = parseFilters(
options.miniProgram.filter.lang, options.miniProgram.filter.lang,
options.filename options.filename
......
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import debug from 'debug'
import { UserConfig } from 'vite' import { UserConfig } from 'vite'
import { import {
emptyDir, emptyDir,
EXTNAME_JS_RE,
isCSSRequest, isCSSRequest,
normalizePath, normalizePath,
hasJsonFile,
removeExt,
resolveMainPathOnce, resolveMainPathOnce,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { GetManualChunk, GetModuleInfo } from 'rollup' import { GetManualChunk, GetModuleInfo } from 'rollup'
...@@ -16,6 +20,8 @@ import { ...@@ -16,6 +20,8 @@ import {
parseVirtualPagePath, parseVirtualPagePath,
} from '../plugins/entry' } from '../plugins/entry'
const debugChunk = debug('vite:uni:chunk')
export function buildOptions(): UserConfig['build'] { export function buildOptions(): UserConfig['build'] {
const inputDir = process.env.UNI_INPUT_DIR const inputDir = process.env.UNI_INPUT_DIR
const outputDir = process.env.UNI_OUTPUT_DIR const outputDir = process.env.UNI_OUTPUT_DIR
...@@ -25,6 +31,7 @@ export function buildOptions(): UserConfig['build'] { ...@@ -25,6 +31,7 @@ export function buildOptions(): UserConfig['build'] {
} }
return { return {
// sourcemap: 'inline', // TODO // sourcemap: 'inline', // TODO
target: ['chrome53'],
emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml emptyOutDir: false, // 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
assetsInlineLimit: 0, // TODO assetsInlineLimit: 0, // TODO
lib: { lib: {
...@@ -62,16 +69,47 @@ export function buildOptions(): UserConfig['build'] { ...@@ -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 { function createMoveToVendorChunkFn(): GetManualChunk {
const cache = new Map<string, boolean>() const cache = new Map<string, boolean>()
const inputDir = normalizePath(process.env.UNI_INPUT_DIR)
return (id, { getModuleInfo }) => { return (id, { getModuleInfo }) => {
id = normalizePath(id)
if ( if (
(id.includes('node_modules') || isVueJs(id) ||
id.includes('plugin-vue:export-helper')) && isDCloudJs(id) ||
!isCSSRequest(id) && (id.includes('node_modules') &&
staticImportedByEntry(id, getModuleInfo, cache) !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.
先完成此消息的编辑!
想要评论请 注册