vite 5.0.0-beta.5 → 5.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/client.mjs +17 -0
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-4109817a.js → dep-7af400e9.js} +228 -117
- package/dist/node/chunks/{dep-958c4c65.js → dep-8648c2fe.js} +1 -1
- package/dist/node/chunks/{dep-86245b77.js → dep-cb981dcb.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/index.d.ts +3270 -3474
- package/dist/node/index.js +2 -2
- package/package.json +6 -9
- package/types/hot.d.ts +4 -0
|
@@ -11876,11 +11876,22 @@ const replaceSlashOrColonRE = /[/:]/g;
|
|
|
11876
11876
|
const replaceDotRE = /\./g;
|
|
11877
11877
|
const replaceNestedIdRE = /(\s*>\s*)/g;
|
|
11878
11878
|
const replaceHashRE = /#/g;
|
|
11879
|
-
const flattenId = (id) =>
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11879
|
+
const flattenId = (id) => {
|
|
11880
|
+
const flatId = limitFlattenIdLength(id
|
|
11881
|
+
.replace(replaceSlashOrColonRE, '_')
|
|
11882
|
+
.replace(replaceDotRE, '__')
|
|
11883
|
+
.replace(replaceNestedIdRE, '___')
|
|
11884
|
+
.replace(replaceHashRE, '____'));
|
|
11885
|
+
return flatId;
|
|
11886
|
+
};
|
|
11887
|
+
const FLATTEN_ID_HASH_LENGTH = 8;
|
|
11888
|
+
const FLATTEN_ID_MAX_FILE_LENGTH = 170;
|
|
11889
|
+
const limitFlattenIdLength = (id, limit = FLATTEN_ID_MAX_FILE_LENGTH) => {
|
|
11890
|
+
if (id.length <= limit) {
|
|
11891
|
+
return id;
|
|
11892
|
+
}
|
|
11893
|
+
return id.slice(0, limit - (FLATTEN_ID_HASH_LENGTH + 1)) + '_' + getHash(id);
|
|
11894
|
+
};
|
|
11884
11895
|
const normalizeId = (id) => id.replace(replaceNestedIdRE, ' > ');
|
|
11885
11896
|
// Supported by Node, Deno, Bun
|
|
11886
11897
|
const NODE_BUILTIN_NAMESPACE = 'node:';
|
|
@@ -28500,7 +28511,7 @@ const browserExternalId = '__vite-browser-external';
|
|
|
28500
28511
|
// special id for packages that are optional peer deps
|
|
28501
28512
|
const optionalPeerDepId = '__vite-optional-peer-dep';
|
|
28502
28513
|
const subpathImportsPrefix = '#';
|
|
28503
|
-
const startsWithWordCharRE = /^\w/;
|
|
28514
|
+
const startsWithWordCharRE$1 = /^\w/;
|
|
28504
28515
|
const debug$e = createDebugger('vite:resolve-details', {
|
|
28505
28516
|
onlyWhenFocused: true,
|
|
28506
28517
|
});
|
|
@@ -28592,7 +28603,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
28592
28603
|
// relative
|
|
28593
28604
|
if (id[0] === '.' ||
|
|
28594
28605
|
((preferRelative || importer?.endsWith('.html')) &&
|
|
28595
|
-
startsWithWordCharRE.test(id))) {
|
|
28606
|
+
startsWithWordCharRE$1.test(id))) {
|
|
28596
28607
|
const basedir = importer ? path$o.dirname(importer) : process.cwd();
|
|
28597
28608
|
const fsPath = path$o.resolve(basedir, id);
|
|
28598
28609
|
// handle browser field mapping for relative imports
|
|
@@ -38042,7 +38053,7 @@ function buildHtmlPlugin(config) {
|
|
|
38042
38053
|
// newline trailing the previous node
|
|
38043
38054
|
const lineStartOffset = node.sourceCodeLocation.startOffset -
|
|
38044
38055
|
node.sourceCodeLocation.startCol;
|
|
38045
|
-
const line = s.slice(lineStartOffset, node.sourceCodeLocation.startOffset);
|
|
38056
|
+
const line = s.slice(Math.max(0, lineStartOffset), node.sourceCodeLocation.startOffset);
|
|
38046
38057
|
// <previous-line-node></previous-line-node>
|
|
38047
38058
|
// <target-node></target-node>
|
|
38048
38059
|
//
|
|
@@ -38116,21 +38127,7 @@ function buildHtmlPlugin(config) {
|
|
|
38116
38127
|
}
|
|
38117
38128
|
else if (node.childNodes.length) {
|
|
38118
38129
|
const scriptNode = node.childNodes.pop();
|
|
38119
|
-
|
|
38120
|
-
let match;
|
|
38121
|
-
inlineImportRE.lastIndex = 0;
|
|
38122
|
-
while ((match = inlineImportRE.exec(cleanCode))) {
|
|
38123
|
-
const { 1: url, index } = match;
|
|
38124
|
-
const startUrl = cleanCode.indexOf(url, index);
|
|
38125
|
-
const start = startUrl + 1;
|
|
38126
|
-
const end = start + url.length - 2;
|
|
38127
|
-
const startOffset = scriptNode.sourceCodeLocation.startOffset;
|
|
38128
|
-
scriptUrls.push({
|
|
38129
|
-
start: start + startOffset,
|
|
38130
|
-
end: end + startOffset,
|
|
38131
|
-
url: scriptNode.value.slice(start, end),
|
|
38132
|
-
});
|
|
38133
|
-
}
|
|
38130
|
+
scriptUrls.push(...extractImportExpressionFromClassicScript(scriptNode));
|
|
38134
38131
|
}
|
|
38135
38132
|
}
|
|
38136
38133
|
// For asset references in index.html, also generate an import
|
|
@@ -38171,26 +38168,19 @@ function buildHtmlPlugin(config) {
|
|
|
38171
38168
|
}
|
|
38172
38169
|
}
|
|
38173
38170
|
}
|
|
38174
|
-
|
|
38175
|
-
// extract inline styles as virtual css and add class attribute to tag for selecting
|
|
38176
|
-
const inlineStyle = node.attrs.find((prop) => prop.prefix === undefined &&
|
|
38177
|
-
prop.name === 'style' &&
|
|
38178
|
-
// only url(...) or image-set(...) in css need to emit file
|
|
38179
|
-
(prop.value.includes('url(') ||
|
|
38180
|
-
prop.value.includes('image-set(')));
|
|
38171
|
+
const inlineStyle = findNeedTransformStyleAttribute(node);
|
|
38181
38172
|
if (inlineStyle) {
|
|
38182
38173
|
inlineModuleIndex++;
|
|
38183
|
-
// replace `inline style`
|
|
38174
|
+
// replace `inline style` with __VITE_INLINE_CSS__**_**__
|
|
38184
38175
|
// and import css in js code
|
|
38185
|
-
const code = inlineStyle.value;
|
|
38176
|
+
const code = inlineStyle.attr.value;
|
|
38186
38177
|
const filePath = id.replace(normalizePath$3(config.root), '');
|
|
38187
38178
|
addToHTMLProxyCache(config, filePath, inlineModuleIndex, { code });
|
|
38188
38179
|
// will transform with css plugin and cache result with css-post plugin
|
|
38189
38180
|
js += `\nimport "${id}?html-proxy&inline-css&style-attr&index=${inlineModuleIndex}.css"`;
|
|
38190
38181
|
const hash = getHash(cleanUrl(id));
|
|
38191
38182
|
// will transform in `applyHtmlTransforms`
|
|
38192
|
-
|
|
38193
|
-
overwriteAttrValue(s, sourceCodeLocation, `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`);
|
|
38183
|
+
overwriteAttrValue(s, inlineStyle.location, `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`);
|
|
38194
38184
|
}
|
|
38195
38185
|
// <style>...</style>
|
|
38196
38186
|
if (node.nodeName === 'style' && node.childNodes.length) {
|
|
@@ -38449,6 +38439,37 @@ function buildHtmlPlugin(config) {
|
|
|
38449
38439
|
},
|
|
38450
38440
|
};
|
|
38451
38441
|
}
|
|
38442
|
+
// <tag style="... url(...) or image-set(...) ..."></tag>
|
|
38443
|
+
// extract inline styles as virtual css
|
|
38444
|
+
function findNeedTransformStyleAttribute(node) {
|
|
38445
|
+
const attr = node.attrs.find((prop) => prop.prefix === undefined &&
|
|
38446
|
+
prop.name === 'style' &&
|
|
38447
|
+
// only url(...) or image-set(...) in css need to emit file
|
|
38448
|
+
(prop.value.includes('url(') || prop.value.includes('image-set(')));
|
|
38449
|
+
if (!attr)
|
|
38450
|
+
return undefined;
|
|
38451
|
+
const location = node.sourceCodeLocation?.attrs?.['style'];
|
|
38452
|
+
return { attr, location };
|
|
38453
|
+
}
|
|
38454
|
+
function extractImportExpressionFromClassicScript(scriptTextNode) {
|
|
38455
|
+
const startOffset = scriptTextNode.sourceCodeLocation.startOffset;
|
|
38456
|
+
const cleanCode = stripLiteral(scriptTextNode.value);
|
|
38457
|
+
const scriptUrls = [];
|
|
38458
|
+
let match;
|
|
38459
|
+
inlineImportRE.lastIndex = 0;
|
|
38460
|
+
while ((match = inlineImportRE.exec(cleanCode))) {
|
|
38461
|
+
const { 1: url, index } = match;
|
|
38462
|
+
const startUrl = cleanCode.indexOf(url, index);
|
|
38463
|
+
const start = startUrl + 1;
|
|
38464
|
+
const end = start + url.length - 2;
|
|
38465
|
+
scriptUrls.push({
|
|
38466
|
+
start: start + startOffset,
|
|
38467
|
+
end: end + startOffset,
|
|
38468
|
+
url: scriptTextNode.value.slice(start, end),
|
|
38469
|
+
});
|
|
38470
|
+
}
|
|
38471
|
+
return scriptUrls;
|
|
38472
|
+
}
|
|
38452
38473
|
function preImportMapHook(config) {
|
|
38453
38474
|
return (html, ctx) => {
|
|
38454
38475
|
const importMapIndex = html.match(importMapRE)?.index;
|
|
@@ -38902,6 +38923,19 @@ function cssPostPlugin(config) {
|
|
|
38902
38923
|
return;
|
|
38903
38924
|
}
|
|
38904
38925
|
css = stripBomTag(css);
|
|
38926
|
+
// cache css compile result to map
|
|
38927
|
+
// and then use the cache replace inline-style-flag
|
|
38928
|
+
// when `generateBundle` in vite:build-html plugin and devHtmlHook
|
|
38929
|
+
const inlineCSS = inlineCSSRE.test(id);
|
|
38930
|
+
const isHTMLProxy = htmlProxyRE.test(id);
|
|
38931
|
+
if (inlineCSS && isHTMLProxy) {
|
|
38932
|
+
const query = parseRequest(id);
|
|
38933
|
+
if (styleAttrRE.test(id)) {
|
|
38934
|
+
css = css.replace(/"/g, '"');
|
|
38935
|
+
}
|
|
38936
|
+
addToHTMLProxyTransformResult(`${getHash(cleanUrl(id))}_${Number.parseInt(query.index)}`, css);
|
|
38937
|
+
return `export default ''`;
|
|
38938
|
+
}
|
|
38905
38939
|
const inlined = inlineRE.test(id);
|
|
38906
38940
|
const modules = cssModulesCache.get(config).get(id);
|
|
38907
38941
|
// #6984, #7552
|
|
@@ -38945,18 +38979,6 @@ function cssPostPlugin(config) {
|
|
|
38945
38979
|
}
|
|
38946
38980
|
// build CSS handling ----------------------------------------------------
|
|
38947
38981
|
// record css
|
|
38948
|
-
// cache css compile result to map
|
|
38949
|
-
// and then use the cache replace inline-style-flag when `generateBundle` in vite:build-html plugin
|
|
38950
|
-
const inlineCSS = inlineCSSRE.test(id);
|
|
38951
|
-
const isHTMLProxy = htmlProxyRE.test(id);
|
|
38952
|
-
const query = parseRequest(id);
|
|
38953
|
-
if (inlineCSS && isHTMLProxy) {
|
|
38954
|
-
if (styleAttrRE.test(id)) {
|
|
38955
|
-
css = css.replace(/"/g, '"');
|
|
38956
|
-
}
|
|
38957
|
-
addToHTMLProxyTransformResult(`${getHash(cleanUrl(id))}_${Number.parseInt(query.index)}`, css);
|
|
38958
|
-
return `export default ''`;
|
|
38959
|
-
}
|
|
38960
38982
|
if (!inlined) {
|
|
38961
38983
|
styles.set(id, css);
|
|
38962
38984
|
}
|
|
@@ -39148,13 +39170,7 @@ function cssPostPlugin(config) {
|
|
|
39148
39170
|
.filter((chunk) => chunk.type === 'chunk')
|
|
39149
39171
|
.map((chunk) => [chunk.preliminaryFileName, chunk.fileName]));
|
|
39150
39172
|
const pureCssChunkNames = [...pureCssChunks].map((pureCssChunk) => prelimaryNameToChunkMap[pureCssChunk.fileName]);
|
|
39151
|
-
const
|
|
39152
|
-
.map((file) => path$o.basename(file))
|
|
39153
|
-
.join('|')
|
|
39154
|
-
.replace(/\./g, '\\.');
|
|
39155
|
-
const emptyChunkRE = new RegExp(opts.format === 'es'
|
|
39156
|
-
? `\\bimport\\s*["'][^"']*(?:${emptyChunkFiles})["'];\n?`
|
|
39157
|
-
: `\\brequire\\(\\s*["'][^"']*(?:${emptyChunkFiles})["']\\);\n?`, 'g');
|
|
39173
|
+
const replaceEmptyChunk = getEmptyChunkReplacer(pureCssChunkNames, opts.format);
|
|
39158
39174
|
for (const file in bundle) {
|
|
39159
39175
|
const chunk = bundle[file];
|
|
39160
39176
|
if (chunk.type === 'chunk') {
|
|
@@ -39170,9 +39186,7 @@ function cssPostPlugin(config) {
|
|
|
39170
39186
|
}
|
|
39171
39187
|
return true;
|
|
39172
39188
|
});
|
|
39173
|
-
chunk.code = chunk.code
|
|
39174
|
-
// remove css import while preserving source map location
|
|
39175
|
-
(m) => `/* empty css ${''.padEnd(m.length - 15)}*/`);
|
|
39189
|
+
chunk.code = replaceEmptyChunk(chunk.code);
|
|
39176
39190
|
}
|
|
39177
39191
|
}
|
|
39178
39192
|
const removedPureCssFiles = removedPureCssFilesCache.get(config);
|
|
@@ -39213,6 +39227,23 @@ function cssPostPlugin(config) {
|
|
|
39213
39227
|
},
|
|
39214
39228
|
};
|
|
39215
39229
|
}
|
|
39230
|
+
/**
|
|
39231
|
+
* Create a replacer function that takes code and replaces given pure CSS chunk imports
|
|
39232
|
+
* @param pureCssChunkNames The chunks that only contain pure CSS and should be replaced
|
|
39233
|
+
* @param outputFormat The module output format to decide whether to replace `import` or `require`
|
|
39234
|
+
*/
|
|
39235
|
+
function getEmptyChunkReplacer(pureCssChunkNames, outputFormat) {
|
|
39236
|
+
const emptyChunkFiles = pureCssChunkNames
|
|
39237
|
+
.map((file) => path$o.basename(file))
|
|
39238
|
+
.join('|')
|
|
39239
|
+
.replace(/\./g, '\\.');
|
|
39240
|
+
const emptyChunkRE = new RegExp(outputFormat === 'es'
|
|
39241
|
+
? `\\bimport\\s*["'][^"']*(?:${emptyChunkFiles})["'];\n?`
|
|
39242
|
+
: `\\brequire\\(\\s*["'][^"']*(?:${emptyChunkFiles})["']\\);\n?`, 'g');
|
|
39243
|
+
return (code) => code.replace(emptyChunkRE,
|
|
39244
|
+
// remove css import while preserving source map location
|
|
39245
|
+
(m) => `/* empty css ${''.padEnd(m.length - 15)}*/`);
|
|
39246
|
+
}
|
|
39216
39247
|
function createCSSResolvers(config) {
|
|
39217
39248
|
let cssResolve;
|
|
39218
39249
|
let sassResolve;
|
|
@@ -39508,8 +39539,8 @@ function createCachedImport(imp) {
|
|
|
39508
39539
|
return cached;
|
|
39509
39540
|
};
|
|
39510
39541
|
}
|
|
39511
|
-
const importPostcssImport = createCachedImport(() => import('./dep-
|
|
39512
|
-
const importPostcssModules = createCachedImport(() => import('./dep-
|
|
39542
|
+
const importPostcssImport = createCachedImport(() => import('./dep-8648c2fe.js').then(function (n) { return n.i; }));
|
|
39543
|
+
const importPostcssModules = createCachedImport(() => import('./dep-cb981dcb.js').then(function (n) { return n.i; }));
|
|
39513
39544
|
const importPostcss = createCachedImport(() => import('postcss'));
|
|
39514
39545
|
/**
|
|
39515
39546
|
* @experimental
|
|
@@ -42330,19 +42361,8 @@ function importAnalysisPlugin(config) {
|
|
|
42330
42361
|
[imports, exports] = parse$e(source);
|
|
42331
42362
|
}
|
|
42332
42363
|
catch (e) {
|
|
42333
|
-
const
|
|
42334
|
-
|
|
42335
|
-
const maybeJSX = !isVue && isJSRequest(importer);
|
|
42336
|
-
const msg = isVue
|
|
42337
|
-
? `Install @vitejs/plugin-vue to handle .vue files.`
|
|
42338
|
-
: maybeJSX
|
|
42339
|
-
? isJsx
|
|
42340
|
-
? `If you use tsconfig.json, make sure to not set jsx to preserve.`
|
|
42341
|
-
: `If you are using JSX, make sure to name the file with the .jsx or .tsx extension.`
|
|
42342
|
-
: `You may need to install appropriate plugins to handle the ${path$o.extname(importer)} file format, or if it's an asset, add "**/*${path$o.extname(importer)}" to \`assetsInclude\` in your configuration.`;
|
|
42343
|
-
this.error(`Failed to parse source for import analysis because the content ` +
|
|
42344
|
-
`contains invalid JS syntax. ` +
|
|
42345
|
-
msg, e.idx);
|
|
42364
|
+
const { message, showCodeFrame } = createParseErrorInfo(importer, source);
|
|
42365
|
+
this.error(message, showCodeFrame ? e.idx : undefined);
|
|
42346
42366
|
}
|
|
42347
42367
|
const depsOptimizer = getDepsOptimizer(config, ssr);
|
|
42348
42368
|
const { moduleGraph } = server;
|
|
@@ -42733,6 +42753,25 @@ function mergeAcceptedUrls(orderedUrls) {
|
|
|
42733
42753
|
}
|
|
42734
42754
|
return acceptedUrls;
|
|
42735
42755
|
}
|
|
42756
|
+
function createParseErrorInfo(importer, source) {
|
|
42757
|
+
const isVue = importer.endsWith('.vue');
|
|
42758
|
+
const isJsx = importer.endsWith('.jsx') || importer.endsWith('.tsx');
|
|
42759
|
+
const maybeJSX = !isVue && isJSRequest(importer);
|
|
42760
|
+
const probablyBinary = source.includes('\ufffd' /* unicode replacement character */);
|
|
42761
|
+
const msg = isVue
|
|
42762
|
+
? `Install @vitejs/plugin-vue to handle .vue files.`
|
|
42763
|
+
: maybeJSX
|
|
42764
|
+
? isJsx
|
|
42765
|
+
? `If you use tsconfig.json, make sure to not set jsx to preserve.`
|
|
42766
|
+
: `If you are using JSX, make sure to name the file with the .jsx or .tsx extension.`
|
|
42767
|
+
: `You may need to install appropriate plugins to handle the ${path$o.extname(importer)} file format, or if it's an asset, add "**/*${path$o.extname(importer)}" to \`assetsInclude\` in your configuration.`;
|
|
42768
|
+
return {
|
|
42769
|
+
message: `Failed to parse source for import analysis because the content ` +
|
|
42770
|
+
`contains invalid JS syntax. ` +
|
|
42771
|
+
msg,
|
|
42772
|
+
showCodeFrame: !probablyBinary,
|
|
42773
|
+
};
|
|
42774
|
+
}
|
|
42736
42775
|
function interopNamedImports(str, importSpecifier, rewrittenUrl, importIndex, importer, config) {
|
|
42737
42776
|
const source = str.original;
|
|
42738
42777
|
const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex, } = importSpecifier;
|
|
@@ -47277,7 +47316,8 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47277
47316
|
imports = parse$e(source)[0];
|
|
47278
47317
|
}
|
|
47279
47318
|
catch (e) {
|
|
47280
|
-
|
|
47319
|
+
const { message, showCodeFrame } = createParseErrorInfo(importer, source);
|
|
47320
|
+
this.error(message, showCodeFrame ? e.idx : undefined);
|
|
47281
47321
|
}
|
|
47282
47322
|
if (!imports.length) {
|
|
47283
47323
|
return null;
|
|
@@ -47444,6 +47484,23 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47444
47484
|
}
|
|
47445
47485
|
const s = new MagicString(code);
|
|
47446
47486
|
const rewroteMarkerStartPos = new Set(); // position of the leading double quote
|
|
47487
|
+
const fileDeps = [];
|
|
47488
|
+
const addFileDep = (url, runtime = false) => {
|
|
47489
|
+
const index = fileDeps.findIndex((dep) => dep.url === url);
|
|
47490
|
+
if (index === -1) {
|
|
47491
|
+
return fileDeps.push({ url, runtime }) - 1;
|
|
47492
|
+
}
|
|
47493
|
+
else {
|
|
47494
|
+
return index;
|
|
47495
|
+
}
|
|
47496
|
+
};
|
|
47497
|
+
const getFileDep = (index) => {
|
|
47498
|
+
const fileDep = fileDeps[index];
|
|
47499
|
+
if (!fileDep) {
|
|
47500
|
+
throw new Error(`Cannot find file dep at index ${index}`);
|
|
47501
|
+
}
|
|
47502
|
+
return fileDep;
|
|
47503
|
+
};
|
|
47447
47504
|
if (imports.length) {
|
|
47448
47505
|
for (let index = 0; index < imports.length; index++) {
|
|
47449
47506
|
// To handle escape sequences in specifier strings, the .n field will be provided where possible.
|
|
@@ -47471,12 +47528,12 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47471
47528
|
analyzed.add(filename);
|
|
47472
47529
|
const chunk = bundle[filename];
|
|
47473
47530
|
if (chunk) {
|
|
47474
|
-
deps.add(chunk.fileName);
|
|
47531
|
+
deps.add(addFileDep(chunk.fileName));
|
|
47475
47532
|
chunk.imports.forEach(addDeps);
|
|
47476
47533
|
// Ensure that the css imported by current chunk is loaded after the dependencies.
|
|
47477
47534
|
// So the style of current chunk won't be overwritten unexpectedly.
|
|
47478
47535
|
chunk.viteMetadata.importedCss.forEach((file) => {
|
|
47479
|
-
deps.add(file);
|
|
47536
|
+
deps.add(addFileDep(file));
|
|
47480
47537
|
});
|
|
47481
47538
|
}
|
|
47482
47539
|
else {
|
|
@@ -47485,7 +47542,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47485
47542
|
if (chunk) {
|
|
47486
47543
|
if (chunk.viteMetadata.importedCss.size) {
|
|
47487
47544
|
chunk.viteMetadata.importedCss.forEach((file) => {
|
|
47488
|
-
deps.add(file);
|
|
47545
|
+
deps.add(addFileDep(file));
|
|
47489
47546
|
});
|
|
47490
47547
|
hasRemovedPureCssChunk = true;
|
|
47491
47548
|
}
|
|
@@ -47508,7 +47565,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47508
47565
|
? modulePreload === false
|
|
47509
47566
|
? // CSS deps use the same mechanism as module preloads, so even if disabled,
|
|
47510
47567
|
// we still need to pass these deps to the preload helper in dynamic imports.
|
|
47511
|
-
[...deps].filter((d) => d.endsWith('.css'))
|
|
47568
|
+
[...deps].filter((d) => getFileDep(d).url.endsWith('.css'))
|
|
47512
47569
|
: [...deps]
|
|
47513
47570
|
: [];
|
|
47514
47571
|
let renderedDeps;
|
|
@@ -47524,13 +47581,18 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47524
47581
|
const cssDeps = [];
|
|
47525
47582
|
const otherDeps = [];
|
|
47526
47583
|
for (const dep of depsArray) {
|
|
47527
|
-
(dep.endsWith('.css')
|
|
47584
|
+
if (getFileDep(dep).url.endsWith('.css')) {
|
|
47585
|
+
cssDeps.push(dep);
|
|
47586
|
+
}
|
|
47587
|
+
else {
|
|
47588
|
+
otherDeps.push(dep);
|
|
47589
|
+
}
|
|
47528
47590
|
}
|
|
47529
47591
|
resolvedDeps = [
|
|
47530
|
-
...resolveDependencies(normalizedFile, otherDeps, {
|
|
47592
|
+
...resolveDependencies(normalizedFile, otherDeps.map((otherDep) => getFileDep(otherDep).url), {
|
|
47531
47593
|
hostId: file,
|
|
47532
47594
|
hostType: 'js',
|
|
47533
|
-
}),
|
|
47595
|
+
}).map((otherDep) => addFileDep(otherDep)),
|
|
47534
47596
|
...cssDeps,
|
|
47535
47597
|
];
|
|
47536
47598
|
}
|
|
@@ -47538,26 +47600,36 @@ function buildImportAnalysisPlugin(config) {
|
|
|
47538
47600
|
resolvedDeps = depsArray;
|
|
47539
47601
|
}
|
|
47540
47602
|
renderedDeps = resolvedDeps.map((dep) => {
|
|
47541
|
-
const replacement = toOutputFilePathInJS(dep, 'asset', chunk.fileName, 'js', config, toRelativePath);
|
|
47542
|
-
|
|
47543
|
-
|
|
47544
|
-
|
|
47545
|
-
return
|
|
47603
|
+
const replacement = toOutputFilePathInJS(getFileDep(dep).url, 'asset', chunk.fileName, 'js', config, toRelativePath);
|
|
47604
|
+
if (typeof replacement === 'string') {
|
|
47605
|
+
return addFileDep(replacement);
|
|
47606
|
+
}
|
|
47607
|
+
return addFileDep(replacement.runtime, true);
|
|
47546
47608
|
});
|
|
47547
47609
|
}
|
|
47548
47610
|
else {
|
|
47549
47611
|
renderedDeps = depsArray.map((d) =>
|
|
47550
47612
|
// Don't include the assets dir if the default asset file names
|
|
47551
47613
|
// are used, the path will be reconstructed by the import preload helper
|
|
47552
|
-
|
|
47553
|
-
? toRelativePath(d, file)
|
|
47554
|
-
: d)
|
|
47614
|
+
optimizeModulePreloadRelativePaths
|
|
47615
|
+
? addFileDep(toRelativePath(getFileDep(d).url, file))
|
|
47616
|
+
: d);
|
|
47555
47617
|
}
|
|
47556
|
-
s.update(markerStartPos, markerStartPos + preloadMarker.length + 2, `[${renderedDeps.join(',')}]`);
|
|
47618
|
+
s.update(markerStartPos, markerStartPos + preloadMarker.length + 2, `__vite__mapDeps([${renderedDeps.join(',')}])`);
|
|
47557
47619
|
rewroteMarkerStartPos.add(markerStartPos);
|
|
47558
47620
|
}
|
|
47559
47621
|
}
|
|
47560
47622
|
}
|
|
47623
|
+
const fileDepsCode = `[${fileDeps
|
|
47624
|
+
.map((fileDep) => fileDep.runtime ? fileDep.url : JSON.stringify(fileDep.url))
|
|
47625
|
+
.join(',')}]`;
|
|
47626
|
+
s.append(`\
|
|
47627
|
+
function __vite__mapDeps(indexes) {
|
|
47628
|
+
if (!__vite__mapDeps.viteFileDeps) {
|
|
47629
|
+
__vite__mapDeps.viteFileDeps = ${fileDepsCode}
|
|
47630
|
+
}
|
|
47631
|
+
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
47632
|
+
}`);
|
|
47561
47633
|
// there may still be markers due to inlined dynamic imports, remove
|
|
47562
47634
|
// all the markers regardless
|
|
47563
47635
|
let markerStartPos = indexOfMatchInSlice(code, preloadMarkerWithQuote);
|
|
@@ -64895,7 +64967,8 @@ function proxyMiddleware(httpServer, options, config) {
|
|
|
64895
64967
|
}
|
|
64896
64968
|
else if (bypassResult === false) {
|
|
64897
64969
|
debug$1?.(`bypass: ${req.url} -> 404`);
|
|
64898
|
-
|
|
64970
|
+
res.statusCode = 404;
|
|
64971
|
+
return res.end();
|
|
64899
64972
|
}
|
|
64900
64973
|
}
|
|
64901
64974
|
debug$1?.(`${req.url} -> ${opts.target || opts.forward}`);
|
|
@@ -65300,8 +65373,9 @@ function getHtmlFilename(url, server) {
|
|
|
65300
65373
|
function shouldPreTransform(url, config) {
|
|
65301
65374
|
return (!checkPublicFile(url, config) && (isJSRequest(url) || isCSSRequest(url)));
|
|
65302
65375
|
}
|
|
65303
|
-
const
|
|
65304
|
-
|
|
65376
|
+
const startsWithWordCharRE = /^\w/;
|
|
65377
|
+
const isSrcSet = (attr) => attr.name === 'srcset' && attr.prefix === undefined;
|
|
65378
|
+
const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, server) => {
|
|
65305
65379
|
if (server?.moduleGraph) {
|
|
65306
65380
|
const mod = server.moduleGraph.urlToModuleMap.get(url);
|
|
65307
65381
|
if (mod && mod.lastHMRTimestamp > 0) {
|
|
@@ -65312,12 +65386,12 @@ const processNodeUrl = (attr, sourceCodeLocation, s, config, htmlPath, originalU
|
|
|
65312
65386
|
if (url[0] === '/' && url[1] !== '/') {
|
|
65313
65387
|
// prefix with base (dev only, base is never relative)
|
|
65314
65388
|
const fullUrl = path$o.posix.join(devBase, url);
|
|
65315
|
-
overwriteAttrValue(s, sourceCodeLocation, fullUrl);
|
|
65316
65389
|
if (server && shouldPreTransform(url, config)) {
|
|
65317
65390
|
preTransformRequest(server, fullUrl, devBase);
|
|
65318
65391
|
}
|
|
65392
|
+
return fullUrl;
|
|
65319
65393
|
}
|
|
65320
|
-
else if (url[0] === '.' &&
|
|
65394
|
+
else if ((url[0] === '.' || startsWithWordCharRE.test(url)) &&
|
|
65321
65395
|
originalUrl &&
|
|
65322
65396
|
originalUrl !== '/' &&
|
|
65323
65397
|
htmlPath === '/index.html') {
|
|
@@ -65333,10 +65407,10 @@ const processNodeUrl = (attr, sourceCodeLocation, s, config, htmlPath, originalU
|
|
|
65333
65407
|
// path will add `/a/` prefix, it will caused 404.
|
|
65334
65408
|
// rewrite before `./index.js` -> `localhost:5173/a/index.js`.
|
|
65335
65409
|
// rewrite after `../index.js` -> `localhost:5173/index.js`.
|
|
65336
|
-
const processedUrl =
|
|
65410
|
+
const processedUrl = useSrcSetReplacer
|
|
65337
65411
|
? processSrcSetSync(url, ({ url }) => replacer(url))
|
|
65338
65412
|
: replacer(url);
|
|
65339
|
-
|
|
65413
|
+
return processedUrl;
|
|
65340
65414
|
}
|
|
65341
65415
|
};
|
|
65342
65416
|
const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl }) => {
|
|
@@ -65364,6 +65438,7 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
65364
65438
|
let inlineModuleIndex = -1;
|
|
65365
65439
|
const proxyCacheUrl = cleanUrl(proxyModulePath).replace(normalizePath$3(config.root), '');
|
|
65366
65440
|
const styleUrl = [];
|
|
65441
|
+
const inlineStyles = [];
|
|
65367
65442
|
const addInlineModule = (node, ext) => {
|
|
65368
65443
|
inlineModuleIndex++;
|
|
65369
65444
|
const contentNode = node.childNodes[0];
|
|
@@ -65396,11 +65471,32 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
65396
65471
|
if (node.nodeName === 'script') {
|
|
65397
65472
|
const { src, sourceCodeLocation, isModule } = getScriptInfo(node);
|
|
65398
65473
|
if (src) {
|
|
65399
|
-
processNodeUrl(src,
|
|
65474
|
+
const processedUrl = processNodeUrl(src.value, isSrcSet(src), config, htmlPath, originalUrl, server);
|
|
65475
|
+
if (processedUrl) {
|
|
65476
|
+
overwriteAttrValue(s, sourceCodeLocation, processedUrl);
|
|
65477
|
+
}
|
|
65400
65478
|
}
|
|
65401
65479
|
else if (isModule && node.childNodes.length) {
|
|
65402
65480
|
addInlineModule(node, 'js');
|
|
65403
65481
|
}
|
|
65482
|
+
else if (node.childNodes.length) {
|
|
65483
|
+
const scriptNode = node.childNodes[node.childNodes.length - 1];
|
|
65484
|
+
for (const { url, start, end, } of extractImportExpressionFromClassicScript(scriptNode)) {
|
|
65485
|
+
const processedUrl = processNodeUrl(url, false, config, htmlPath, originalUrl);
|
|
65486
|
+
if (processedUrl) {
|
|
65487
|
+
s.update(start, end, processedUrl);
|
|
65488
|
+
}
|
|
65489
|
+
}
|
|
65490
|
+
}
|
|
65491
|
+
}
|
|
65492
|
+
const inlineStyle = findNeedTransformStyleAttribute(node);
|
|
65493
|
+
if (inlineStyle) {
|
|
65494
|
+
inlineModuleIndex++;
|
|
65495
|
+
inlineStyles.push({
|
|
65496
|
+
index: inlineModuleIndex,
|
|
65497
|
+
location: inlineStyle.location,
|
|
65498
|
+
code: inlineStyle.attr.value,
|
|
65499
|
+
});
|
|
65404
65500
|
}
|
|
65405
65501
|
if (node.nodeName === 'style' && node.childNodes.length) {
|
|
65406
65502
|
const children = node.childNodes[0];
|
|
@@ -65416,31 +65512,46 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
65416
65512
|
for (const p of node.attrs) {
|
|
65417
65513
|
const attrKey = getAttrKey(p);
|
|
65418
65514
|
if (p.value && assetAttrs.includes(attrKey)) {
|
|
65419
|
-
processNodeUrl(p
|
|
65515
|
+
const processedUrl = processNodeUrl(p.value, isSrcSet(p), config, htmlPath, originalUrl);
|
|
65516
|
+
if (processedUrl) {
|
|
65517
|
+
overwriteAttrValue(s, node.sourceCodeLocation.attrs[attrKey], processedUrl);
|
|
65518
|
+
}
|
|
65420
65519
|
}
|
|
65421
65520
|
}
|
|
65422
65521
|
}
|
|
65423
65522
|
});
|
|
65424
|
-
await Promise.all(
|
|
65425
|
-
|
|
65426
|
-
|
|
65427
|
-
|
|
65428
|
-
|
|
65429
|
-
|
|
65430
|
-
|
|
65431
|
-
|
|
65432
|
-
if (result
|
|
65433
|
-
if (result.map.
|
|
65434
|
-
|
|
65523
|
+
await Promise.all([
|
|
65524
|
+
...styleUrl.map(async ({ start, end, code }, index) => {
|
|
65525
|
+
const url = `${proxyModulePath}?html-proxy&direct&index=${index}.css`;
|
|
65526
|
+
// ensure module in graph after successful load
|
|
65527
|
+
const mod = await moduleGraph.ensureEntryFromUrl(url, false);
|
|
65528
|
+
ensureWatchedFile(watcher, mod.file, config.root);
|
|
65529
|
+
const result = await server.pluginContainer.transform(code, mod.id);
|
|
65530
|
+
let content = '';
|
|
65531
|
+
if (result) {
|
|
65532
|
+
if (result.map && 'version' in result.map) {
|
|
65533
|
+
if (result.map.mappings) {
|
|
65534
|
+
await injectSourcesContent(result.map, proxyModulePath, config.logger);
|
|
65535
|
+
}
|
|
65536
|
+
content = getCodeWithSourcemap('css', result.code, result.map);
|
|
65537
|
+
}
|
|
65538
|
+
else {
|
|
65539
|
+
content = result.code;
|
|
65435
65540
|
}
|
|
65436
|
-
content = getCodeWithSourcemap('css', result.code, result.map);
|
|
65437
|
-
}
|
|
65438
|
-
else {
|
|
65439
|
-
content = result.code;
|
|
65440
65541
|
}
|
|
65441
|
-
|
|
65442
|
-
|
|
65443
|
-
|
|
65542
|
+
s.overwrite(start, end, content);
|
|
65543
|
+
}),
|
|
65544
|
+
...inlineStyles.map(async ({ index, location, code }) => {
|
|
65545
|
+
// will transform with css plugin and cache result with css-post plugin
|
|
65546
|
+
const url = `${proxyModulePath}?html-proxy&inline-css&style-attr&index=${index}.css`;
|
|
65547
|
+
const mod = await moduleGraph.ensureEntryFromUrl(url, false);
|
|
65548
|
+
ensureWatchedFile(watcher, mod.file, config.root);
|
|
65549
|
+
await server?.pluginContainer.transform(code, mod.id);
|
|
65550
|
+
const hash = getHash(cleanUrl(mod.id));
|
|
65551
|
+
const result = htmlProxyResult.get(`${hash}_${index}`);
|
|
65552
|
+
overwriteAttrValue(s, location, result ?? '');
|
|
65553
|
+
}),
|
|
65554
|
+
]);
|
|
65444
65555
|
html = s.toString();
|
|
65445
65556
|
return {
|
|
65446
65557
|
html,
|
|
@@ -66866,8 +66977,8 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter
|
|
|
66866
66977
|
*/
|
|
66867
66978
|
function resolveBaseUrl(base = '/', isBuild, logger) {
|
|
66868
66979
|
if (base[0] === '.') {
|
|
66869
|
-
logger.warn(colors$1.yellow(colors$1.bold(`(!) invalid "base" option: ${base}. The value can only be an absolute ` +
|
|
66870
|
-
`URL,
|
|
66980
|
+
logger.warn(colors$1.yellow(colors$1.bold(`(!) invalid "base" option: "${base}". The value can only be an absolute ` +
|
|
66981
|
+
`URL, "./", or an empty string.`)));
|
|
66871
66982
|
return '/';
|
|
66872
66983
|
}
|
|
66873
66984
|
// external URL flag
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as commonjsGlobal, D as getDefaultExportFromCjs } from './dep-
|
|
1
|
+
import { E as commonjsGlobal, D as getDefaultExportFromCjs } from './dep-7af400e9.js';
|
|
2
2
|
import require$$0__default from 'fs';
|
|
3
3
|
import require$$0 from 'postcss';
|
|
4
4
|
import require$$0$1 from 'path';
|
package/dist/node/cli.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { performance } from 'node:perf_hooks';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
-
import { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-
|
|
5
|
+
import { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-7af400e9.js';
|
|
6
6
|
import { VERSION } from './constants.js';
|
|
7
7
|
import 'node:fs/promises';
|
|
8
8
|
import 'node:url';
|
|
@@ -759,7 +759,7 @@ cli
|
|
|
759
759
|
filterDuplicateOptions(options);
|
|
760
760
|
// output structure is preserved even after bundling so require()
|
|
761
761
|
// is ok here
|
|
762
|
-
const { createServer } = await import('./chunks/dep-
|
|
762
|
+
const { createServer } = await import('./chunks/dep-7af400e9.js').then(function (n) { return n.H; });
|
|
763
763
|
try {
|
|
764
764
|
const server = await createServer({
|
|
765
765
|
root,
|
|
@@ -840,7 +840,7 @@ cli
|
|
|
840
840
|
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
|
|
841
841
|
.action(async (root, options) => {
|
|
842
842
|
filterDuplicateOptions(options);
|
|
843
|
-
const { build } = await import('./chunks/dep-
|
|
843
|
+
const { build } = await import('./chunks/dep-7af400e9.js').then(function (n) { return n.G; });
|
|
844
844
|
const buildOptions = cleanOptions(options);
|
|
845
845
|
try {
|
|
846
846
|
await build({
|
|
@@ -868,7 +868,7 @@ cli
|
|
|
868
868
|
.option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
|
|
869
869
|
.action(async (root, options) => {
|
|
870
870
|
filterDuplicateOptions(options);
|
|
871
|
-
const { optimizeDeps } = await import('./chunks/dep-
|
|
871
|
+
const { optimizeDeps } = await import('./chunks/dep-7af400e9.js').then(function (n) { return n.F; });
|
|
872
872
|
try {
|
|
873
873
|
const config = await resolveConfig({
|
|
874
874
|
root,
|
|
@@ -895,7 +895,7 @@ cli
|
|
|
895
895
|
.option('--outDir <dir>', `[string] output directory (default: dist)`)
|
|
896
896
|
.action(async (root, options) => {
|
|
897
897
|
filterDuplicateOptions(options);
|
|
898
|
-
const { preview } = await import('./chunks/dep-
|
|
898
|
+
const { preview } = await import('./chunks/dep-7af400e9.js').then(function (n) { return n.I; });
|
|
899
899
|
try {
|
|
900
900
|
const server = await preview({
|
|
901
901
|
root,
|