Skip to content

Commit bc4ba9f

Browse files
committed
wip(dom2): 优化编译资源同步策略
1 parent 03869c8 commit bc4ba9f

File tree

5 files changed

+75
-54
lines changed

5 files changed

+75
-54
lines changed

packages/uni-cli-shared/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function requireHashSum () {
124124
}
125125

126126
var hashSumExports = /*@__PURE__*/ requireHashSum();
127-
var hash_sum = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
127+
var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
128128

129129
const CSS_VARS_HELPER = `useCssVars`;
130130
function getCssVarsHelper(vapor) {
@@ -146,7 +146,7 @@ function genCssVarsFromList(vars, id, isProd, isSSR = false) {
146146
}
147147
function genVarName(id, raw, isProd, isSSR = false) {
148148
if (isProd) {
149-
return hash_sum(id + raw).replace(/^\d/, (r) => `v${r}`);
149+
return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
150150
} else {
151151
return `${id}-${shared.getEscapedCssVarName(raw, isSSR)}`;
152152
}
@@ -21624,6 +21624,7 @@ let __temp${any}, __restore${any}
2162421624
if (destructureElements.length) {
2162521625
args += `, { ${destructureElements.join(", ")} }`;
2162621626
}
21627+
let templateHash = "";
2162721628
let templateMap;
2162821629
let returned;
2162921630
const propsDecl = genRuntimeProps(ctx);
@@ -21687,7 +21688,7 @@ let __temp${any}, __restore${any}
2168721688
}
2168821689
};
2168921690
}
21690-
const { code, preamble, tips, errors, helpers, map: map2 } = compileTemplate({
21691+
const { code, ast, preamble, tips, errors, helpers, map: map2 } = compileTemplate({
2169121692
filename,
2169221693
ast: sfc.template.ast,
2169321694
source: sfc.template.content,
@@ -21702,9 +21703,14 @@ let __temp${any}, __restore${any}
2170221703
...options.templateOptions && options.templateOptions.compilerOptions,
2170321704
inline: true,
2170421705
isTS: ctx.isTS,
21705-
bindingMetadata: ctx.bindingMetadata
21706+
bindingMetadata: ctx.bindingMetadata,
21707+
// @ts-expect-error
21708+
isWatch: options.isWatch
2170621709
}
2170721710
});
21711+
if (ast && ast.hash) {
21712+
templateHash = ast.hash;
21713+
}
2170821714
templateMap = map2;
2170921715
if (tips.length) {
2171021716
tips.forEach(warnOnce);
@@ -21767,9 +21773,9 @@ ${vapor && !ssr ? `` : `return `}${returned}
2176721773
const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
2176821774
let runtimeOptions = ``;
2176921775
if (options.className) {
21770-
if (options.isWatch) {
21776+
if (options.isWatch && templateHash) {
2177121777
runtimeOptions += `
21772-
__hash: "${hash_sum(sfc.source)}",`;
21778+
__hash: "${templateHash}",`;
2177321779
}
2177421780
runtimeOptions += `
2177521781
__className,`;

packages/uni-cli-shared/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26898,7 +26898,7 @@ function requireHashSum () {
2689826898
}
2689926899

2690026900
var hashSumExports = /*@__PURE__*/ requireHashSum();
26901-
var hash_sum = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
26901+
var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
2690226902

2690326903
const CSS_VARS_HELPER = `useCssVars`;
2690426904
function getCssVarsHelper(vapor) {
@@ -26920,7 +26920,7 @@ function genCssVarsFromList(vars, id, isProd, isSSR = false) {
2692026920
}
2692126921
function genVarName$1(id, raw, isProd, isSSR = false) {
2692226922
if (isProd) {
26923-
return hash_sum(id + raw).replace(/^\d/, (r) => `v${r}`);
26923+
return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
2692426924
} else {
2692526925
return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
2692626926
}
@@ -55045,6 +55045,7 @@ let __temp${any}, __restore${any}
5504555045
if (destructureElements.length) {
5504655046
args += `, { ${destructureElements.join(", ")} }`;
5504755047
}
55048+
let templateHash = "";
5504855049
let templateMap;
5504955050
let returned;
5505055051
const propsDecl = genRuntimeProps(ctx);
@@ -55105,7 +55106,7 @@ let __temp${any}, __restore${any}
5510555106
}
5510655107
};
5510755108
}
55108-
const { code, preamble, tips, errors, helpers, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
55109+
const { code, ast, preamble, tips, errors, helpers, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
5510955110
filename,
5511055111
ast: sfc.template.ast,
5511155112
source: sfc.template.content,
@@ -55119,9 +55120,14 @@ let __temp${any}, __restore${any}
5511955120
compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
5512055121
inline: true,
5512155122
isTS: ctx.isTS,
55122-
bindingMetadata: ctx.bindingMetadata
55123+
bindingMetadata: ctx.bindingMetadata,
55124+
// @ts-expect-error
55125+
isWatch: options.isWatch
5512355126
})
5512455127
}));
55128+
if (ast && ast.hash) {
55129+
templateHash = ast.hash;
55130+
}
5512555131
templateMap = map2;
5512655132
if (tips.length) {
5512755133
tips.forEach(warnOnce$1);
@@ -55184,9 +55190,9 @@ ${vapor && !ssr ? `` : `return `}${returned}
5518455190
const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
5518555191
let runtimeOptions = ``;
5518655192
if (options.className) {
55187-
if (options.isWatch) {
55193+
if (options.isWatch && templateHash) {
5518855194
runtimeOptions += `
55189-
__hash: "${hash_sum(sfc.source)}",`;
55195+
__hash: "${templateHash}",`;
5519055196
}
5519155197
runtimeOptions += `
5519255198
__className,`;

packages/uni-cli-shared/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js

Lines changed: 38 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uni-cli-shared/src/vite/plugins/stats.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function uniStatsPlugin(): Plugin {
2020
const emittedHash = emittedHashMap.get(resolvedConfig)!
2121
const changedFiles: string[] = []
2222
Object.keys(bundle).forEach((filename) => {
23+
// 不处理sourcemap
24+
if (filename.endsWith('.map')) {
25+
return
26+
}
2327
const outputFile = bundle[filename]
2428
let outputFileHash = ''
2529
if (outputFile.type === 'asset') {

packages/vite-plugin-uni/src/cli/action.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ export async function runDev(options: CliOptions & ServerOptions) {
136136
}
137137
}
138138
}
139+
// dom2 下仅 cpp 变更需要整体编译,理论上是不是所有平台,所有场景下,都是这样?
140+
// 如果有changedFiles就增量输出,否则就不要输出,而是打印无变更,静态资源走额外的全量同步
141+
// 之前之所以没有增量就全量同步,是为了兼容性,怕出意外。
142+
if (process.env.UNI_APP_X_DOM2 === 'true') {
143+
if (process.env.UNI_APP_X_DOM2_CPP_CHANGED === 'true') {
144+
return output('log', M['dev.watching.end'])
145+
}
146+
return output('log', M['uvue.dev.watching.end.empty'])
147+
}
139148
return output('log', M['dev.watching.end'])
140149
} else if (event.code === 'END') {
141150
// 重要:1.0 的APP端是自实现的AppWatcher,它是不会触发END事件的,这里边的逻辑只有非1.0的APP端会触发

0 commit comments

Comments
 (0)