vite 6.0.0-alpha.6 → 6.0.0-alpha.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.
@@ -15675,7 +15675,7 @@ function checkPublicFile(url, config) {
|
|
15675
15675
|
const assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g;
|
15676
15676
|
const jsSourceMapRE = /\.[cm]?js\.map$/;
|
15677
15677
|
const assetCache = new WeakMap();
|
15678
|
-
const
|
15678
|
+
const generatedAssetsMap = new WeakMap();
|
15679
15679
|
// add own dictionary entry by directly assigning mrmime
|
15680
15680
|
function registerCustomMime() {
|
15681
15681
|
// https://github.com/lukeed/mrmime/issues/3
|
@@ -15685,7 +15685,9 @@ function registerCustomMime() {
|
|
15685
15685
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
15686
15686
|
mimes['eot'] = 'application/vnd.ms-fontobject';
|
15687
15687
|
}
|
15688
|
-
function renderAssetUrlInJS(ctx,
|
15688
|
+
function renderAssetUrlInJS(ctx, chunk, opts, code) {
|
15689
|
+
const environment = ctx.environment;
|
15690
|
+
const { config } = environment;
|
15689
15691
|
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(opts.format, config.isWorker);
|
15690
15692
|
let match;
|
15691
15693
|
let s;
|
@@ -15733,8 +15735,12 @@ function assetPlugin(config) {
|
|
15733
15735
|
return {
|
15734
15736
|
name: 'vite:asset',
|
15735
15737
|
buildStart() {
|
15736
|
-
|
15737
|
-
|
15738
|
+
const { environment } = this;
|
15739
|
+
if (!environment) {
|
15740
|
+
return;
|
15741
|
+
}
|
15742
|
+
assetCache.set(environment, new Map());
|
15743
|
+
generatedAssetsMap.set(environment, new Map());
|
15738
15744
|
},
|
15739
15745
|
resolveId(id) {
|
15740
15746
|
if (!config.assetsInclude(cleanUrl(id)) && !urlRE.test(id)) {
|
@@ -15769,7 +15775,7 @@ function assetPlugin(config) {
|
|
15769
15775
|
return;
|
15770
15776
|
}
|
15771
15777
|
id = removeUrlQuery(id);
|
15772
|
-
let url = await fileToUrl$1(
|
15778
|
+
let url = await fileToUrl$1(this, id);
|
15773
15779
|
// Inherit HMR timestamp if this asset was invalidated
|
15774
15780
|
const environment = this.environment;
|
15775
15781
|
const mod = environment?.mode === 'dev' &&
|
@@ -15787,11 +15793,11 @@ function assetPlugin(config) {
|
|
15787
15793
|
};
|
15788
15794
|
},
|
15789
15795
|
renderChunk(code, chunk, opts) {
|
15790
|
-
const s = renderAssetUrlInJS(this,
|
15796
|
+
const s = renderAssetUrlInJS(this, chunk, opts, code);
|
15791
15797
|
if (s) {
|
15792
15798
|
return {
|
15793
15799
|
code: s.toString(),
|
15794
|
-
map:
|
15800
|
+
map: this.environment?.options.build.sourcemap
|
15795
15801
|
? s.generateMap({ hires: 'boundary' })
|
15796
15802
|
: null,
|
15797
15803
|
};
|
@@ -15801,6 +15807,7 @@ function assetPlugin(config) {
|
|
15801
15807
|
}
|
15802
15808
|
},
|
15803
15809
|
generateBundle(_, bundle) {
|
15810
|
+
const environment = this.environment;
|
15804
15811
|
// Remove empty entry point file
|
15805
15812
|
for (const file in bundle) {
|
15806
15813
|
const chunk = bundle[file];
|
@@ -15812,9 +15819,7 @@ function assetPlugin(config) {
|
|
15812
15819
|
}
|
15813
15820
|
}
|
15814
15821
|
// do not emit assets for SSR build
|
15815
|
-
if (config.command === 'build' &&
|
15816
|
-
config.build.ssr &&
|
15817
|
-
!config.build.emitAssets) {
|
15822
|
+
if (config.command === 'build' && !environment.options.build.emitAssets) {
|
15818
15823
|
for (const file in bundle) {
|
15819
15824
|
if (bundle[file].type === 'asset' &&
|
15820
15825
|
!file.endsWith('ssr-manifest.json') &&
|
@@ -15826,12 +15831,13 @@ function assetPlugin(config) {
|
|
15826
15831
|
},
|
15827
15832
|
};
|
15828
15833
|
}
|
15829
|
-
async function fileToUrl$1(
|
15830
|
-
|
15831
|
-
|
15834
|
+
async function fileToUrl$1(ctx, id) {
|
15835
|
+
const environment = ctx.environment;
|
15836
|
+
if (environment.config.command === 'serve') {
|
15837
|
+
return fileToDevUrl(id, environment.config);
|
15832
15838
|
}
|
15833
15839
|
else {
|
15834
|
-
return fileToBuiltUrl(
|
15840
|
+
return fileToBuiltUrl(ctx, id);
|
15835
15841
|
}
|
15836
15842
|
}
|
15837
15843
|
function fileToDevUrl(id, config) {
|
@@ -15884,11 +15890,13 @@ function isGitLfsPlaceholder(content) {
|
|
15884
15890
|
* Register an asset to be emitted as part of the bundle (if necessary)
|
15885
15891
|
* and returns the resolved public URL
|
15886
15892
|
*/
|
15887
|
-
async function fileToBuiltUrl(
|
15893
|
+
async function fileToBuiltUrl(pluginContext, id, skipPublicCheck = false, forceInline) {
|
15894
|
+
const environment = pluginContext.environment;
|
15895
|
+
const { config } = environment;
|
15888
15896
|
if (!skipPublicCheck && checkPublicFile(id, config)) {
|
15889
15897
|
return publicFileToBuiltUrl(id, config);
|
15890
15898
|
}
|
15891
|
-
const cache = assetCache.get(
|
15899
|
+
const cache = assetCache.get(environment);
|
15892
15900
|
const cached = cache.get(id);
|
15893
15901
|
if (cached) {
|
15894
15902
|
return cached;
|
@@ -15896,7 +15904,7 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
15896
15904
|
const file = cleanUrl(id);
|
15897
15905
|
const content = await fsp.readFile(file);
|
15898
15906
|
let url;
|
15899
|
-
if (shouldInline(
|
15907
|
+
if (shouldInline(pluginContext, file, id, content, forceInline)) {
|
15900
15908
|
if (config.build.lib && isGitLfsPlaceholder(content)) {
|
15901
15909
|
config.logger.warn(colors$1.yellow(`Inlined file ${id} was not downloaded via Git LFS`));
|
15902
15910
|
}
|
@@ -15920,24 +15928,29 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
15920
15928
|
source: content,
|
15921
15929
|
});
|
15922
15930
|
const originalName = normalizePath$3(path$o.relative(config.root, file));
|
15923
|
-
|
15931
|
+
generatedAssetsMap.get(environment).set(referenceId, { originalName });
|
15924
15932
|
url = `__VITE_ASSET__${referenceId}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
|
15925
15933
|
}
|
15926
15934
|
cache.set(id, url);
|
15927
15935
|
return url;
|
15928
15936
|
}
|
15929
|
-
async function urlToBuiltUrl(url, importer,
|
15937
|
+
async function urlToBuiltUrl(pluginContext, url, importer, forceInline) {
|
15938
|
+
const environment = pluginContext.environment;
|
15939
|
+
const { config } = environment;
|
15930
15940
|
if (checkPublicFile(url, config)) {
|
15931
15941
|
return publicFileToBuiltUrl(url, config);
|
15932
15942
|
}
|
15933
15943
|
const file = url[0] === '/'
|
15934
15944
|
? path$o.join(config.root, url)
|
15935
15945
|
: path$o.join(path$o.dirname(importer), url);
|
15936
|
-
return fileToBuiltUrl(
|
15946
|
+
return fileToBuiltUrl(pluginContext, file,
|
15937
15947
|
// skip public check since we just did it above
|
15938
15948
|
true, forceInline);
|
15939
15949
|
}
|
15940
|
-
const shouldInline = (
|
15950
|
+
const shouldInline = (pluginContext, file, id, content, forceInline) => {
|
15951
|
+
const environment = pluginContext.environment;
|
15952
|
+
const { config } = environment;
|
15953
|
+
const { assetsInlineLimit } = environment.options.build;
|
15941
15954
|
if (config.build.lib)
|
15942
15955
|
return true;
|
15943
15956
|
if (pluginContext.getModuleInfo(id)?.isEntry)
|
@@ -15945,14 +15958,14 @@ const shouldInline = (config, file, id, content, pluginContext, forceInline) =>
|
|
15945
15958
|
if (forceInline !== undefined)
|
15946
15959
|
return forceInline;
|
15947
15960
|
let limit;
|
15948
|
-
if (typeof
|
15949
|
-
const userShouldInline =
|
15961
|
+
if (typeof assetsInlineLimit === 'function') {
|
15962
|
+
const userShouldInline = assetsInlineLimit(file, content);
|
15950
15963
|
if (userShouldInline != null)
|
15951
15964
|
return userShouldInline;
|
15952
15965
|
limit = DEFAULT_ASSETS_INLINE_LIMIT;
|
15953
15966
|
}
|
15954
15967
|
else {
|
15955
|
-
limit = Number(
|
15968
|
+
limit = Number(assetsInlineLimit);
|
15956
15969
|
}
|
15957
15970
|
if (file.endsWith('.html'))
|
15958
15971
|
return false;
|
@@ -15990,7 +16003,7 @@ function svgToDataURL(content) {
|
|
15990
16003
|
}
|
15991
16004
|
|
15992
16005
|
const endsWithJSRE = /\.[cm]?js$/;
|
15993
|
-
function manifestPlugin(
|
16006
|
+
function manifestPlugin() {
|
15994
16007
|
const manifest = {};
|
15995
16008
|
let outputCount;
|
15996
16009
|
return {
|
@@ -15999,8 +16012,14 @@ function manifestPlugin(config) {
|
|
15999
16012
|
outputCount = 0;
|
16000
16013
|
},
|
16001
16014
|
generateBundle({ format }, bundle) {
|
16015
|
+
const { environment } = this;
|
16016
|
+
if (!environment) {
|
16017
|
+
return;
|
16018
|
+
}
|
16019
|
+
const { root } = environment.config;
|
16020
|
+
const buildOptions = environment.options.build;
|
16002
16021
|
function getChunkName(chunk) {
|
16003
|
-
return getChunkOriginalFileName(chunk,
|
16022
|
+
return getChunkOriginalFileName(chunk, root, format);
|
16004
16023
|
}
|
16005
16024
|
function getInternalImports(imports) {
|
16006
16025
|
const filteredImports = [];
|
@@ -16056,7 +16075,7 @@ function manifestPlugin(config) {
|
|
16056
16075
|
return manifestChunk;
|
16057
16076
|
}
|
16058
16077
|
const fileNameToAssetMeta = new Map();
|
16059
|
-
const assets =
|
16078
|
+
const assets = generatedAssetsMap.get(environment);
|
16060
16079
|
assets.forEach((asset, referenceId) => {
|
16061
16080
|
try {
|
16062
16081
|
const fileName = this.getFileName(referenceId);
|
@@ -16099,12 +16118,12 @@ function manifestPlugin(config) {
|
|
16099
16118
|
}
|
16100
16119
|
});
|
16101
16120
|
outputCount++;
|
16102
|
-
const output =
|
16121
|
+
const output = buildOptions.rollupOptions?.output;
|
16103
16122
|
const outputLength = Array.isArray(output) ? output.length : 1;
|
16104
16123
|
if (outputCount >= outputLength) {
|
16105
16124
|
this.emitFile({
|
16106
|
-
fileName: typeof
|
16107
|
-
?
|
16125
|
+
fileName: typeof buildOptions.manifest === 'string'
|
16126
|
+
? buildOptions.manifest
|
16108
16127
|
: '.vite/manifest.json',
|
16109
16128
|
type: 'asset',
|
16110
16129
|
source: JSON.stringify(sortObjectKeys(manifest), undefined, 2),
|
@@ -29222,6 +29241,17 @@ const environmentColors = [
|
|
29222
29241
|
colors$1.green,
|
29223
29242
|
colors$1.gray,
|
29224
29243
|
];
|
29244
|
+
function cachedByEnvironment(create) {
|
29245
|
+
const cache = new WeakMap();
|
29246
|
+
return function (environment) {
|
29247
|
+
let data = cache.get(environment);
|
29248
|
+
if (!data) {
|
29249
|
+
data = create(environment);
|
29250
|
+
cache.set(environment, data);
|
29251
|
+
}
|
29252
|
+
return data;
|
29253
|
+
};
|
29254
|
+
}
|
29225
29255
|
|
29226
29256
|
// An implementation of fsUtils without caching
|
29227
29257
|
const commonFsUtils = {
|
@@ -58083,7 +58113,7 @@ function buildHtmlPlugin(config) {
|
|
58083
58113
|
!namedOutput.includes(removeLeadingSlash(url)) // Allow for absolute references as named output can't be an absolute path
|
58084
58114
|
) {
|
58085
58115
|
try {
|
58086
|
-
return await urlToBuiltUrl(url, id,
|
58116
|
+
return await urlToBuiltUrl(this, url, id, shouldInline);
|
58087
58117
|
}
|
58088
58118
|
catch (e) {
|
58089
58119
|
if (e.code !== 'ENOENT') {
|
@@ -58247,7 +58277,7 @@ function buildHtmlPlugin(config) {
|
|
58247
58277
|
s.update(start, end, partialEncodeURIPath(toOutputPublicFilePath(url)));
|
58248
58278
|
}
|
58249
58279
|
else if (!isExcludedUrl(url)) {
|
58250
|
-
s.update(start, end, partialEncodeURIPath(await urlToBuiltUrl(url, id
|
58280
|
+
s.update(start, end, partialEncodeURIPath(await urlToBuiltUrl(this, url, id)));
|
58251
58281
|
}
|
58252
58282
|
}
|
58253
58283
|
// ignore <link rel="stylesheet"> if its url can't be resolved
|
@@ -58398,7 +58428,7 @@ function buildHtmlPlugin(config) {
|
|
58398
58428
|
result = injectToHead(result, assetTags);
|
58399
58429
|
}
|
58400
58430
|
// inject css link when cssCodeSplit is false
|
58401
|
-
if (
|
58431
|
+
if (this.environment?.options.build.cssCodeSplit === false) {
|
58402
58432
|
const cssChunk = Object.values(bundle).find((chunk) => chunk.type === 'asset' && chunk.name === 'style.css');
|
58403
58433
|
if (cssChunk) {
|
58404
58434
|
result = injectToHead(result, [
|
@@ -62697,8 +62727,8 @@ async function bundleWorkerEntry(config, id) {
|
|
62697
62727
|
// bundle the file as entry to support imports
|
62698
62728
|
const { rollup } = await import('rollup');
|
62699
62729
|
const { plugins, rollupOptions, format } = config.worker;
|
62700
|
-
const
|
62701
|
-
const
|
62730
|
+
const { plugins: resolvedPlugins, config: workerConfig } = await plugins(newBundleChain);
|
62731
|
+
const workerEnvironment = new BuildEnvironment('client', workerConfig); // TODO: should this be 'worker'?
|
62702
62732
|
const bundle = await rollup({
|
62703
62733
|
...rollupOptions,
|
62704
62734
|
input,
|
@@ -62939,7 +62969,7 @@ function webWorkerPlugin(config) {
|
|
62939
62969
|
}
|
62940
62970
|
}
|
62941
62971
|
else {
|
62942
|
-
let url = await fileToUrl$1(cleanUrl(id)
|
62972
|
+
let url = await fileToUrl$1(this, cleanUrl(id));
|
62943
62973
|
url = injectQuery(url, `${WORKER_FILE_ID}&type=${workerType}`);
|
62944
62974
|
urlCode = JSON.stringify(url);
|
62945
62975
|
}
|
@@ -63959,7 +63989,7 @@ const wasmHelperPlugin = (config) => {
|
|
63959
63989
|
if (!id.endsWith('.wasm?init')) {
|
63960
63990
|
return;
|
63961
63991
|
}
|
63962
|
-
const url = await fileToUrl$1(
|
63992
|
+
const url = await fileToUrl$1(this, id);
|
63963
63993
|
return `
|
63964
63994
|
import initWasm from "${wasmHelperId}"
|
63965
63995
|
export default opts => initWasm(opts, ${JSON.stringify(url)})
|
@@ -64107,7 +64137,7 @@ function workerImportMetaUrlPlugin(config) {
|
|
64107
64137
|
builtUrl = await workerFileToUrl(config, file);
|
64108
64138
|
}
|
64109
64139
|
else {
|
64110
|
-
builtUrl = await fileToUrl$1(cleanUrl(file)
|
64140
|
+
builtUrl = await fileToUrl$1(this, cleanUrl(file));
|
64111
64141
|
builtUrl = injectQuery(builtUrl, `${WORKER_FILE_ID}&type=${workerType}`);
|
64112
64142
|
}
|
64113
64143
|
s.update(expStart, expEnd,
|
@@ -64220,10 +64250,10 @@ function assetImportMetaUrlPlugin(config) {
|
|
64220
64250
|
try {
|
64221
64251
|
if (publicDir && isParentDirectory(publicDir, file)) {
|
64222
64252
|
const publicPath = '/' + path$o.posix.relative(publicDir, file);
|
64223
|
-
builtUrl = await fileToUrl$1(
|
64253
|
+
builtUrl = await fileToUrl$1(this, publicPath);
|
64224
64254
|
}
|
64225
64255
|
else {
|
64226
|
-
builtUrl = await fileToUrl$1(
|
64256
|
+
builtUrl = await fileToUrl$1(this, file);
|
64227
64257
|
}
|
64228
64258
|
}
|
64229
64259
|
catch {
|
@@ -64531,8 +64561,10 @@ function dynamicImportVarsPlugin(config) {
|
|
64531
64561
|
tryIndex: false,
|
64532
64562
|
extensions: [],
|
64533
64563
|
});
|
64534
|
-
const
|
64535
|
-
|
64564
|
+
const getFilter = cachedByEnvironment((environment) => {
|
64565
|
+
const { include, exclude } = environment.options.build.dynamicImportVarsOptions;
|
64566
|
+
return createFilter(include, exclude);
|
64567
|
+
});
|
64536
64568
|
return {
|
64537
64569
|
name: 'vite:dynamic-import-vars',
|
64538
64570
|
resolveId(id) {
|
@@ -64548,7 +64580,7 @@ function dynamicImportVarsPlugin(config) {
|
|
64548
64580
|
async transform(source, importer) {
|
64549
64581
|
const { environment } = this;
|
64550
64582
|
if (!environment ||
|
64551
|
-
!
|
64583
|
+
!getFilter(environment)(importer) ||
|
64552
64584
|
importer === CLIENT_ENTRY ||
|
64553
64585
|
!hasDynamicImportRE.test(source)) {
|
64554
64586
|
return;
|
@@ -64581,7 +64613,7 @@ function dynamicImportVarsPlugin(config) {
|
|
64581
64613
|
result = await transformDynamicImport(source.slice(start, end), importer, (id, importer) => resolve(environment, id, importer), config.root);
|
64582
64614
|
}
|
64583
64615
|
catch (error) {
|
64584
|
-
if (warnOnError) {
|
64616
|
+
if (environment.options.build.dynamicImportVarsOptions.warnOnError) {
|
64585
64617
|
this.warn(error);
|
64586
64618
|
}
|
64587
64619
|
else {
|
@@ -64646,7 +64678,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
64646
64678
|
namedExports: true,
|
64647
64679
|
...config.json,
|
64648
64680
|
}, isBuild),
|
64649
|
-
wasmHelperPlugin(
|
64681
|
+
wasmHelperPlugin(),
|
64650
64682
|
webWorkerPlugin(config),
|
64651
64683
|
assetPlugin(config),
|
64652
64684
|
...normalPlugins,
|
@@ -65507,7 +65539,7 @@ function cssPlugin(config) {
|
|
65507
65539
|
}
|
65508
65540
|
const resolved = await resolveUrl(decodedUrl, importer);
|
65509
65541
|
if (resolved) {
|
65510
|
-
return fileToUrl$1(
|
65542
|
+
return fileToUrl$1(this, resolved);
|
65511
65543
|
}
|
65512
65544
|
if (config.command === 'build') {
|
65513
65545
|
const isExternal = config.build.rollupOptions.external
|
@@ -65673,6 +65705,11 @@ function cssPostPlugin(config) {
|
|
65673
65705
|
};
|
65674
65706
|
},
|
65675
65707
|
async renderChunk(code, chunk, opts) {
|
65708
|
+
const { environment } = this;
|
65709
|
+
if (!environment) {
|
65710
|
+
return;
|
65711
|
+
}
|
65712
|
+
const generatedAssets = generatedAssetsMap.get(environment);
|
65676
65713
|
let chunkCSS = '';
|
65677
65714
|
let isPureCssChunk = true;
|
65678
65715
|
const ids = Object.keys(chunk.modules);
|
@@ -65764,9 +65801,7 @@ function cssPostPlugin(config) {
|
|
65764
65801
|
type: 'asset',
|
65765
65802
|
source: content,
|
65766
65803
|
});
|
65767
|
-
generatedAssets
|
65768
|
-
.get(config)
|
65769
|
-
.set(referenceId, { originalName: originalFilename });
|
65804
|
+
generatedAssets.set(referenceId, { originalName: originalFilename });
|
65770
65805
|
const replacement = toOutputFilePathInJS(this.getFileName(referenceId), 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
|
65771
65806
|
const replacementString = typeof replacement === 'string'
|
65772
65807
|
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
|
@@ -65802,9 +65837,10 @@ function cssPostPlugin(config) {
|
|
65802
65837
|
type: 'asset',
|
65803
65838
|
source: chunkCSS,
|
65804
65839
|
});
|
65805
|
-
generatedAssets
|
65806
|
-
|
65807
|
-
|
65840
|
+
generatedAssets.set(referenceId, {
|
65841
|
+
originalName: originalFilename,
|
65842
|
+
isEntry,
|
65843
|
+
});
|
65808
65844
|
chunk.viteMetadata.importedCss.add(this.getFileName(referenceId));
|
65809
65845
|
}
|
65810
65846
|
else if (!config.build.ssr) {
|
@@ -65817,7 +65853,8 @@ function cssPostPlugin(config) {
|
|
65817
65853
|
chunkCSS = await finalizeCss(chunkCSS, true, config);
|
65818
65854
|
let cssString = JSON.stringify(chunkCSS);
|
65819
65855
|
cssString =
|
65820
|
-
renderAssetUrlInJS(this,
|
65856
|
+
renderAssetUrlInJS(this, chunk, opts, cssString)?.toString() ||
|
65857
|
+
cssString;
|
65821
65858
|
const style = `__vite_style__`;
|
65822
65859
|
const injectCode = `var ${style} = document.createElement('style');` +
|
65823
65860
|
`${style}.textContent = ${cssString};` +
|
@@ -65969,7 +66006,7 @@ function cssAnalysisPlugin(config) {
|
|
65969
66006
|
for (const file of pluginImports) {
|
65970
66007
|
depModules.add(isCSSRequest(file)
|
65971
66008
|
? moduleGraph.createFileOnlyEntry(file)
|
65972
|
-
: await moduleGraph.ensureEntryFromUrl(stripBase(await fileToUrl$1(
|
66009
|
+
: await moduleGraph.ensureEntryFromUrl(stripBase(await fileToUrl$1(this, file), (config.server?.origin ?? '') + devBase)));
|
65973
66010
|
}
|
65974
66011
|
moduleGraph.updateModuleInfo(thisModule, depModules, null,
|
65975
66012
|
// The root CSS proxy module is self-accepting and should not
|
@@ -67412,43 +67449,24 @@ function preload(baseModule, deps, importerUrl) {
|
|
67412
67449
|
}
|
67413
67450
|
});
|
67414
67451
|
}
|
67452
|
+
function getModulePreloadData(environment) {
|
67453
|
+
const { modulePreload } = environment.options.build;
|
67454
|
+
const { config } = environment;
|
67455
|
+
const resolveModulePreloadDependencies = modulePreload && modulePreload.resolveDependencies;
|
67456
|
+
const renderBuiltUrl = config.experimental.renderBuiltUrl;
|
67457
|
+
const customModulePreloadPaths = !!(resolveModulePreloadDependencies || renderBuiltUrl);
|
67458
|
+
const isRelativeBase = config.base === './' || config.base === '';
|
67459
|
+
const optimizeModulePreloadRelativePaths = isRelativeBase && !customModulePreloadPaths;
|
67460
|
+
return {
|
67461
|
+
customModulePreloadPaths,
|
67462
|
+
optimizeModulePreloadRelativePaths,
|
67463
|
+
};
|
67464
|
+
}
|
67415
67465
|
/**
|
67416
67466
|
* Build only. During serve this is performed as part of ./importAnalysis.
|
67417
67467
|
*/
|
67418
67468
|
function buildImportAnalysisPlugin(config) {
|
67419
|
-
const ssr = !!config.build.ssr;
|
67420
67469
|
const isWorker = config.isWorker;
|
67421
|
-
const insertPreload = !(ssr || !!config.build.lib || isWorker);
|
67422
|
-
const resolveModulePreloadDependencies = config.build.modulePreload && config.build.modulePreload.resolveDependencies;
|
67423
|
-
const renderBuiltUrl = config.experimental.renderBuiltUrl;
|
67424
|
-
const customModulePreloadPaths = !!(resolveModulePreloadDependencies || renderBuiltUrl);
|
67425
|
-
const isRelativeBase = config.base === './' || config.base === '';
|
67426
|
-
const optimizeModulePreloadRelativePaths = isRelativeBase && !customModulePreloadPaths;
|
67427
|
-
const { modulePreload } = config.build;
|
67428
|
-
const scriptRel = modulePreload && modulePreload.polyfill
|
67429
|
-
? `'modulepreload'`
|
67430
|
-
: `(${detectScriptRel.toString()})()`;
|
67431
|
-
// There are three different cases for the preload list format in __vitePreload
|
67432
|
-
//
|
67433
|
-
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
|
67434
|
-
//
|
67435
|
-
// This is maintained to keep backwards compatibility as some users developed plugins
|
67436
|
-
// using regex over this list to workaround the fact that module preload wasn't
|
67437
|
-
// configurable.
|
67438
|
-
const assetsURL = customModulePreloadPaths
|
67439
|
-
? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used
|
67440
|
-
// the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
|
67441
|
-
// a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
|
67442
|
-
`function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }`
|
67443
|
-
: optimizeModulePreloadRelativePaths
|
67444
|
-
? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
|
67445
|
-
// to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
|
67446
|
-
// The importerUrl is passed as third parameter to __vitePreload in this case
|
67447
|
-
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
|
67448
|
-
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
|
67449
|
-
// is appended inside __vitePreload too.
|
67450
|
-
`function(dep) { return ${JSON.stringify(config.base)}+dep }`;
|
67451
|
-
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
|
67452
67470
|
return {
|
67453
67471
|
name: 'vite:build-import-analysis',
|
67454
67472
|
resolveId(id) {
|
@@ -67457,12 +67475,41 @@ function buildImportAnalysisPlugin(config) {
|
|
67457
67475
|
}
|
67458
67476
|
},
|
67459
67477
|
load(id) {
|
67460
|
-
|
67478
|
+
const { environment } = this;
|
67479
|
+
if (environment && id === preloadHelperId) {
|
67480
|
+
const { modulePreload } = environment.options.build;
|
67481
|
+
const { customModulePreloadPaths, optimizeModulePreloadRelativePaths } = getModulePreloadData(environment);
|
67482
|
+
const scriptRel = modulePreload && modulePreload.polyfill
|
67483
|
+
? `'modulepreload'`
|
67484
|
+
: `(${detectScriptRel.toString()})()`;
|
67485
|
+
// There are three different cases for the preload list format in __vitePreload
|
67486
|
+
//
|
67487
|
+
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
|
67488
|
+
//
|
67489
|
+
// This is maintained to keep backwards compatibility as some users developed plugins
|
67490
|
+
// using regex over this list to workaround the fact that module preload wasn't
|
67491
|
+
// configurable.
|
67492
|
+
const assetsURL = customModulePreloadPaths
|
67493
|
+
? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used
|
67494
|
+
// the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
|
67495
|
+
// a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
|
67496
|
+
`function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }`
|
67497
|
+
: optimizeModulePreloadRelativePaths
|
67498
|
+
? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
|
67499
|
+
// to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
|
67500
|
+
// The importerUrl is passed as third parameter to __vitePreload in this case
|
67501
|
+
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
|
67502
|
+
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
|
67503
|
+
// is appended inside __vitePreload too.
|
67504
|
+
`function(dep) { return ${JSON.stringify(config.base)}+dep }`;
|
67505
|
+
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
|
67461
67506
|
return preloadCode;
|
67462
67507
|
}
|
67463
67508
|
},
|
67464
67509
|
async transform(source, importer) {
|
67465
|
-
|
67510
|
+
const { environment } = this;
|
67511
|
+
if (!environment ||
|
67512
|
+
(isInNodeModules$1(importer) && !dynamicImportPrefixRE.test(source))) {
|
67466
67513
|
return;
|
67467
67514
|
}
|
67468
67515
|
await init;
|
@@ -67481,6 +67528,9 @@ function buildImportAnalysisPlugin(config) {
|
|
67481
67528
|
let s;
|
67482
67529
|
const str = () => s || (s = new MagicString(source));
|
67483
67530
|
let needPreloadHelper = false;
|
67531
|
+
const ssr = environment.options.build.ssr;
|
67532
|
+
const insertPreload = !(ssr || !!config.build.lib || isWorker);
|
67533
|
+
const { customModulePreloadPaths, optimizeModulePreloadRelativePaths } = getModulePreloadData(environment);
|
67484
67534
|
for (let index = 0; index < imports.length; index++) {
|
67485
67535
|
const { e: end, ss: expStart, se: expEnd, d: dynamicIndex, a: attributeIndex, } = imports[index];
|
67486
67536
|
const isDynamicImport = dynamicIndex > -1;
|
@@ -67504,7 +67554,7 @@ function buildImportAnalysisPlugin(config) {
|
|
67504
67554
|
if (s) {
|
67505
67555
|
return {
|
67506
67556
|
code: s.toString(),
|
67507
|
-
map:
|
67557
|
+
map: environment.options.build.sourcemap
|
67508
67558
|
? s.generateMap({ hires: 'boundary' })
|
67509
67559
|
: null,
|
67510
67560
|
};
|
@@ -67512,10 +67562,11 @@ function buildImportAnalysisPlugin(config) {
|
|
67512
67562
|
},
|
67513
67563
|
renderChunk(code, _, { format }) {
|
67514
67564
|
// make sure we only perform the preload logic in modern builds.
|
67515
|
-
|
67565
|
+
const { environment } = this;
|
67566
|
+
if (environment && code.indexOf(isModernFlag) > -1) {
|
67516
67567
|
const re = new RegExp(isModernFlag, 'g');
|
67517
67568
|
const isModern = String(format === 'es');
|
67518
|
-
if (
|
67569
|
+
if (environment.options.build.sourcemap) {
|
67519
67570
|
const s = new MagicString(code);
|
67520
67571
|
let match;
|
67521
67572
|
while ((match = re.exec(code))) {
|
@@ -67533,9 +67584,14 @@ function buildImportAnalysisPlugin(config) {
|
|
67533
67584
|
return null;
|
67534
67585
|
},
|
67535
67586
|
generateBundle({ format }, bundle) {
|
67536
|
-
|
67587
|
+
const { environment } = this;
|
67588
|
+
const ssr = environment?.options.build.ssr;
|
67589
|
+
if (!environment || format !== 'es' || ssr || isWorker) {
|
67537
67590
|
return;
|
67538
67591
|
}
|
67592
|
+
const buildSourcemap = environment.options.build.sourcemap;
|
67593
|
+
const { modulePreload } = environment.options.build;
|
67594
|
+
const { customModulePreloadPaths, optimizeModulePreloadRelativePaths } = getModulePreloadData(environment);
|
67539
67595
|
for (const file in bundle) {
|
67540
67596
|
const chunk = bundle[file];
|
67541
67597
|
// can't use chunk.dynamicImports.length here since some modules e.g.
|
@@ -67712,7 +67768,7 @@ function buildImportAnalysisPlugin(config) {
|
|
67712
67768
|
}
|
67713
67769
|
if (s.hasChanged()) {
|
67714
67770
|
chunk.code = s.toString();
|
67715
|
-
if (
|
67771
|
+
if (buildSourcemap && chunk.map) {
|
67716
67772
|
const nextMap = s.generateMap({
|
67717
67773
|
source: chunk.fileName,
|
67718
67774
|
hires: 'boundary',
|
@@ -67723,11 +67779,11 @@ function buildImportAnalysisPlugin(config) {
|
|
67723
67779
|
]);
|
67724
67780
|
map.toUrl = () => genSourceMapUrl(map);
|
67725
67781
|
chunk.map = map;
|
67726
|
-
if (
|
67782
|
+
if (buildSourcemap === 'inline') {
|
67727
67783
|
chunk.code = chunk.code.replace(convertSourceMap.mapFileCommentRegex, '');
|
67728
67784
|
chunk.code += `\n//# sourceMappingURL=${genSourceMapUrl(map)}`;
|
67729
67785
|
}
|
67730
|
-
else if (
|
67786
|
+
else if (buildSourcemap) {
|
67731
67787
|
const mapAsset = bundle[chunk.fileName + '.map'];
|
67732
67788
|
if (mapAsset && mapAsset.type === 'asset') {
|
67733
67789
|
mapAsset.source = map.toString();
|
@@ -67988,7 +68044,7 @@ async function resolveBuildPlugins(config) {
|
|
67988
68044
|
...(options.minify ? [terserPlugin(config)] : []),
|
67989
68045
|
...(!config.isWorker
|
67990
68046
|
? [
|
67991
|
-
...(options.manifest ? [manifestPlugin(
|
68047
|
+
...(options.manifest ? [manifestPlugin()] : []),
|
67992
68048
|
...(options.ssrManifest ? [ssrManifestPlugin(config)] : []),
|
67993
68049
|
buildReporterPlugin(config),
|
67994
68050
|
]
|
@@ -68378,13 +68434,19 @@ function isExternal(id, test) {
|
|
68378
68434
|
return test.test(id);
|
68379
68435
|
}
|
68380
68436
|
}
|
68437
|
+
// TODO:
|
68438
|
+
// - Could we get Rollup to let us extends PluginContext in a more performant way?
|
68439
|
+
// - Extend for all hooks?
|
68381
68440
|
function injectEnvironmentToHooks(plugin, environment) {
|
68382
|
-
const { resolveId, load, transform } = plugin;
|
68441
|
+
const { buildStart, resolveId, load, transform, generateBundle, renderChunk, } = plugin;
|
68383
68442
|
return {
|
68384
68443
|
...plugin,
|
68385
68444
|
resolveId: wrapEnvironmentResolveId(resolveId, environment),
|
68386
68445
|
load: wrapEnvironmentLoad(load, environment),
|
68387
68446
|
transform: wrapEnvironmentTransform(transform, environment),
|
68447
|
+
buildStart: wrapEnvironmentHook(buildStart, environment),
|
68448
|
+
generateBundle: wrapEnvironmentHook(generateBundle, environment),
|
68449
|
+
renderChunk: wrapEnvironmentHook(renderChunk, environment),
|
68388
68450
|
};
|
68389
68451
|
}
|
68390
68452
|
function wrapEnvironmentResolveId(hook, environment) {
|
@@ -68438,6 +68500,23 @@ function wrapEnvironmentTransform(hook, environment) {
|
|
68438
68500
|
return handler;
|
68439
68501
|
}
|
68440
68502
|
}
|
68503
|
+
function wrapEnvironmentHook(hook, environment) {
|
68504
|
+
if (!hook)
|
68505
|
+
return;
|
68506
|
+
const fn = getHookHandler(hook);
|
68507
|
+
const handler = function (...args) {
|
68508
|
+
return fn.call(injectEnvironmentInContext(this, environment), ...args);
|
68509
|
+
};
|
68510
|
+
if ('handler' in hook) {
|
68511
|
+
return {
|
68512
|
+
...hook,
|
68513
|
+
handler,
|
68514
|
+
};
|
68515
|
+
}
|
68516
|
+
else {
|
68517
|
+
return handler;
|
68518
|
+
}
|
68519
|
+
}
|
68441
68520
|
function injectEnvironmentInContext(context, environment) {
|
68442
68521
|
return new Proxy(context, {
|
68443
68522
|
get(target, prop, receiver) {
|
@@ -68493,6 +68572,7 @@ const customRelativeUrlMechanisms = {
|
|
68493
68572
|
...relativeUrlMechanisms,
|
68494
68573
|
'worker-iife': (relativePath) => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', self.location.href`),
|
68495
68574
|
};
|
68575
|
+
// TODO: experimental.renderBuiltUrl => environment.build.renderBuiltUrl?
|
68496
68576
|
function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
|
68497
68577
|
const { renderBuiltUrl } = config.experimental;
|
68498
68578
|
let relative = config.base === '' || config.base === './';
|
@@ -69283,6 +69363,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
|
|
69283
69363
|
logger.warn(colors$1.yellow(`worker.plugins is now a function that returns an array of plugins. ` +
|
69284
69364
|
`Please update your Vite config accordingly.\n`));
|
69285
69365
|
}
|
69366
|
+
// TODO: Workers as environments could allow us to remove a lot of complexity
|
69286
69367
|
const createWorkerPlugins = async function (bundleChain) {
|
69287
69368
|
// Some plugins that aren't intended to work in the bundling of workers (doing post-processing at build time for example).
|
69288
69369
|
// And Plugins may also have cached that could be corrupted by being used in these extra rollup calls.
|
@@ -69310,7 +69391,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
|
|
69310
69391
|
await Promise.all(createPluginHookUtils(resolvedWorkerPlugins)
|
69311
69392
|
.getSortedPluginHooks('configResolved')
|
69312
69393
|
.map((hook) => hook(workerResolved)));
|
69313
|
-
return resolvedWorkerPlugins;
|
69394
|
+
return { plugins: resolvedWorkerPlugins, config: workerResolved };
|
69314
69395
|
};
|
69315
69396
|
const resolvedWorkerOptions = {
|
69316
69397
|
format: config.worker?.format || 'iife',
|
package/dist/node/cli.js
CHANGED
@@ -731,7 +731,7 @@ cli
|
|
731
731
|
filterDuplicateOptions(options);
|
732
732
|
// output structure is preserved even after bundling so require()
|
733
733
|
// is ok here
|
734
|
-
const { createServer } = await import('./chunks/dep-
|
734
|
+
const { createServer } = await import('./chunks/dep-o_W9DKGE.js').then(function (n) { return n.C; });
|
735
735
|
try {
|
736
736
|
const server = await createServer({
|
737
737
|
root,
|
@@ -812,7 +812,7 @@ cli
|
|
812
812
|
.option('--app', `[boolean] same as builder.entireApp`)
|
813
813
|
.action(async (root, options) => {
|
814
814
|
filterDuplicateOptions(options);
|
815
|
-
const { createBuilder, buildEnvironment } = await import('./chunks/dep-
|
815
|
+
const { createBuilder, buildEnvironment } = await import('./chunks/dep-o_W9DKGE.js').then(function (n) { return n.E; });
|
816
816
|
const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
|
817
817
|
const config = {
|
818
818
|
root,
|
@@ -888,7 +888,7 @@ cli
|
|
888
888
|
.option('--outDir <dir>', `[string] output directory (default: dist)`)
|
889
889
|
.action(async (root, options) => {
|
890
890
|
filterDuplicateOptions(options);
|
891
|
-
const { preview } = await import('./chunks/dep-
|
891
|
+
const { preview } = await import('./chunks/dep-o_W9DKGE.js').then(function (n) { return n.F; });
|
892
892
|
try {
|
893
893
|
const server = await preview({
|
894
894
|
root,
|
package/dist/node/index.d.ts
CHANGED
@@ -3252,6 +3252,15 @@ interface TransformPluginContext extends rollup.TransformPluginContext {
|
|
3252
3252
|
* Environment Plugins are closer to regular rollup plugins. They can't define
|
3253
3253
|
* app level hooks (like config, configResolved, configureServer, etc).
|
3254
3254
|
*/
|
3255
|
+
type ModifyFunctionContext<Function_, NewContext> = Function_ extends (this: infer This, ...parameters: infer Arguments) => infer Return ? (this: NewContext, ...parameters: Arguments) => Return : never;
|
3256
|
+
type ModifyObjectHookContext<Handler, Object_ extends {
|
3257
|
+
handler: Handler;
|
3258
|
+
}, NewContext> = Object_ & {
|
3259
|
+
handler: ModifyFunctionContext<Handler, NewContext>;
|
3260
|
+
};
|
3261
|
+
type ModifyHookContext<Hook, NewContext> = Hook extends {
|
3262
|
+
handler: infer Handler;
|
3263
|
+
} ? ModifyObjectHookContext<Handler, Hook, NewContext> : ModifyFunctionContext<Hook, NewContext>;
|
3255
3264
|
interface BasePlugin<A = any> extends rollup.Plugin<A> {
|
3256
3265
|
/**
|
3257
3266
|
* Perform custom handling of HMR updates.
|
@@ -3293,6 +3302,9 @@ interface BasePlugin<A = any> extends rollup.Plugin<A> {
|
|
3293
3302
|
*/
|
3294
3303
|
ssr?: boolean;
|
3295
3304
|
}) => Promise<rollup.TransformResult> | rollup.TransformResult>;
|
3305
|
+
buildStart?: ModifyHookContext<rollup.Plugin<A>['buildStart'], PluginContext>;
|
3306
|
+
generateBundle?: ModifyHookContext<rollup.Plugin<A>['generateBundle'], PluginContext>;
|
3307
|
+
renderChunk?: ModifyHookContext<rollup.Plugin<A>['renderChunk'], PluginContext>;
|
3296
3308
|
}
|
3297
3309
|
type BoundedPlugin<A = any> = BasePlugin<A>;
|
3298
3310
|
interface Plugin<A = any> extends BasePlugin<A> {
|
@@ -3825,7 +3837,10 @@ interface LegacyOptions {
|
|
3825
3837
|
}
|
3826
3838
|
interface ResolvedWorkerOptions {
|
3827
3839
|
format: 'es' | 'iife';
|
3828
|
-
plugins: (bundleChain: string[]) => Promise<
|
3840
|
+
plugins: (bundleChain: string[]) => Promise<{
|
3841
|
+
plugins: Plugin[];
|
3842
|
+
config: ResolvedConfig;
|
3843
|
+
}>;
|
3829
3844
|
rollupOptions: RollupOptions;
|
3830
3845
|
}
|
3831
3846
|
interface InlineConfig extends UserConfig {
|
package/dist/node/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
2
|
-
import { i as isInNodeModules, a as arraify } from './chunks/dep-
|
3
|
-
export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, e as createBuilder, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, o as mergeConfig, n as normalizePath, g as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-
|
2
|
+
import { i as isInNodeModules, a as arraify } from './chunks/dep-o_W9DKGE.js';
|
3
|
+
export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, e as createBuilder, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, o as mergeConfig, n as normalizePath, g as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-o_W9DKGE.js';
|
4
4
|
export { VERSION as version } from './constants.js';
|
5
5
|
export { version as esbuildVersion } from 'esbuild';
|
6
6
|
export { c as createLogger } from './chunks/dep-C7zR1Rh8.js';
|