vite 3.1.7 → 3.2.0-beta.1
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/client.d.ts +38 -11
- package/dist/client/client.mjs +27 -22
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-0ebb5606.js → dep-34b5a6bf.js} +1160 -702
- package/dist/node/chunks/{dep-42c2c4e4.js → dep-39e6741e.js} +0 -0
- package/dist/node/chunks/{dep-77359784.js → dep-46ac452b.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -1
- package/dist/node/index.d.ts +88 -165
- package/dist/node/index.js +1 -1
- package/dist/node-cjs/publicUtils.cjs +42 -28
- package/package.json +24 -17
- package/src/client/client.ts +4 -3
- package/src/client/overlay.ts +23 -19
- package/src/client/tsconfig.json +1 -1
- package/types/alias.d.ts +6 -59
- package/types/anymatch.d.ts +1 -5
- package/types/chokidar.d.ts +6 -224
- package/types/commonjs.d.ts +1 -230
- package/types/connect.d.ts +1 -111
- package/types/customEvent.d.ts +5 -0
- package/types/dynamicImportVars.d.ts +1 -17
- package/types/http-proxy.d.ts +1 -250
- package/types/importMeta.d.ts +7 -14
- package/types/package.json +1 -1
- package/types/terser.d.ts +1 -250
- package/types/ws.d.ts +1 -553
- package/types/shims.d.ts +0 -96
|
@@ -165,14 +165,21 @@ function getEntries({ entries, customResolver }) {
|
|
|
165
165
|
return { find: key, replacement: value, resolverFunction: resolverFunctionFromOptions };
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
+
function getHookFunction(hook) {
|
|
169
|
+
if (typeof hook === 'function') {
|
|
170
|
+
return hook;
|
|
171
|
+
}
|
|
172
|
+
if (hook && 'handler' in hook && typeof hook.handler === 'function') {
|
|
173
|
+
return hook.handler;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
168
177
|
function resolveCustomResolver(customResolver) {
|
|
178
|
+
if (typeof customResolver === 'function') {
|
|
179
|
+
return customResolver;
|
|
180
|
+
}
|
|
169
181
|
if (customResolver) {
|
|
170
|
-
|
|
171
|
-
return customResolver;
|
|
172
|
-
}
|
|
173
|
-
if (typeof customResolver.resolveId === 'function') {
|
|
174
|
-
return customResolver.resolveId;
|
|
175
|
-
}
|
|
182
|
+
return getHookFunction(customResolver.resolveId);
|
|
176
183
|
}
|
|
177
184
|
return null;
|
|
178
185
|
}
|
|
@@ -187,10 +194,7 @@ function alias$1(options = {}) {
|
|
|
187
194
|
return {
|
|
188
195
|
name: 'alias',
|
|
189
196
|
async buildStart(inputOptions) {
|
|
190
|
-
await Promise.all([...(Array.isArray(options.entries) ? options.entries : []), options].map(({ customResolver }) => customResolver &&
|
|
191
|
-
typeof customResolver === 'object' &&
|
|
192
|
-
typeof customResolver.buildStart === 'function' &&
|
|
193
|
-
customResolver.buildStart.call(this, inputOptions)));
|
|
197
|
+
await Promise.all([...(Array.isArray(options.entries) ? options.entries : []), options].map(({ customResolver }) => { var _a; return customResolver && ((_a = getHookFunction(customResolver.buildStart)) === null || _a === void 0 ? void 0 : _a.call(this, inputOptions)); }));
|
|
194
198
|
},
|
|
195
199
|
resolveId(importee, importer, resolveOptions) {
|
|
196
200
|
if (!importer) {
|
|
@@ -210,7 +214,7 @@ function alias$1(options = {}) {
|
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
var picomatch$
|
|
217
|
+
var picomatch$5 = {exports: {}};
|
|
214
218
|
|
|
215
219
|
var utils$k = {};
|
|
216
220
|
|
|
@@ -1960,9 +1964,9 @@ const isObject$4 = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
|
1960
1964
|
* @api public
|
|
1961
1965
|
*/
|
|
1962
1966
|
|
|
1963
|
-
const picomatch$
|
|
1967
|
+
const picomatch$4 = (glob, options, returnState = false) => {
|
|
1964
1968
|
if (Array.isArray(glob)) {
|
|
1965
|
-
const fns = glob.map(input => picomatch$
|
|
1969
|
+
const fns = glob.map(input => picomatch$4(input, options, returnState));
|
|
1966
1970
|
const arrayMatcher = str => {
|
|
1967
1971
|
for (const isMatch of fns) {
|
|
1968
1972
|
const state = isMatch(str);
|
|
@@ -1982,8 +1986,8 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
1982
1986
|
const opts = options || {};
|
|
1983
1987
|
const posix = utils$h.isWindows(options);
|
|
1984
1988
|
const regex = isState
|
|
1985
|
-
? picomatch$
|
|
1986
|
-
: picomatch$
|
|
1989
|
+
? picomatch$4.compileRe(glob, options)
|
|
1990
|
+
: picomatch$4.makeRe(glob, options, false, true);
|
|
1987
1991
|
|
|
1988
1992
|
const state = regex.state;
|
|
1989
1993
|
delete regex.state;
|
|
@@ -1991,11 +1995,11 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
1991
1995
|
let isIgnored = () => false;
|
|
1992
1996
|
if (opts.ignore) {
|
|
1993
1997
|
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1994
|
-
isIgnored = picomatch$
|
|
1998
|
+
isIgnored = picomatch$4(opts.ignore, ignoreOpts, returnState);
|
|
1995
1999
|
}
|
|
1996
2000
|
|
|
1997
2001
|
const matcher = (input, returnObject = false) => {
|
|
1998
|
-
const { isMatch, match, output } = picomatch$
|
|
2002
|
+
const { isMatch, match, output } = picomatch$4.test(input, regex, options, { glob, posix });
|
|
1999
2003
|
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
2000
2004
|
|
|
2001
2005
|
if (typeof opts.onResult === 'function') {
|
|
@@ -2045,7 +2049,7 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
2045
2049
|
* @api public
|
|
2046
2050
|
*/
|
|
2047
2051
|
|
|
2048
|
-
picomatch$
|
|
2052
|
+
picomatch$4.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2049
2053
|
if (typeof input !== 'string') {
|
|
2050
2054
|
throw new TypeError('Expected input to be a string');
|
|
2051
2055
|
}
|
|
@@ -2066,7 +2070,7 @@ picomatch$3.test = (input, regex, options, { glob, posix } = {}) => {
|
|
|
2066
2070
|
|
|
2067
2071
|
if (match === false || opts.capture === true) {
|
|
2068
2072
|
if (opts.matchBase === true || opts.basename === true) {
|
|
2069
|
-
match = picomatch$
|
|
2073
|
+
match = picomatch$4.matchBase(input, regex, options, posix);
|
|
2070
2074
|
} else {
|
|
2071
2075
|
match = regex.exec(output);
|
|
2072
2076
|
}
|
|
@@ -2089,8 +2093,8 @@ picomatch$3.test = (input, regex, options, { glob, posix } = {}) => {
|
|
|
2089
2093
|
* @api public
|
|
2090
2094
|
*/
|
|
2091
2095
|
|
|
2092
|
-
picomatch$
|
|
2093
|
-
const regex = glob instanceof RegExp ? glob : picomatch$
|
|
2096
|
+
picomatch$4.matchBase = (input, glob, options, posix = utils$h.isWindows(options)) => {
|
|
2097
|
+
const regex = glob instanceof RegExp ? glob : picomatch$4.makeRe(glob, options);
|
|
2094
2098
|
return regex.test(path$l.basename(input));
|
|
2095
2099
|
};
|
|
2096
2100
|
|
|
@@ -2111,7 +2115,7 @@ picomatch$3.matchBase = (input, glob, options, posix = utils$h.isWindows(options
|
|
|
2111
2115
|
* @api public
|
|
2112
2116
|
*/
|
|
2113
2117
|
|
|
2114
|
-
picomatch$
|
|
2118
|
+
picomatch$4.isMatch = (str, patterns, options) => picomatch$4(patterns, options)(str);
|
|
2115
2119
|
|
|
2116
2120
|
/**
|
|
2117
2121
|
* Parse a glob pattern to create the source string for a regular
|
|
@@ -2127,8 +2131,8 @@ picomatch$3.isMatch = (str, patterns, options) => picomatch$3(patterns, options)
|
|
|
2127
2131
|
* @api public
|
|
2128
2132
|
*/
|
|
2129
2133
|
|
|
2130
|
-
picomatch$
|
|
2131
|
-
if (Array.isArray(pattern)) return pattern.map(p => picomatch$
|
|
2134
|
+
picomatch$4.parse = (pattern, options) => {
|
|
2135
|
+
if (Array.isArray(pattern)) return pattern.map(p => picomatch$4.parse(p, options));
|
|
2132
2136
|
return parse$i(pattern, { ...options, fastpaths: false });
|
|
2133
2137
|
};
|
|
2134
2138
|
|
|
@@ -2159,7 +2163,7 @@ picomatch$3.parse = (pattern, options) => {
|
|
|
2159
2163
|
* @api public
|
|
2160
2164
|
*/
|
|
2161
2165
|
|
|
2162
|
-
picomatch$
|
|
2166
|
+
picomatch$4.scan = (input, options) => scan$1(input, options);
|
|
2163
2167
|
|
|
2164
2168
|
/**
|
|
2165
2169
|
* Compile a regular expression from the `state` object returned by the
|
|
@@ -2173,7 +2177,7 @@ picomatch$3.scan = (input, options) => scan$1(input, options);
|
|
|
2173
2177
|
* @api public
|
|
2174
2178
|
*/
|
|
2175
2179
|
|
|
2176
|
-
picomatch$
|
|
2180
|
+
picomatch$4.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2177
2181
|
if (returnOutput === true) {
|
|
2178
2182
|
return state.output;
|
|
2179
2183
|
}
|
|
@@ -2187,7 +2191,7 @@ picomatch$3.compileRe = (state, options, returnOutput = false, returnState = fal
|
|
|
2187
2191
|
source = `^(?!${source}).*$`;
|
|
2188
2192
|
}
|
|
2189
2193
|
|
|
2190
|
-
const regex = picomatch$
|
|
2194
|
+
const regex = picomatch$4.toRegex(source, options);
|
|
2191
2195
|
if (returnState === true) {
|
|
2192
2196
|
regex.state = state;
|
|
2193
2197
|
}
|
|
@@ -2214,7 +2218,7 @@ picomatch$3.compileRe = (state, options, returnOutput = false, returnState = fal
|
|
|
2214
2218
|
* @api public
|
|
2215
2219
|
*/
|
|
2216
2220
|
|
|
2217
|
-
picomatch$
|
|
2221
|
+
picomatch$4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2218
2222
|
if (!input || typeof input !== 'string') {
|
|
2219
2223
|
throw new TypeError('Expected a non-empty string');
|
|
2220
2224
|
}
|
|
@@ -2229,7 +2233,7 @@ picomatch$3.makeRe = (input, options = {}, returnOutput = false, returnState = f
|
|
|
2229
2233
|
parsed = parse$i(input, options);
|
|
2230
2234
|
}
|
|
2231
2235
|
|
|
2232
|
-
return picomatch$
|
|
2236
|
+
return picomatch$4.compileRe(parsed, options, returnOutput, returnState);
|
|
2233
2237
|
};
|
|
2234
2238
|
|
|
2235
2239
|
/**
|
|
@@ -2249,7 +2253,7 @@ picomatch$3.makeRe = (input, options = {}, returnOutput = false, returnState = f
|
|
|
2249
2253
|
* @api public
|
|
2250
2254
|
*/
|
|
2251
2255
|
|
|
2252
|
-
picomatch$
|
|
2256
|
+
picomatch$4.toRegex = (source, options) => {
|
|
2253
2257
|
try {
|
|
2254
2258
|
const opts = options || {};
|
|
2255
2259
|
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
|
@@ -2264,20 +2268,20 @@ picomatch$3.toRegex = (source, options) => {
|
|
|
2264
2268
|
* @return {Object}
|
|
2265
2269
|
*/
|
|
2266
2270
|
|
|
2267
|
-
picomatch$
|
|
2271
|
+
picomatch$4.constants = constants$4;
|
|
2268
2272
|
|
|
2269
2273
|
/**
|
|
2270
2274
|
* Expose "picomatch"
|
|
2271
2275
|
*/
|
|
2272
2276
|
|
|
2273
|
-
var picomatch_1 = picomatch$
|
|
2277
|
+
var picomatch_1 = picomatch$4;
|
|
2274
2278
|
|
|
2275
2279
|
(function (module) {
|
|
2276
2280
|
|
|
2277
2281
|
module.exports = picomatch_1;
|
|
2278
|
-
} (picomatch$
|
|
2282
|
+
} (picomatch$5));
|
|
2279
2283
|
|
|
2280
|
-
var
|
|
2284
|
+
var picomatch$3 = /*@__PURE__*/getDefaultExportFromCjs(picomatch$5.exports);
|
|
2281
2285
|
|
|
2282
2286
|
function walk$4(ast, { enter, leave }) {
|
|
2283
2287
|
return visit$2(ast, null, enter, leave);
|
|
@@ -2576,7 +2580,7 @@ const createFilter$2 = function createFilter(include, exclude, options) {
|
|
|
2576
2580
|
test: (what) => {
|
|
2577
2581
|
// this refactor is a tad overly verbose but makes for easy debugging
|
|
2578
2582
|
const pattern = getMatcherString$1(id, resolutionBase);
|
|
2579
|
-
const fn =
|
|
2583
|
+
const fn = picomatch$3(pattern, { dot: true });
|
|
2580
2584
|
const result = fn(what);
|
|
2581
2585
|
return result;
|
|
2582
2586
|
}
|
|
@@ -9645,16 +9649,30 @@ const schemeRegex = /^[\w+.-]+:\/\//;
|
|
|
9645
9649
|
* 3. Host, guaranteed.
|
|
9646
9650
|
* 4. Port, including ":", optional.
|
|
9647
9651
|
* 5. Path, including "/", optional.
|
|
9652
|
+
* 6. Query, including "?", optional.
|
|
9653
|
+
* 7. Hash, including "#", optional.
|
|
9648
9654
|
*/
|
|
9649
|
-
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?/;
|
|
9655
|
+
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
9650
9656
|
/**
|
|
9651
9657
|
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
9652
9658
|
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
9653
9659
|
*
|
|
9654
9660
|
* 1. Host, optional.
|
|
9655
|
-
* 2. Path, which may
|
|
9656
|
-
|
|
9657
|
-
|
|
9661
|
+
* 2. Path, which may include "/", guaranteed.
|
|
9662
|
+
* 3. Query, including "?", optional.
|
|
9663
|
+
* 4. Hash, including "#", optional.
|
|
9664
|
+
*/
|
|
9665
|
+
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
9666
|
+
var UrlType;
|
|
9667
|
+
(function (UrlType) {
|
|
9668
|
+
UrlType[UrlType["Empty"] = 1] = "Empty";
|
|
9669
|
+
UrlType[UrlType["Hash"] = 2] = "Hash";
|
|
9670
|
+
UrlType[UrlType["Query"] = 3] = "Query";
|
|
9671
|
+
UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
|
|
9672
|
+
UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
|
|
9673
|
+
UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
|
|
9674
|
+
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
9675
|
+
})(UrlType || (UrlType = {}));
|
|
9658
9676
|
function isAbsoluteUrl(input) {
|
|
9659
9677
|
return schemeRegex.test(input);
|
|
9660
9678
|
}
|
|
@@ -9667,35 +9685,42 @@ function isAbsolutePath(input) {
|
|
|
9667
9685
|
function isFileUrl(input) {
|
|
9668
9686
|
return input.startsWith('file:');
|
|
9669
9687
|
}
|
|
9688
|
+
function isRelative(input) {
|
|
9689
|
+
return /^[.?#]/.test(input);
|
|
9690
|
+
}
|
|
9670
9691
|
function parseAbsoluteUrl(input) {
|
|
9671
9692
|
const match = urlRegex.exec(input);
|
|
9672
|
-
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/');
|
|
9693
|
+
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
9673
9694
|
}
|
|
9674
9695
|
function parseFileUrl(input) {
|
|
9675
9696
|
const match = fileRegex.exec(input);
|
|
9676
9697
|
const path = match[2];
|
|
9677
|
-
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path);
|
|
9698
|
+
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
9678
9699
|
}
|
|
9679
|
-
function makeUrl(scheme, user, host, port, path) {
|
|
9700
|
+
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
9680
9701
|
return {
|
|
9681
9702
|
scheme,
|
|
9682
9703
|
user,
|
|
9683
9704
|
host,
|
|
9684
9705
|
port,
|
|
9685
9706
|
path,
|
|
9686
|
-
|
|
9707
|
+
query,
|
|
9708
|
+
hash,
|
|
9709
|
+
type: UrlType.Absolute,
|
|
9687
9710
|
};
|
|
9688
9711
|
}
|
|
9689
9712
|
function parseUrl$2(input) {
|
|
9690
9713
|
if (isSchemeRelativeUrl(input)) {
|
|
9691
9714
|
const url = parseAbsoluteUrl('http:' + input);
|
|
9692
9715
|
url.scheme = '';
|
|
9716
|
+
url.type = UrlType.SchemeRelative;
|
|
9693
9717
|
return url;
|
|
9694
9718
|
}
|
|
9695
9719
|
if (isAbsolutePath(input)) {
|
|
9696
9720
|
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
9697
9721
|
url.scheme = '';
|
|
9698
9722
|
url.host = '';
|
|
9723
|
+
url.type = UrlType.AbsolutePath;
|
|
9699
9724
|
return url;
|
|
9700
9725
|
}
|
|
9701
9726
|
if (isFileUrl(input))
|
|
@@ -9705,7 +9730,13 @@ function parseUrl$2(input) {
|
|
|
9705
9730
|
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
9706
9731
|
url.scheme = '';
|
|
9707
9732
|
url.host = '';
|
|
9708
|
-
url.
|
|
9733
|
+
url.type = input
|
|
9734
|
+
? input.startsWith('?')
|
|
9735
|
+
? UrlType.Query
|
|
9736
|
+
: input.startsWith('#')
|
|
9737
|
+
? UrlType.Hash
|
|
9738
|
+
: UrlType.RelativePath
|
|
9739
|
+
: UrlType.Empty;
|
|
9709
9740
|
return url;
|
|
9710
9741
|
}
|
|
9711
9742
|
function stripPathFilename(path) {
|
|
@@ -9717,10 +9748,7 @@ function stripPathFilename(path) {
|
|
|
9717
9748
|
return path.slice(0, index + 1);
|
|
9718
9749
|
}
|
|
9719
9750
|
function mergePaths(url, base) {
|
|
9720
|
-
|
|
9721
|
-
if (!url.relativePath)
|
|
9722
|
-
return;
|
|
9723
|
-
normalizePath$5(base);
|
|
9751
|
+
normalizePath$5(base, base.type);
|
|
9724
9752
|
// If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
|
|
9725
9753
|
// path).
|
|
9726
9754
|
if (url.path === '/') {
|
|
@@ -9730,15 +9758,13 @@ function mergePaths(url, base) {
|
|
|
9730
9758
|
// Resolution happens relative to the base path's directory, not the file.
|
|
9731
9759
|
url.path = stripPathFilename(base.path) + url.path;
|
|
9732
9760
|
}
|
|
9733
|
-
// If the base path is absolute, then our path is now absolute too.
|
|
9734
|
-
url.relativePath = base.relativePath;
|
|
9735
9761
|
}
|
|
9736
9762
|
/**
|
|
9737
9763
|
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
9738
9764
|
* "foo/.". We need to normalize to a standard representation.
|
|
9739
9765
|
*/
|
|
9740
|
-
function normalizePath$5(url) {
|
|
9741
|
-
const
|
|
9766
|
+
function normalizePath$5(url, type) {
|
|
9767
|
+
const rel = type <= UrlType.RelativePath;
|
|
9742
9768
|
const pieces = url.path.split('/');
|
|
9743
9769
|
// We need to preserve the first piece always, so that we output a leading slash. The item at
|
|
9744
9770
|
// pieces[0] is an empty string.
|
|
@@ -9770,7 +9796,7 @@ function normalizePath$5(url) {
|
|
|
9770
9796
|
positive--;
|
|
9771
9797
|
pointer--;
|
|
9772
9798
|
}
|
|
9773
|
-
else if (
|
|
9799
|
+
else if (rel) {
|
|
9774
9800
|
// If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
|
|
9775
9801
|
// URL, protocol relative URL, or an absolute path, we don't need to keep excess.
|
|
9776
9802
|
pieces[pointer++] = piece;
|
|
@@ -9798,37 +9824,60 @@ function resolve$3(input, base) {
|
|
|
9798
9824
|
if (!input && !base)
|
|
9799
9825
|
return '';
|
|
9800
9826
|
const url = parseUrl$2(input);
|
|
9801
|
-
|
|
9802
|
-
if (base &&
|
|
9827
|
+
let inputType = url.type;
|
|
9828
|
+
if (base && inputType !== UrlType.Absolute) {
|
|
9803
9829
|
const baseUrl = parseUrl$2(base);
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9830
|
+
const baseType = baseUrl.type;
|
|
9831
|
+
switch (inputType) {
|
|
9832
|
+
case UrlType.Empty:
|
|
9833
|
+
url.hash = baseUrl.hash;
|
|
9834
|
+
// fall through
|
|
9835
|
+
case UrlType.Hash:
|
|
9836
|
+
url.query = baseUrl.query;
|
|
9837
|
+
// fall through
|
|
9838
|
+
case UrlType.Query:
|
|
9839
|
+
case UrlType.RelativePath:
|
|
9840
|
+
mergePaths(url, baseUrl);
|
|
9841
|
+
// fall through
|
|
9842
|
+
case UrlType.AbsolutePath:
|
|
9843
|
+
// The host, user, and port are joined, you can't copy one without the others.
|
|
9844
|
+
url.user = baseUrl.user;
|
|
9845
|
+
url.host = baseUrl.host;
|
|
9846
|
+
url.port = baseUrl.port;
|
|
9847
|
+
// fall through
|
|
9848
|
+
case UrlType.SchemeRelative:
|
|
9849
|
+
// The input doesn't have a schema at least, so we need to copy at least that over.
|
|
9850
|
+
url.scheme = baseUrl.scheme;
|
|
9851
|
+
}
|
|
9852
|
+
if (baseType > inputType)
|
|
9853
|
+
inputType = baseType;
|
|
9854
|
+
}
|
|
9855
|
+
normalizePath$5(url, inputType);
|
|
9856
|
+
const queryHash = url.query + url.hash;
|
|
9857
|
+
switch (inputType) {
|
|
9858
|
+
// This is impossible, because of the empty checks at the start of the function.
|
|
9859
|
+
// case UrlType.Empty:
|
|
9860
|
+
case UrlType.Hash:
|
|
9861
|
+
case UrlType.Query:
|
|
9862
|
+
return queryHash;
|
|
9863
|
+
case UrlType.RelativePath: {
|
|
9864
|
+
// The first char is always a "/", and we need it to be relative.
|
|
9865
|
+
const path = url.path.slice(1);
|
|
9866
|
+
if (!path)
|
|
9867
|
+
return queryHash || '.';
|
|
9868
|
+
if (isRelative(base || input) && !isRelative(path)) {
|
|
9869
|
+
// If base started with a leading ".", or there is no base and input started with a ".",
|
|
9870
|
+
// then we need to ensure that the relative path starts with a ".". We don't know if
|
|
9871
|
+
// relative starts with a "..", though, so check before prepending.
|
|
9872
|
+
return './' + path + queryHash;
|
|
9873
|
+
}
|
|
9874
|
+
return path + queryHash;
|
|
9875
|
+
}
|
|
9876
|
+
case UrlType.AbsolutePath:
|
|
9877
|
+
return url.path + queryHash;
|
|
9878
|
+
default:
|
|
9879
|
+
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
9826
9880
|
}
|
|
9827
|
-
// If there's no host (and no scheme/user/port), then we need to output an absolute path.
|
|
9828
|
-
if (!url.scheme && !url.host)
|
|
9829
|
-
return url.path;
|
|
9830
|
-
// We're outputting either an absolute URL, or a protocol relative one.
|
|
9831
|
-
return `${url.scheme}//${url.user}${url.host}${url.port}${url.path}`;
|
|
9832
9881
|
}
|
|
9833
9882
|
|
|
9834
9883
|
function resolve$2(input, base) {
|
|
@@ -10033,7 +10082,9 @@ class TraceMap {
|
|
|
10033
10082
|
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
|
|
10034
10083
|
if (line >= decoded.length)
|
|
10035
10084
|
return null;
|
|
10036
|
-
|
|
10085
|
+
const segments = decoded[line];
|
|
10086
|
+
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
|
|
10087
|
+
return index === -1 ? null : segments[index];
|
|
10037
10088
|
};
|
|
10038
10089
|
originalPositionFor$1 = (map, { line, column, bias }) => {
|
|
10039
10090
|
line--;
|
|
@@ -10046,10 +10097,12 @@ class TraceMap {
|
|
|
10046
10097
|
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
|
|
10047
10098
|
if (line >= decoded.length)
|
|
10048
10099
|
return OMapping(null, null, null, null);
|
|
10049
|
-
const
|
|
10050
|
-
|
|
10100
|
+
const segments = decoded[line];
|
|
10101
|
+
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
10102
|
+
if (index === -1)
|
|
10051
10103
|
return OMapping(null, null, null, null);
|
|
10052
|
-
|
|
10104
|
+
const segment = segments[index];
|
|
10105
|
+
if (segment.length === 1)
|
|
10053
10106
|
return OMapping(null, null, null, null);
|
|
10054
10107
|
const { names, resolvedSources } = map;
|
|
10055
10108
|
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
@@ -10066,8 +10119,8 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
|
10066
10119
|
else if (bias === LEAST_UPPER_BOUND)
|
|
10067
10120
|
index++;
|
|
10068
10121
|
if (index === -1 || index === segments.length)
|
|
10069
|
-
return
|
|
10070
|
-
return
|
|
10122
|
+
return -1;
|
|
10123
|
+
return index;
|
|
10071
10124
|
}
|
|
10072
10125
|
|
|
10073
10126
|
/**
|
|
@@ -11494,7 +11547,7 @@ const createFilter$1 = function createFilter(include, exclude, options) {
|
|
|
11494
11547
|
test: (what) => {
|
|
11495
11548
|
// this refactor is a tad overly verbose but makes for easy debugging
|
|
11496
11549
|
const pattern = getMatcherString(id, resolutionBase);
|
|
11497
|
-
const fn =
|
|
11550
|
+
const fn = picomatch$3(pattern, { dot: true });
|
|
11498
11551
|
const result = fn(what);
|
|
11499
11552
|
return result;
|
|
11500
11553
|
}
|
|
@@ -11995,16 +12048,46 @@ function isFileReadable(filename) {
|
|
|
11995
12048
|
return false;
|
|
11996
12049
|
}
|
|
11997
12050
|
}
|
|
12051
|
+
const splitFirstDirRE = /(.+?)[\\/](.+)/;
|
|
11998
12052
|
/**
|
|
11999
12053
|
* Delete every file and subdirectory. **The given directory must exist.**
|
|
12000
|
-
* Pass an optional `skip` array to preserve files
|
|
12054
|
+
* Pass an optional `skip` array to preserve files under the root directory.
|
|
12001
12055
|
*/
|
|
12002
12056
|
function emptyDir(dir, skip) {
|
|
12057
|
+
const skipInDir = [];
|
|
12058
|
+
let nested = null;
|
|
12059
|
+
if (skip?.length) {
|
|
12060
|
+
for (const file of skip) {
|
|
12061
|
+
if (path$n.dirname(file) !== '.') {
|
|
12062
|
+
const matched = file.match(splitFirstDirRE);
|
|
12063
|
+
if (matched) {
|
|
12064
|
+
nested ?? (nested = new Map());
|
|
12065
|
+
const [, nestedDir, skipPath] = matched;
|
|
12066
|
+
let nestedSkip = nested.get(nestedDir);
|
|
12067
|
+
if (!nestedSkip) {
|
|
12068
|
+
nestedSkip = [];
|
|
12069
|
+
nested.set(nestedDir, nestedSkip);
|
|
12070
|
+
}
|
|
12071
|
+
if (!nestedSkip.includes(skipPath)) {
|
|
12072
|
+
nestedSkip.push(skipPath);
|
|
12073
|
+
}
|
|
12074
|
+
}
|
|
12075
|
+
}
|
|
12076
|
+
else {
|
|
12077
|
+
skipInDir.push(file);
|
|
12078
|
+
}
|
|
12079
|
+
}
|
|
12080
|
+
}
|
|
12003
12081
|
for (const file of fs$l.readdirSync(dir)) {
|
|
12004
|
-
if (
|
|
12082
|
+
if (skipInDir.includes(file)) {
|
|
12005
12083
|
continue;
|
|
12006
12084
|
}
|
|
12007
|
-
|
|
12085
|
+
if (nested?.has(file)) {
|
|
12086
|
+
emptyDir(path$n.resolve(dir, file), nested.get(file));
|
|
12087
|
+
}
|
|
12088
|
+
else {
|
|
12089
|
+
fs$l.rmSync(path$n.resolve(dir, file), { recursive: true, force: true });
|
|
12090
|
+
}
|
|
12008
12091
|
}
|
|
12009
12092
|
}
|
|
12010
12093
|
function copyDir(srcDir, destDir) {
|
|
@@ -15503,7 +15586,7 @@ var braces_1 = braces$2;
|
|
|
15503
15586
|
|
|
15504
15587
|
const util$1 = require$$0$6;
|
|
15505
15588
|
const braces$1 = braces_1;
|
|
15506
|
-
const picomatch$2 = picomatch$
|
|
15589
|
+
const picomatch$2 = picomatch$5.exports;
|
|
15507
15590
|
const utils$b = utils$k;
|
|
15508
15591
|
const isEmptyString = val => val === '' || val === './';
|
|
15509
15592
|
|
|
@@ -26127,11 +26210,10 @@ class Chunk {
|
|
|
26127
26210
|
this.storeName = false;
|
|
26128
26211
|
this.edited = false;
|
|
26129
26212
|
|
|
26130
|
-
|
|
26131
|
-
|
|
26132
|
-
|
|
26133
|
-
|
|
26134
|
-
});
|
|
26213
|
+
{
|
|
26214
|
+
this.previous = null;
|
|
26215
|
+
this.next = null;
|
|
26216
|
+
}
|
|
26135
26217
|
}
|
|
26136
26218
|
|
|
26137
26219
|
appendLeft(content) {
|
|
@@ -26774,6 +26856,11 @@ class MagicString {
|
|
|
26774
26856
|
}
|
|
26775
26857
|
|
|
26776
26858
|
overwrite(start, end, content, options) {
|
|
26859
|
+
options = options || {};
|
|
26860
|
+
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
26861
|
+
}
|
|
26862
|
+
|
|
26863
|
+
update(start, end, content, options) {
|
|
26777
26864
|
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
26778
26865
|
|
|
26779
26866
|
while (start < 0) start += this.original.length;
|
|
@@ -26799,7 +26886,7 @@ class MagicString {
|
|
|
26799
26886
|
options = { storeName: true };
|
|
26800
26887
|
}
|
|
26801
26888
|
const storeName = options !== undefined ? options.storeName : false;
|
|
26802
|
-
const
|
|
26889
|
+
const overwrite = options !== undefined ? options.overwrite : false;
|
|
26803
26890
|
|
|
26804
26891
|
if (storeName) {
|
|
26805
26892
|
const original = this.original.slice(start, end);
|
|
@@ -26823,7 +26910,7 @@ class MagicString {
|
|
|
26823
26910
|
chunk.edit('', false);
|
|
26824
26911
|
}
|
|
26825
26912
|
|
|
26826
|
-
first.edit(content, storeName,
|
|
26913
|
+
first.edit(content, storeName, !overwrite);
|
|
26827
26914
|
} else {
|
|
26828
26915
|
// must be inserting at the end
|
|
26829
26916
|
const newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
@@ -27142,7 +27229,7 @@ class MagicString {
|
|
|
27142
27229
|
return this.original !== this.toString();
|
|
27143
27230
|
}
|
|
27144
27231
|
|
|
27145
|
-
|
|
27232
|
+
_replaceRegexp(searchValue, replacement) {
|
|
27146
27233
|
function getReplacement(match, str) {
|
|
27147
27234
|
if (typeof replacement === 'string') {
|
|
27148
27235
|
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
@@ -27165,7 +27252,7 @@ class MagicString {
|
|
|
27165
27252
|
}
|
|
27166
27253
|
return matches;
|
|
27167
27254
|
}
|
|
27168
|
-
if (
|
|
27255
|
+
if (searchValue.global) {
|
|
27169
27256
|
const matches = matchAll(searchValue, this.original);
|
|
27170
27257
|
matches.forEach((match) => {
|
|
27171
27258
|
if (match.index != null)
|
|
@@ -27186,6 +27273,53 @@ class MagicString {
|
|
|
27186
27273
|
}
|
|
27187
27274
|
return this;
|
|
27188
27275
|
}
|
|
27276
|
+
|
|
27277
|
+
_replaceString(string, replacement) {
|
|
27278
|
+
const { original } = this;
|
|
27279
|
+
const index = original.indexOf(string);
|
|
27280
|
+
|
|
27281
|
+
if (index !== -1) {
|
|
27282
|
+
this.overwrite(index, index + string.length, replacement);
|
|
27283
|
+
}
|
|
27284
|
+
|
|
27285
|
+
return this;
|
|
27286
|
+
}
|
|
27287
|
+
|
|
27288
|
+
replace(searchValue, replacement) {
|
|
27289
|
+
if (typeof searchValue === 'string') {
|
|
27290
|
+
return this._replaceString(searchValue, replacement);
|
|
27291
|
+
}
|
|
27292
|
+
|
|
27293
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
27294
|
+
}
|
|
27295
|
+
|
|
27296
|
+
_replaceAllString(string, replacement) {
|
|
27297
|
+
const { original } = this;
|
|
27298
|
+
const stringLength = string.length;
|
|
27299
|
+
for (
|
|
27300
|
+
let index = original.indexOf(string);
|
|
27301
|
+
index !== -1;
|
|
27302
|
+
index = original.indexOf(string, index + stringLength)
|
|
27303
|
+
) {
|
|
27304
|
+
this.overwrite(index, index + stringLength, replacement);
|
|
27305
|
+
}
|
|
27306
|
+
|
|
27307
|
+
return this;
|
|
27308
|
+
}
|
|
27309
|
+
|
|
27310
|
+
replaceAll(searchValue, replacement) {
|
|
27311
|
+
if (typeof searchValue === 'string') {
|
|
27312
|
+
return this._replaceAllString(searchValue, replacement);
|
|
27313
|
+
}
|
|
27314
|
+
|
|
27315
|
+
if (!searchValue.global) {
|
|
27316
|
+
throw new TypeError(
|
|
27317
|
+
'MagicString.prototype.replaceAll called with a non-global RegExp argument'
|
|
27318
|
+
);
|
|
27319
|
+
}
|
|
27320
|
+
|
|
27321
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
27322
|
+
}
|
|
27189
27323
|
}
|
|
27190
27324
|
|
|
27191
27325
|
const isDebug$6 = !!process.env.DEBUG;
|
|
@@ -32875,7 +33009,7 @@ function stripLiteralAcorn(code) {
|
|
|
32875
33009
|
}
|
|
32876
33010
|
|
|
32877
33011
|
const multilineCommentsRE = /\/\*.*?\*\//gms;
|
|
32878
|
-
const singlelineCommentsRE =
|
|
33012
|
+
const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm;
|
|
32879
33013
|
const templateLiteralRE = /\$\{(\s*(?:(?!\$\{).|\n|\r)*?\s*)\}/g;
|
|
32880
33014
|
const quotesRE = [
|
|
32881
33015
|
/(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm,
|
|
@@ -33323,6 +33457,7 @@ function lookup(extn) {
|
|
|
33323
33457
|
}
|
|
33324
33458
|
|
|
33325
33459
|
const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g;
|
|
33460
|
+
const duplicateAssets = new WeakMap();
|
|
33326
33461
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
33327
33462
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
33328
33463
|
const assetCache = new WeakMap();
|
|
@@ -33341,6 +33476,7 @@ function registerCustomMime() {
|
|
|
33341
33476
|
mimes$1['eot'] = 'application/vnd.ms-fontobject';
|
|
33342
33477
|
}
|
|
33343
33478
|
function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
33479
|
+
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(opts.format);
|
|
33344
33480
|
let match;
|
|
33345
33481
|
let s;
|
|
33346
33482
|
// Urls added with JS using e.g.
|
|
@@ -33356,13 +33492,11 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
|
33356
33492
|
const file = getAssetFilename(hash, config) || ctx.getFileName(hash);
|
|
33357
33493
|
chunk.viteMetadata.importedAssets.add(cleanUrl(file));
|
|
33358
33494
|
const filename = file + postfix;
|
|
33359
|
-
const replacement =
|
|
33495
|
+
const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
33360
33496
|
const replacementString = typeof replacement === 'string'
|
|
33361
33497
|
? JSON.stringify(replacement).slice(1, -1)
|
|
33362
33498
|
: `"+${replacement.runtime}+"`;
|
|
33363
|
-
s.
|
|
33364
|
-
contentOnly: true
|
|
33365
|
-
});
|
|
33499
|
+
s.update(match.index, match.index + full.length, replacementString);
|
|
33366
33500
|
}
|
|
33367
33501
|
// Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths
|
|
33368
33502
|
const publicAssetUrlMap = publicAssetUrlCache.get(config);
|
|
@@ -33370,13 +33504,11 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
|
33370
33504
|
s || (s = new MagicString(code));
|
|
33371
33505
|
const [full, hash] = match;
|
|
33372
33506
|
const publicUrl = publicAssetUrlMap.get(hash).slice(1);
|
|
33373
|
-
const replacement =
|
|
33507
|
+
const replacement = toOutputFilePathInJS(publicUrl, 'public', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
33374
33508
|
const replacementString = typeof replacement === 'string'
|
|
33375
33509
|
? JSON.stringify(replacement).slice(1, -1)
|
|
33376
33510
|
: `"+${replacement.runtime}+"`;
|
|
33377
|
-
s.
|
|
33378
|
-
contentOnly: true
|
|
33379
|
-
});
|
|
33511
|
+
s.update(match.index, match.index + full.length, replacementString);
|
|
33380
33512
|
}
|
|
33381
33513
|
return s;
|
|
33382
33514
|
}
|
|
@@ -33392,6 +33524,7 @@ function assetPlugin(config) {
|
|
|
33392
33524
|
buildStart() {
|
|
33393
33525
|
assetCache.set(config, new Map());
|
|
33394
33526
|
emittedHashMap.set(config, new Set());
|
|
33527
|
+
duplicateAssets.set(config, new Map());
|
|
33395
33528
|
},
|
|
33396
33529
|
resolveId(id) {
|
|
33397
33530
|
if (!config.assetsInclude(cleanUrl(id))) {
|
|
@@ -33651,8 +33784,9 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
|
33651
33784
|
map.set(contentHash, fileName);
|
|
33652
33785
|
}
|
|
33653
33786
|
const emittedSet = emittedHashMap.get(config);
|
|
33787
|
+
const duplicates = duplicateAssets.get(config);
|
|
33788
|
+
const name = normalizePath$3(path$n.relative(config.root, file));
|
|
33654
33789
|
if (!emittedSet.has(contentHash)) {
|
|
33655
|
-
const name = normalizePath$3(path$n.relative(config.root, file));
|
|
33656
33790
|
pluginContext.emitFile({
|
|
33657
33791
|
name,
|
|
33658
33792
|
fileName,
|
|
@@ -33661,6 +33795,15 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
|
33661
33795
|
});
|
|
33662
33796
|
emittedSet.add(contentHash);
|
|
33663
33797
|
}
|
|
33798
|
+
else {
|
|
33799
|
+
duplicates.set(name, {
|
|
33800
|
+
name,
|
|
33801
|
+
fileName: map.get(contentHash),
|
|
33802
|
+
type: 'asset',
|
|
33803
|
+
source: content,
|
|
33804
|
+
isAsset: true
|
|
33805
|
+
});
|
|
33806
|
+
}
|
|
33664
33807
|
url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
|
|
33665
33808
|
}
|
|
33666
33809
|
cache.set(id, url);
|
|
@@ -34184,6 +34327,282 @@ function watchPackageDataPlugin(config) {
|
|
|
34184
34327
|
};
|
|
34185
34328
|
}
|
|
34186
34329
|
|
|
34330
|
+
const WORKER_FILE_ID = 'worker_file';
|
|
34331
|
+
const workerCache = new WeakMap();
|
|
34332
|
+
function isWorkerRequest(id) {
|
|
34333
|
+
const query = parseRequest(id);
|
|
34334
|
+
if (query && query[WORKER_FILE_ID] != null) {
|
|
34335
|
+
return true;
|
|
34336
|
+
}
|
|
34337
|
+
return false;
|
|
34338
|
+
}
|
|
34339
|
+
function saveEmitWorkerAsset(config, asset) {
|
|
34340
|
+
const fileName = asset.fileName;
|
|
34341
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34342
|
+
workerMap.assets.set(fileName, asset);
|
|
34343
|
+
}
|
|
34344
|
+
async function bundleWorkerEntry(config, id, query) {
|
|
34345
|
+
// bundle the file as entry to support imports
|
|
34346
|
+
const { rollup } = await import('rollup');
|
|
34347
|
+
const { plugins, rollupOptions, format } = config.worker;
|
|
34348
|
+
const bundle = await rollup({
|
|
34349
|
+
...rollupOptions,
|
|
34350
|
+
input: cleanUrl(id),
|
|
34351
|
+
plugins,
|
|
34352
|
+
onwarn(warning, warn) {
|
|
34353
|
+
onRollupWarning(warning, warn, config);
|
|
34354
|
+
},
|
|
34355
|
+
preserveEntrySignatures: false
|
|
34356
|
+
});
|
|
34357
|
+
let chunk;
|
|
34358
|
+
try {
|
|
34359
|
+
const workerOutputConfig = config.worker.rollupOptions.output;
|
|
34360
|
+
const workerConfig = workerOutputConfig
|
|
34361
|
+
? Array.isArray(workerOutputConfig)
|
|
34362
|
+
? workerOutputConfig[0] || {}
|
|
34363
|
+
: workerOutputConfig
|
|
34364
|
+
: {};
|
|
34365
|
+
const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
|
|
34366
|
+
entryFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
34367
|
+
chunkFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
34368
|
+
assetFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].[ext]'),
|
|
34369
|
+
...workerConfig,
|
|
34370
|
+
format,
|
|
34371
|
+
sourcemap: config.build.sourcemap
|
|
34372
|
+
});
|
|
34373
|
+
chunk = outputChunk;
|
|
34374
|
+
outputChunks.forEach((outputChunk) => {
|
|
34375
|
+
if (outputChunk.type === 'asset') {
|
|
34376
|
+
saveEmitWorkerAsset(config, outputChunk);
|
|
34377
|
+
}
|
|
34378
|
+
else if (outputChunk.type === 'chunk') {
|
|
34379
|
+
saveEmitWorkerAsset(config, {
|
|
34380
|
+
fileName: outputChunk.fileName,
|
|
34381
|
+
source: outputChunk.code,
|
|
34382
|
+
type: 'asset'
|
|
34383
|
+
});
|
|
34384
|
+
}
|
|
34385
|
+
});
|
|
34386
|
+
}
|
|
34387
|
+
finally {
|
|
34388
|
+
await bundle.close();
|
|
34389
|
+
}
|
|
34390
|
+
return emitSourcemapForWorkerEntry(config, query, chunk);
|
|
34391
|
+
}
|
|
34392
|
+
function emitSourcemapForWorkerEntry(config, query, chunk) {
|
|
34393
|
+
const { map: sourcemap } = chunk;
|
|
34394
|
+
if (sourcemap) {
|
|
34395
|
+
if (config.build.sourcemap === 'inline') {
|
|
34396
|
+
// Manually add the sourcemap to the code if configured for inline sourcemaps.
|
|
34397
|
+
// TODO: Remove when https://github.com/rollup/rollup/issues/3913 is resolved
|
|
34398
|
+
// Currently seems that it won't be resolved until Rollup 3
|
|
34399
|
+
const dataUrl = sourcemap.toUrl();
|
|
34400
|
+
chunk.code += `//# sourceMappingURL=${dataUrl}`;
|
|
34401
|
+
}
|
|
34402
|
+
else if (config.build.sourcemap === 'hidden' ||
|
|
34403
|
+
config.build.sourcemap === true) {
|
|
34404
|
+
const data = sourcemap.toString();
|
|
34405
|
+
const mapFileName = chunk.fileName + '.map';
|
|
34406
|
+
saveEmitWorkerAsset(config, {
|
|
34407
|
+
fileName: mapFileName,
|
|
34408
|
+
type: 'asset',
|
|
34409
|
+
source: data
|
|
34410
|
+
});
|
|
34411
|
+
// Emit the comment that tells the JS debugger where it can find the
|
|
34412
|
+
// sourcemap file.
|
|
34413
|
+
// 'hidden' causes the sourcemap file to be created but
|
|
34414
|
+
// the comment in the file to be omitted.
|
|
34415
|
+
if (config.build.sourcemap === true) {
|
|
34416
|
+
// inline web workers need to use the full sourcemap path
|
|
34417
|
+
// non-inline web workers can use a relative path
|
|
34418
|
+
const sourceMapUrl = query?.inline != null
|
|
34419
|
+
? mapFileName
|
|
34420
|
+
: path$n.relative(config.build.assetsDir, mapFileName);
|
|
34421
|
+
chunk.code += `//# sourceMappingURL=${sourceMapUrl}`;
|
|
34422
|
+
}
|
|
34423
|
+
}
|
|
34424
|
+
}
|
|
34425
|
+
return chunk;
|
|
34426
|
+
}
|
|
34427
|
+
const workerAssetUrlRE = /__VITE_WORKER_ASSET__([a-z\d]{8})__/g;
|
|
34428
|
+
function encodeWorkerAssetFileName(fileName, workerCache) {
|
|
34429
|
+
const { fileNameHash } = workerCache;
|
|
34430
|
+
const hash = getHash(fileName);
|
|
34431
|
+
if (!fileNameHash.get(hash)) {
|
|
34432
|
+
fileNameHash.set(hash, fileName);
|
|
34433
|
+
}
|
|
34434
|
+
return `__VITE_WORKER_ASSET__${hash}__`;
|
|
34435
|
+
}
|
|
34436
|
+
async function workerFileToUrl(config, id, query) {
|
|
34437
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34438
|
+
let fileName = workerMap.bundle.get(id);
|
|
34439
|
+
if (!fileName) {
|
|
34440
|
+
const outputChunk = await bundleWorkerEntry(config, id, query);
|
|
34441
|
+
fileName = outputChunk.fileName;
|
|
34442
|
+
saveEmitWorkerAsset(config, {
|
|
34443
|
+
fileName,
|
|
34444
|
+
source: outputChunk.code,
|
|
34445
|
+
type: 'asset'
|
|
34446
|
+
});
|
|
34447
|
+
workerMap.bundle.set(id, fileName);
|
|
34448
|
+
}
|
|
34449
|
+
return encodeWorkerAssetFileName(fileName, workerMap);
|
|
34450
|
+
}
|
|
34451
|
+
function webWorkerPlugin(config) {
|
|
34452
|
+
const isBuild = config.command === 'build';
|
|
34453
|
+
let server;
|
|
34454
|
+
const isWorker = config.isWorker;
|
|
34455
|
+
return {
|
|
34456
|
+
name: 'vite:worker',
|
|
34457
|
+
configureServer(_server) {
|
|
34458
|
+
server = _server;
|
|
34459
|
+
},
|
|
34460
|
+
buildStart() {
|
|
34461
|
+
if (isWorker) {
|
|
34462
|
+
return;
|
|
34463
|
+
}
|
|
34464
|
+
workerCache.set(config, {
|
|
34465
|
+
assets: new Map(),
|
|
34466
|
+
bundle: new Map(),
|
|
34467
|
+
fileNameHash: new Map()
|
|
34468
|
+
});
|
|
34469
|
+
},
|
|
34470
|
+
load(id) {
|
|
34471
|
+
if (isBuild) {
|
|
34472
|
+
const parsedQuery = parseRequest(id);
|
|
34473
|
+
if (parsedQuery &&
|
|
34474
|
+
(parsedQuery.worker ?? parsedQuery.sharedworker) != null) {
|
|
34475
|
+
return '';
|
|
34476
|
+
}
|
|
34477
|
+
}
|
|
34478
|
+
},
|
|
34479
|
+
async transform(raw, id, options) {
|
|
34480
|
+
const ssr = options?.ssr === true;
|
|
34481
|
+
const query = parseRequest(id);
|
|
34482
|
+
if (query && query[WORKER_FILE_ID] != null) {
|
|
34483
|
+
// if import worker by worker constructor will have query.type
|
|
34484
|
+
// other type will be import worker by esm
|
|
34485
|
+
const workerType = query['type'];
|
|
34486
|
+
let injectEnv = '';
|
|
34487
|
+
if (workerType === 'classic') {
|
|
34488
|
+
injectEnv = `importScripts('${ENV_PUBLIC_PATH}')\n`;
|
|
34489
|
+
}
|
|
34490
|
+
else if (workerType === 'module') {
|
|
34491
|
+
injectEnv = `import '${ENV_PUBLIC_PATH}'\n`;
|
|
34492
|
+
}
|
|
34493
|
+
else if (workerType === 'ignore') {
|
|
34494
|
+
if (isBuild) {
|
|
34495
|
+
injectEnv = '';
|
|
34496
|
+
}
|
|
34497
|
+
else if (server) {
|
|
34498
|
+
// dynamic worker type we can't know how import the env
|
|
34499
|
+
// so we copy /@vite/env code of server transform result into file header
|
|
34500
|
+
const { moduleGraph } = server;
|
|
34501
|
+
const module = moduleGraph.getModuleById(ENV_ENTRY);
|
|
34502
|
+
injectEnv = module?.transformResult?.code || '';
|
|
34503
|
+
}
|
|
34504
|
+
}
|
|
34505
|
+
return {
|
|
34506
|
+
code: injectEnv + raw
|
|
34507
|
+
};
|
|
34508
|
+
}
|
|
34509
|
+
if (query == null ||
|
|
34510
|
+
(query && (query.worker ?? query.sharedworker) == null)) {
|
|
34511
|
+
return;
|
|
34512
|
+
}
|
|
34513
|
+
// stringified url or `new URL(...)`
|
|
34514
|
+
let url;
|
|
34515
|
+
const { format } = config.worker;
|
|
34516
|
+
const workerConstructor = query.sharedworker != null ? 'SharedWorker' : 'Worker';
|
|
34517
|
+
const workerType = isBuild
|
|
34518
|
+
? format === 'es'
|
|
34519
|
+
? 'module'
|
|
34520
|
+
: 'classic'
|
|
34521
|
+
: 'module';
|
|
34522
|
+
const workerOptions = workerType === 'classic' ? '' : ',{type: "module"}';
|
|
34523
|
+
if (isBuild) {
|
|
34524
|
+
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
34525
|
+
if (query.inline != null) {
|
|
34526
|
+
const chunk = await bundleWorkerEntry(config, id, query);
|
|
34527
|
+
// inline as blob data url
|
|
34528
|
+
return {
|
|
34529
|
+
code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
|
|
34530
|
+
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
|
|
34531
|
+
export default function WorkerWrapper() {
|
|
34532
|
+
const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
|
|
34533
|
+
try {
|
|
34534
|
+
return objURL ? new ${workerConstructor}(objURL) : new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
|
|
34535
|
+
} finally {
|
|
34536
|
+
objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
|
|
34537
|
+
}
|
|
34538
|
+
}`,
|
|
34539
|
+
// Empty sourcemap to suppress Rollup warning
|
|
34540
|
+
map: { mappings: '' }
|
|
34541
|
+
};
|
|
34542
|
+
}
|
|
34543
|
+
else {
|
|
34544
|
+
url = await workerFileToUrl(config, id, query);
|
|
34545
|
+
}
|
|
34546
|
+
}
|
|
34547
|
+
else {
|
|
34548
|
+
url = await fileToUrl(cleanUrl(id), config, this);
|
|
34549
|
+
url = injectQuery(url, WORKER_FILE_ID);
|
|
34550
|
+
url = injectQuery(url, `type=${workerType}`);
|
|
34551
|
+
}
|
|
34552
|
+
if (query.url != null) {
|
|
34553
|
+
return {
|
|
34554
|
+
code: `export default ${JSON.stringify(url)}`,
|
|
34555
|
+
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
34556
|
+
};
|
|
34557
|
+
}
|
|
34558
|
+
return {
|
|
34559
|
+
code: `export default function WorkerWrapper() {
|
|
34560
|
+
return new ${workerConstructor}(${JSON.stringify(url)}${workerOptions})
|
|
34561
|
+
}`,
|
|
34562
|
+
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
34563
|
+
};
|
|
34564
|
+
},
|
|
34565
|
+
renderChunk(code, chunk, outputOptions) {
|
|
34566
|
+
let s;
|
|
34567
|
+
const result = () => {
|
|
34568
|
+
return (s && {
|
|
34569
|
+
code: s.toString(),
|
|
34570
|
+
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
34571
|
+
});
|
|
34572
|
+
};
|
|
34573
|
+
if (code.match(workerAssetUrlRE) || code.includes('import.meta.url')) {
|
|
34574
|
+
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format);
|
|
34575
|
+
let match;
|
|
34576
|
+
s = new MagicString(code);
|
|
34577
|
+
// Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
|
|
34578
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34579
|
+
const { fileNameHash } = workerMap;
|
|
34580
|
+
while ((match = workerAssetUrlRE.exec(code))) {
|
|
34581
|
+
const [full, hash] = match;
|
|
34582
|
+
const filename = fileNameHash.get(hash);
|
|
34583
|
+
const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
34584
|
+
const replacementString = typeof replacement === 'string'
|
|
34585
|
+
? JSON.stringify(replacement).slice(1, -1)
|
|
34586
|
+
: `"+${replacement.runtime}+"`;
|
|
34587
|
+
s.update(match.index, match.index + full.length, replacementString);
|
|
34588
|
+
}
|
|
34589
|
+
}
|
|
34590
|
+
return result();
|
|
34591
|
+
},
|
|
34592
|
+
generateBundle(opts) {
|
|
34593
|
+
// @ts-ignore asset emits are skipped in legacy bundle
|
|
34594
|
+
if (opts.__vite_skip_asset_emit__ || isWorker) {
|
|
34595
|
+
return;
|
|
34596
|
+
}
|
|
34597
|
+
const workerMap = workerCache.get(config);
|
|
34598
|
+
workerMap.assets.forEach((asset) => {
|
|
34599
|
+
this.emitFile(asset);
|
|
34600
|
+
workerMap.assets.delete(asset.fileName);
|
|
34601
|
+
});
|
|
34602
|
+
}
|
|
34603
|
+
};
|
|
34604
|
+
}
|
|
34605
|
+
|
|
34187
34606
|
const normalizedClientEntry$1 = normalizePath$3(CLIENT_ENTRY);
|
|
34188
34607
|
const normalizedEnvEntry$1 = normalizePath$3(ENV_ENTRY);
|
|
34189
34608
|
// special id for paths marked with browser: false
|
|
@@ -34218,12 +34637,15 @@ function resolvePlugin(resolveOptions) {
|
|
|
34218
34637
|
scan: resolveOpts?.scan ?? resolveOptions.scan
|
|
34219
34638
|
};
|
|
34220
34639
|
if (importer) {
|
|
34221
|
-
|
|
34640
|
+
const _importer = isWorkerRequest(importer)
|
|
34641
|
+
? splitFileAndPostfix(importer).file
|
|
34642
|
+
: importer;
|
|
34643
|
+
if (isTsRequest(_importer) ||
|
|
34222
34644
|
resolveOpts.custom?.depScan?.loader?.startsWith('ts')) {
|
|
34223
34645
|
options.isFromTsImporter = true;
|
|
34224
34646
|
}
|
|
34225
34647
|
else {
|
|
34226
|
-
const moduleLang = this.getModuleInfo(
|
|
34648
|
+
const moduleLang = this.getModuleInfo(_importer)?.meta?.vite?.lang;
|
|
34227
34649
|
options.isFromTsImporter = moduleLang && isTsRequest(`.${moduleLang}`);
|
|
34228
34650
|
}
|
|
34229
34651
|
}
|
|
@@ -34294,6 +34716,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
34294
34716
|
return normalizedFsPath;
|
|
34295
34717
|
}
|
|
34296
34718
|
if (targetWeb &&
|
|
34719
|
+
options.browserField &&
|
|
34297
34720
|
(res = tryResolveBrowserMapping(fsPath, importer, options, true))) {
|
|
34298
34721
|
return res;
|
|
34299
34722
|
}
|
|
@@ -34351,6 +34774,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
34351
34774
|
return res;
|
|
34352
34775
|
}
|
|
34353
34776
|
if (targetWeb &&
|
|
34777
|
+
options.browserField &&
|
|
34354
34778
|
(res = tryResolveBrowserMapping(id, importer, options, false, external))) {
|
|
34355
34779
|
return res;
|
|
34356
34780
|
}
|
|
@@ -34438,7 +34862,7 @@ function tryFsResolve(fsPath, options, tryIndex = true, targetWeb = true) {
|
|
|
34438
34862
|
if ((res = tryResolveFile(file, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
34439
34863
|
return res;
|
|
34440
34864
|
}
|
|
34441
|
-
for (const ext of options.extensions
|
|
34865
|
+
for (const ext of options.extensions) {
|
|
34442
34866
|
if (postfix &&
|
|
34443
34867
|
(res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
34444
34868
|
return res;
|
|
@@ -34761,7 +35185,9 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34761
35185
|
// This is because .mjs files can technically import .cjs files which would
|
|
34762
35186
|
// make them invalid for pure ESM environments - so if other module/browser
|
|
34763
35187
|
// fields are present, prioritize those instead.
|
|
34764
|
-
if (targetWeb &&
|
|
35188
|
+
if (targetWeb &&
|
|
35189
|
+
options.browserField &&
|
|
35190
|
+
(!entryPoint || entryPoint.endsWith('.mjs'))) {
|
|
34765
35191
|
// check browser field
|
|
34766
35192
|
// https://github.com/defunctzombie/package-browser-field-spec
|
|
34767
35193
|
const browserEntry = typeof data.browser === 'string'
|
|
@@ -34770,6 +35196,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34770
35196
|
if (browserEntry) {
|
|
34771
35197
|
// check if the package also has a "module" field.
|
|
34772
35198
|
if (!options.isRequire &&
|
|
35199
|
+
options.mainFields.includes('module') &&
|
|
34773
35200
|
typeof data.module === 'string' &&
|
|
34774
35201
|
data.module !== browserEntry) {
|
|
34775
35202
|
// if both are present, we may have a problem: some package points both
|
|
@@ -34797,7 +35224,9 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34797
35224
|
}
|
|
34798
35225
|
}
|
|
34799
35226
|
if (!entryPoint || entryPoint.endsWith('.mjs')) {
|
|
34800
|
-
for (const field of options.mainFields
|
|
35227
|
+
for (const field of options.mainFields) {
|
|
35228
|
+
if (field === 'browser')
|
|
35229
|
+
continue; // already checked above
|
|
34801
35230
|
if (typeof data[field] === 'string') {
|
|
34802
35231
|
entryPoint = data[field];
|
|
34803
35232
|
break;
|
|
@@ -34812,14 +35241,14 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34812
35241
|
: ['index.js', 'index.json', 'index.node'];
|
|
34813
35242
|
for (let entry of entryPoints) {
|
|
34814
35243
|
// make sure we don't get scripts when looking for sass
|
|
34815
|
-
if (options.mainFields
|
|
34816
|
-
!options.extensions
|
|
35244
|
+
if (options.mainFields[0] === 'sass' &&
|
|
35245
|
+
!options.extensions.includes(path$n.extname(entry))) {
|
|
34817
35246
|
entry = '';
|
|
34818
35247
|
options.skipPackageJson = true;
|
|
34819
35248
|
}
|
|
34820
35249
|
// resolve object browser field in package.json
|
|
34821
35250
|
const { browser: browserField } = data;
|
|
34822
|
-
if (targetWeb && isObject$2(browserField)) {
|
|
35251
|
+
if (targetWeb && options.browserField && isObject$2(browserField)) {
|
|
34823
35252
|
entry = mapWithBrowserField(entry, browserField) || entry;
|
|
34824
35253
|
}
|
|
34825
35254
|
const entryPointPath = path$n.join(dir, entry);
|
|
@@ -34847,12 +35276,12 @@ function resolveExports(pkg, key, options, targetWeb) {
|
|
|
34847
35276
|
if (!options.isRequire) {
|
|
34848
35277
|
conditions.push('module');
|
|
34849
35278
|
}
|
|
34850
|
-
if (options.conditions) {
|
|
35279
|
+
if (options.conditions.length > 0) {
|
|
34851
35280
|
conditions.push(...options.conditions);
|
|
34852
35281
|
}
|
|
34853
35282
|
return resolve(pkg, key, {
|
|
34854
|
-
browser: targetWeb,
|
|
34855
|
-
require: options.isRequire,
|
|
35283
|
+
browser: targetWeb && !conditions.includes('node'),
|
|
35284
|
+
require: options.isRequire && !conditions.includes('import'),
|
|
34856
35285
|
conditions
|
|
34857
35286
|
});
|
|
34858
35287
|
}
|
|
@@ -34885,7 +35314,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
34885
35314
|
`${path$n.join(dir, 'package.json')}.`);
|
|
34886
35315
|
}
|
|
34887
35316
|
}
|
|
34888
|
-
else if (targetWeb && isObject$2(browserField)) {
|
|
35317
|
+
else if (targetWeb && options.browserField && isObject$2(browserField)) {
|
|
34889
35318
|
// resolve without postfix (see #7098)
|
|
34890
35319
|
const { file, postfix } = splitFileAndPostfix(relativeId);
|
|
34891
35320
|
const mapped = mapWithBrowserField(file, browserField);
|
|
@@ -34909,7 +35338,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
34909
35338
|
}
|
|
34910
35339
|
function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize) {
|
|
34911
35340
|
let res;
|
|
34912
|
-
const pkg = importer && idToPkgMap.get(importer);
|
|
35341
|
+
const pkg = importer && (idToPkgMap.get(importer) || resolvePkg(importer, options));
|
|
34913
35342
|
if (pkg && isObject$2(pkg.data.browser)) {
|
|
34914
35343
|
const mapId = isFilePath ? './' + slash$1(path$n.relative(pkg.dir, id)) : id;
|
|
34915
35344
|
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
|
|
@@ -34960,6 +35389,36 @@ function getRealPath(resolved, preserveSymlinks) {
|
|
|
34960
35389
|
}
|
|
34961
35390
|
return normalizePath$3(resolved);
|
|
34962
35391
|
}
|
|
35392
|
+
/**
|
|
35393
|
+
* if importer was not resolved by vite's resolver previously
|
|
35394
|
+
* (when esbuild resolved it)
|
|
35395
|
+
* resolve importer's pkg and add to idToPkgMap
|
|
35396
|
+
*/
|
|
35397
|
+
function resolvePkg(importer, options) {
|
|
35398
|
+
const { root, preserveSymlinks, packageCache } = options;
|
|
35399
|
+
if (importer.includes('\x00')) {
|
|
35400
|
+
return null;
|
|
35401
|
+
}
|
|
35402
|
+
const possiblePkgIds = [];
|
|
35403
|
+
for (let prevSlashIndex = -1;;) {
|
|
35404
|
+
const slashIndex = importer.indexOf(isWindows$4 ? '\\' : '/', prevSlashIndex);
|
|
35405
|
+
if (slashIndex < 0) {
|
|
35406
|
+
break;
|
|
35407
|
+
}
|
|
35408
|
+
prevSlashIndex = slashIndex + 1;
|
|
35409
|
+
const possiblePkgId = importer.slice(0, slashIndex);
|
|
35410
|
+
possiblePkgIds.push(possiblePkgId);
|
|
35411
|
+
}
|
|
35412
|
+
let pkg;
|
|
35413
|
+
possiblePkgIds.reverse().find((pkgId) => {
|
|
35414
|
+
pkg = resolvePackageData(pkgId, root, preserveSymlinks, packageCache);
|
|
35415
|
+
return pkg;
|
|
35416
|
+
});
|
|
35417
|
+
if (pkg) {
|
|
35418
|
+
idToPkgMap.set(importer, pkg);
|
|
35419
|
+
}
|
|
35420
|
+
return pkg;
|
|
35421
|
+
}
|
|
34963
35422
|
|
|
34964
35423
|
const externalWithConversionNamespace = 'vite:dep-pre-bundle:external-conversion';
|
|
34965
35424
|
const convertedExternalPrefix = 'vite-dep-pre-bundle-external:';
|
|
@@ -35256,7 +35715,7 @@ function cjsSsrResolveExternals(config, knownImports) {
|
|
|
35256
35715
|
ssrExternals.add(id);
|
|
35257
35716
|
seen.add(id);
|
|
35258
35717
|
});
|
|
35259
|
-
cjsSsrCollectExternals(config.root, config.resolve
|
|
35718
|
+
cjsSsrCollectExternals(config.root, config.resolve, ssrExternals, seen, config.logger);
|
|
35260
35719
|
const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
|
|
35261
35720
|
for (const dep of importedDeps) {
|
|
35262
35721
|
// Assume external if not yet seen
|
|
@@ -35294,8 +35753,8 @@ function createIsConfiguredAsSsrExternal(config) {
|
|
|
35294
35753
|
typeof noExternal !== 'boolean' &&
|
|
35295
35754
|
createFilter(undefined, noExternal, { resolve: false });
|
|
35296
35755
|
const resolveOptions = {
|
|
35756
|
+
...config.resolve,
|
|
35297
35757
|
root,
|
|
35298
|
-
preserveSymlinks: config.resolve.preserveSymlinks,
|
|
35299
35758
|
isProduction: false,
|
|
35300
35759
|
isBuild: true
|
|
35301
35760
|
};
|
|
@@ -35366,7 +35825,7 @@ function createIsSsrExternal(config) {
|
|
|
35366
35825
|
}
|
|
35367
35826
|
// When config.experimental.buildSsrCjsExternalHeuristics is enabled, this function
|
|
35368
35827
|
// is used reverting to the Vite 2.9 SSR externalization heuristics
|
|
35369
|
-
function cjsSsrCollectExternals(root,
|
|
35828
|
+
function cjsSsrCollectExternals(root, resolveOptions, ssrExternals, seen, logger) {
|
|
35370
35829
|
const rootPkgContent = lookupFile(root, ['package.json']);
|
|
35371
35830
|
if (!rootPkgContent) {
|
|
35372
35831
|
return;
|
|
@@ -35376,9 +35835,9 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35376
35835
|
...rootPkg.devDependencies,
|
|
35377
35836
|
...rootPkg.dependencies
|
|
35378
35837
|
};
|
|
35379
|
-
const
|
|
35838
|
+
const internalResolveOptions = {
|
|
35839
|
+
...resolveOptions,
|
|
35380
35840
|
root,
|
|
35381
|
-
preserveSymlinks,
|
|
35382
35841
|
isProduction: false,
|
|
35383
35842
|
isBuild: true
|
|
35384
35843
|
};
|
|
@@ -35390,7 +35849,7 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35390
35849
|
let esmEntry;
|
|
35391
35850
|
let requireEntry;
|
|
35392
35851
|
try {
|
|
35393
|
-
esmEntry = tryNodeResolve(id, undefined,
|
|
35852
|
+
esmEntry = tryNodeResolve(id, undefined, internalResolveOptions, true, // we set `targetWeb` to `true` to get the ESM entry
|
|
35394
35853
|
undefined, true)?.id;
|
|
35395
35854
|
// normalizePath required for windows. tryNodeResolve uses normalizePath
|
|
35396
35855
|
// which returns with '/', require.resolve returns with '\\'
|
|
@@ -35450,7 +35909,7 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35450
35909
|
}
|
|
35451
35910
|
}
|
|
35452
35911
|
for (const depRoot of depsToTrace) {
|
|
35453
|
-
cjsSsrCollectExternals(depRoot,
|
|
35912
|
+
cjsSsrCollectExternals(depRoot, resolveOptions, ssrExternals, seen, logger);
|
|
35454
35913
|
}
|
|
35455
35914
|
}
|
|
35456
35915
|
function cjsShouldExternalizeForSSR(id, externals) {
|
|
@@ -35682,11 +36141,11 @@ function throwOutdatedRequest(id) {
|
|
|
35682
36141
|
throw err;
|
|
35683
36142
|
}
|
|
35684
36143
|
|
|
35685
|
-
const { isMatch: isMatch$
|
|
36144
|
+
const { isMatch: isMatch$1, scan } = micromatch_1;
|
|
35686
36145
|
function getAffectedGlobModules(file, server) {
|
|
35687
36146
|
const modules = [];
|
|
35688
36147
|
for (const [id, allGlobs] of server._importGlobMap) {
|
|
35689
|
-
if (allGlobs.some((glob) => isMatch$
|
|
36148
|
+
if (allGlobs.some((glob) => isMatch$1(file, glob)))
|
|
35690
36149
|
modules.push(...(server.moduleGraph.getModulesByFile(id) || []));
|
|
35691
36150
|
}
|
|
35692
36151
|
modules.forEach((i) => {
|
|
@@ -36867,7 +37326,7 @@ function parse$a(req) {
|
|
|
36867
37326
|
|
|
36868
37327
|
const noop$2 = () => {};
|
|
36869
37328
|
|
|
36870
|
-
function isMatch
|
|
37329
|
+
function isMatch(uri, arr) {
|
|
36871
37330
|
for (let i=0; i < arr.length; i++) {
|
|
36872
37331
|
if (arr[i].test(uri)) return true;
|
|
36873
37332
|
}
|
|
@@ -37033,7 +37492,7 @@ function sirv (dir, opts={}) {
|
|
|
37033
37492
|
catch (err) { /* malform uri */ }
|
|
37034
37493
|
}
|
|
37035
37494
|
|
|
37036
|
-
let data = lookup(pathname, extns) || isSPA && !isMatch
|
|
37495
|
+
let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
|
|
37037
37496
|
if (!data) return next ? next() : isNotFound(req, res);
|
|
37038
37497
|
|
|
37039
37498
|
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
|
|
@@ -37050,7 +37509,6 @@ function sirv (dir, opts={}) {
|
|
|
37050
37509
|
};
|
|
37051
37510
|
}
|
|
37052
37511
|
|
|
37053
|
-
const { isMatch } = micromatch_1;
|
|
37054
37512
|
const sirvOptions = (headers) => {
|
|
37055
37513
|
return {
|
|
37056
37514
|
dev: true,
|
|
@@ -37159,12 +37617,11 @@ function serveRawFsMiddleware(server) {
|
|
|
37159
37617
|
}
|
|
37160
37618
|
};
|
|
37161
37619
|
}
|
|
37162
|
-
const _matchOptions = { matchBase: true };
|
|
37163
37620
|
function isFileServingAllowed(url, server) {
|
|
37164
37621
|
if (!server.config.server.fs.strict)
|
|
37165
37622
|
return true;
|
|
37166
37623
|
const file = fsPathFromUrl(url);
|
|
37167
|
-
if (server.
|
|
37624
|
+
if (server._fsDenyGlob(file))
|
|
37168
37625
|
return false;
|
|
37169
37626
|
if (server.moduleGraph.safeModulesPath.has(file))
|
|
37170
37627
|
return true;
|
|
@@ -37479,7 +37936,7 @@ function extractImportedBindings(id, source, importSpec, importedBindings) {
|
|
|
37479
37936
|
* ```
|
|
37480
37937
|
*
|
|
37481
37938
|
* - CSS imports are appended with `.js` since both the js module and the actual
|
|
37482
|
-
* css (referenced via
|
|
37939
|
+
* css (referenced via `<link>`) may go through the transform pipeline:
|
|
37483
37940
|
*
|
|
37484
37941
|
* ```js
|
|
37485
37942
|
* import './style.css'
|
|
@@ -37513,8 +37970,8 @@ function importAnalysisPlugin(config) {
|
|
|
37513
37970
|
}
|
|
37514
37971
|
const start = performance.now();
|
|
37515
37972
|
await init;
|
|
37516
|
-
let imports
|
|
37517
|
-
let exports
|
|
37973
|
+
let imports;
|
|
37974
|
+
let exports;
|
|
37518
37975
|
source = stripBomTag(source);
|
|
37519
37976
|
try {
|
|
37520
37977
|
[imports, exports] = parse$b(source);
|
|
@@ -38163,276 +38620,6 @@ const wasmFallbackPlugin = () => {
|
|
|
38163
38620
|
};
|
|
38164
38621
|
};
|
|
38165
38622
|
|
|
38166
|
-
const WORKER_FILE_ID = 'worker_file';
|
|
38167
|
-
const workerCache = new WeakMap();
|
|
38168
|
-
function saveEmitWorkerAsset(config, asset) {
|
|
38169
|
-
const fileName = asset.fileName;
|
|
38170
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38171
|
-
workerMap.assets.set(fileName, asset);
|
|
38172
|
-
}
|
|
38173
|
-
async function bundleWorkerEntry(config, id, query) {
|
|
38174
|
-
// bundle the file as entry to support imports
|
|
38175
|
-
const { rollup } = await import('rollup');
|
|
38176
|
-
const { plugins, rollupOptions, format } = config.worker;
|
|
38177
|
-
const bundle = await rollup({
|
|
38178
|
-
...rollupOptions,
|
|
38179
|
-
input: cleanUrl(id),
|
|
38180
|
-
plugins,
|
|
38181
|
-
onwarn(warning, warn) {
|
|
38182
|
-
onRollupWarning(warning, warn, config);
|
|
38183
|
-
},
|
|
38184
|
-
preserveEntrySignatures: false
|
|
38185
|
-
});
|
|
38186
|
-
let chunk;
|
|
38187
|
-
try {
|
|
38188
|
-
const workerOutputConfig = config.worker.rollupOptions.output;
|
|
38189
|
-
const workerConfig = workerOutputConfig
|
|
38190
|
-
? Array.isArray(workerOutputConfig)
|
|
38191
|
-
? workerOutputConfig[0] || {}
|
|
38192
|
-
: workerOutputConfig
|
|
38193
|
-
: {};
|
|
38194
|
-
const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
|
|
38195
|
-
entryFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
38196
|
-
chunkFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
38197
|
-
assetFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].[ext]'),
|
|
38198
|
-
...workerConfig,
|
|
38199
|
-
format,
|
|
38200
|
-
sourcemap: config.build.sourcemap
|
|
38201
|
-
});
|
|
38202
|
-
chunk = outputChunk;
|
|
38203
|
-
outputChunks.forEach((outputChunk) => {
|
|
38204
|
-
if (outputChunk.type === 'asset') {
|
|
38205
|
-
saveEmitWorkerAsset(config, outputChunk);
|
|
38206
|
-
}
|
|
38207
|
-
else if (outputChunk.type === 'chunk') {
|
|
38208
|
-
saveEmitWorkerAsset(config, {
|
|
38209
|
-
fileName: outputChunk.fileName,
|
|
38210
|
-
source: outputChunk.code,
|
|
38211
|
-
type: 'asset'
|
|
38212
|
-
});
|
|
38213
|
-
}
|
|
38214
|
-
});
|
|
38215
|
-
}
|
|
38216
|
-
finally {
|
|
38217
|
-
await bundle.close();
|
|
38218
|
-
}
|
|
38219
|
-
return emitSourcemapForWorkerEntry(config, query, chunk);
|
|
38220
|
-
}
|
|
38221
|
-
function emitSourcemapForWorkerEntry(config, query, chunk) {
|
|
38222
|
-
const { map: sourcemap } = chunk;
|
|
38223
|
-
if (sourcemap) {
|
|
38224
|
-
if (config.build.sourcemap === 'inline') {
|
|
38225
|
-
// Manually add the sourcemap to the code if configured for inline sourcemaps.
|
|
38226
|
-
// TODO: Remove when https://github.com/rollup/rollup/issues/3913 is resolved
|
|
38227
|
-
// Currently seems that it won't be resolved until Rollup 3
|
|
38228
|
-
const dataUrl = sourcemap.toUrl();
|
|
38229
|
-
chunk.code += `//# sourceMappingURL=${dataUrl}`;
|
|
38230
|
-
}
|
|
38231
|
-
else if (config.build.sourcemap === 'hidden' ||
|
|
38232
|
-
config.build.sourcemap === true) {
|
|
38233
|
-
const data = sourcemap.toString();
|
|
38234
|
-
const mapFileName = chunk.fileName + '.map';
|
|
38235
|
-
saveEmitWorkerAsset(config, {
|
|
38236
|
-
fileName: mapFileName,
|
|
38237
|
-
type: 'asset',
|
|
38238
|
-
source: data
|
|
38239
|
-
});
|
|
38240
|
-
// Emit the comment that tells the JS debugger where it can find the
|
|
38241
|
-
// sourcemap file.
|
|
38242
|
-
// 'hidden' causes the sourcemap file to be created but
|
|
38243
|
-
// the comment in the file to be omitted.
|
|
38244
|
-
if (config.build.sourcemap === true) {
|
|
38245
|
-
// inline web workers need to use the full sourcemap path
|
|
38246
|
-
// non-inline web workers can use a relative path
|
|
38247
|
-
const sourceMapUrl = query?.inline != null
|
|
38248
|
-
? mapFileName
|
|
38249
|
-
: path$n.relative(config.build.assetsDir, mapFileName);
|
|
38250
|
-
chunk.code += `//# sourceMappingURL=${sourceMapUrl}`;
|
|
38251
|
-
}
|
|
38252
|
-
}
|
|
38253
|
-
}
|
|
38254
|
-
return chunk;
|
|
38255
|
-
}
|
|
38256
|
-
const workerAssetUrlRE = /__VITE_WORKER_ASSET__([a-z\d]{8})__/g;
|
|
38257
|
-
function encodeWorkerAssetFileName(fileName, workerCache) {
|
|
38258
|
-
const { fileNameHash } = workerCache;
|
|
38259
|
-
const hash = getHash(fileName);
|
|
38260
|
-
if (!fileNameHash.get(hash)) {
|
|
38261
|
-
fileNameHash.set(hash, fileName);
|
|
38262
|
-
}
|
|
38263
|
-
return `__VITE_WORKER_ASSET__${hash}__`;
|
|
38264
|
-
}
|
|
38265
|
-
async function workerFileToUrl(config, id, query) {
|
|
38266
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38267
|
-
let fileName = workerMap.bundle.get(id);
|
|
38268
|
-
if (!fileName) {
|
|
38269
|
-
const outputChunk = await bundleWorkerEntry(config, id, query);
|
|
38270
|
-
fileName = outputChunk.fileName;
|
|
38271
|
-
saveEmitWorkerAsset(config, {
|
|
38272
|
-
fileName,
|
|
38273
|
-
source: outputChunk.code,
|
|
38274
|
-
type: 'asset'
|
|
38275
|
-
});
|
|
38276
|
-
workerMap.bundle.set(id, fileName);
|
|
38277
|
-
}
|
|
38278
|
-
return encodeWorkerAssetFileName(fileName, workerMap);
|
|
38279
|
-
}
|
|
38280
|
-
function webWorkerPlugin(config) {
|
|
38281
|
-
const isBuild = config.command === 'build';
|
|
38282
|
-
let server;
|
|
38283
|
-
const isWorker = config.isWorker;
|
|
38284
|
-
return {
|
|
38285
|
-
name: 'vite:worker',
|
|
38286
|
-
configureServer(_server) {
|
|
38287
|
-
server = _server;
|
|
38288
|
-
},
|
|
38289
|
-
buildStart() {
|
|
38290
|
-
if (isWorker) {
|
|
38291
|
-
return;
|
|
38292
|
-
}
|
|
38293
|
-
workerCache.set(config, {
|
|
38294
|
-
assets: new Map(),
|
|
38295
|
-
bundle: new Map(),
|
|
38296
|
-
fileNameHash: new Map()
|
|
38297
|
-
});
|
|
38298
|
-
},
|
|
38299
|
-
load(id) {
|
|
38300
|
-
if (isBuild) {
|
|
38301
|
-
const parsedQuery = parseRequest(id);
|
|
38302
|
-
if (parsedQuery &&
|
|
38303
|
-
(parsedQuery.worker ?? parsedQuery.sharedworker) != null) {
|
|
38304
|
-
return '';
|
|
38305
|
-
}
|
|
38306
|
-
}
|
|
38307
|
-
},
|
|
38308
|
-
async transform(raw, id, options) {
|
|
38309
|
-
const ssr = options?.ssr === true;
|
|
38310
|
-
const query = parseRequest(id);
|
|
38311
|
-
if (query && query[WORKER_FILE_ID] != null) {
|
|
38312
|
-
// if import worker by worker constructor will have query.type
|
|
38313
|
-
// other type will be import worker by esm
|
|
38314
|
-
const workerType = query['type'];
|
|
38315
|
-
let injectEnv = '';
|
|
38316
|
-
if (workerType === 'classic') {
|
|
38317
|
-
injectEnv = `importScripts('${ENV_PUBLIC_PATH}')\n`;
|
|
38318
|
-
}
|
|
38319
|
-
else if (workerType === 'module') {
|
|
38320
|
-
injectEnv = `import '${ENV_PUBLIC_PATH}'\n`;
|
|
38321
|
-
}
|
|
38322
|
-
else if (workerType === 'ignore') {
|
|
38323
|
-
if (isBuild) {
|
|
38324
|
-
injectEnv = '';
|
|
38325
|
-
}
|
|
38326
|
-
else if (server) {
|
|
38327
|
-
// dynamic worker type we can't know how import the env
|
|
38328
|
-
// so we copy /@vite/env code of server transform result into file header
|
|
38329
|
-
const { moduleGraph } = server;
|
|
38330
|
-
const module = moduleGraph.getModuleById(ENV_ENTRY);
|
|
38331
|
-
injectEnv = module?.transformResult?.code || '';
|
|
38332
|
-
}
|
|
38333
|
-
}
|
|
38334
|
-
return {
|
|
38335
|
-
code: injectEnv + raw
|
|
38336
|
-
};
|
|
38337
|
-
}
|
|
38338
|
-
if (query == null ||
|
|
38339
|
-
(query && (query.worker ?? query.sharedworker) == null)) {
|
|
38340
|
-
return;
|
|
38341
|
-
}
|
|
38342
|
-
// stringified url or `new URL(...)`
|
|
38343
|
-
let url;
|
|
38344
|
-
const { format } = config.worker;
|
|
38345
|
-
const workerConstructor = query.sharedworker != null ? 'SharedWorker' : 'Worker';
|
|
38346
|
-
const workerType = isBuild
|
|
38347
|
-
? format === 'es'
|
|
38348
|
-
? 'module'
|
|
38349
|
-
: 'classic'
|
|
38350
|
-
: 'module';
|
|
38351
|
-
const workerOptions = workerType === 'classic' ? '' : ',{type: "module"}';
|
|
38352
|
-
if (isBuild) {
|
|
38353
|
-
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
38354
|
-
if (query.inline != null) {
|
|
38355
|
-
const chunk = await bundleWorkerEntry(config, id, query);
|
|
38356
|
-
// inline as blob data url
|
|
38357
|
-
return {
|
|
38358
|
-
code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
|
|
38359
|
-
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
|
|
38360
|
-
export default function WorkerWrapper() {
|
|
38361
|
-
const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
|
|
38362
|
-
try {
|
|
38363
|
-
return objURL ? new ${workerConstructor}(objURL) : new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
|
|
38364
|
-
} finally {
|
|
38365
|
-
objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
|
|
38366
|
-
}
|
|
38367
|
-
}`,
|
|
38368
|
-
// Empty sourcemap to suppress Rollup warning
|
|
38369
|
-
map: { mappings: '' }
|
|
38370
|
-
};
|
|
38371
|
-
}
|
|
38372
|
-
else {
|
|
38373
|
-
url = await workerFileToUrl(config, id, query);
|
|
38374
|
-
}
|
|
38375
|
-
}
|
|
38376
|
-
else {
|
|
38377
|
-
url = await fileToUrl(cleanUrl(id), config, this);
|
|
38378
|
-
url = injectQuery(url, WORKER_FILE_ID);
|
|
38379
|
-
url = injectQuery(url, `type=${workerType}`);
|
|
38380
|
-
}
|
|
38381
|
-
if (query.url != null) {
|
|
38382
|
-
return {
|
|
38383
|
-
code: `export default ${JSON.stringify(url)}`,
|
|
38384
|
-
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
38385
|
-
};
|
|
38386
|
-
}
|
|
38387
|
-
return {
|
|
38388
|
-
code: `export default function WorkerWrapper() {
|
|
38389
|
-
return new ${workerConstructor}(${JSON.stringify(url)}${workerOptions})
|
|
38390
|
-
}`,
|
|
38391
|
-
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
38392
|
-
};
|
|
38393
|
-
},
|
|
38394
|
-
renderChunk(code, chunk, outputOptions) {
|
|
38395
|
-
let s;
|
|
38396
|
-
const result = () => {
|
|
38397
|
-
return (s && {
|
|
38398
|
-
code: s.toString(),
|
|
38399
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
38400
|
-
});
|
|
38401
|
-
};
|
|
38402
|
-
if (code.match(workerAssetUrlRE) || code.includes('import.meta.url')) {
|
|
38403
|
-
let match;
|
|
38404
|
-
s = new MagicString(code);
|
|
38405
|
-
// Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
|
|
38406
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38407
|
-
const { fileNameHash } = workerMap;
|
|
38408
|
-
while ((match = workerAssetUrlRE.exec(code))) {
|
|
38409
|
-
const [full, hash] = match;
|
|
38410
|
-
const filename = fileNameHash.get(hash);
|
|
38411
|
-
const replacement = toOutputFilePathInString(filename, 'asset', chunk.fileName, 'js', config, outputOptions.format);
|
|
38412
|
-
const replacementString = typeof replacement === 'string'
|
|
38413
|
-
? JSON.stringify(replacement).slice(1, -1)
|
|
38414
|
-
: `"+${replacement.runtime}+"`;
|
|
38415
|
-
s.overwrite(match.index, match.index + full.length, replacementString, {
|
|
38416
|
-
contentOnly: true
|
|
38417
|
-
});
|
|
38418
|
-
}
|
|
38419
|
-
}
|
|
38420
|
-
return result();
|
|
38421
|
-
},
|
|
38422
|
-
generateBundle(opts) {
|
|
38423
|
-
// @ts-ignore asset emits are skipped in legacy bundle
|
|
38424
|
-
if (opts.__vite_skip_asset_emit__ || isWorker) {
|
|
38425
|
-
return;
|
|
38426
|
-
}
|
|
38427
|
-
const workerMap = workerCache.get(config);
|
|
38428
|
-
workerMap.assets.forEach((asset) => {
|
|
38429
|
-
this.emitFile(asset);
|
|
38430
|
-
workerMap.assets.delete(asset.fileName);
|
|
38431
|
-
});
|
|
38432
|
-
}
|
|
38433
|
-
};
|
|
38434
|
-
}
|
|
38435
|
-
|
|
38436
38623
|
/**
|
|
38437
38624
|
* A plugin to avoid an aliased AND optimized dep from being aliased in src
|
|
38438
38625
|
*/
|
|
@@ -38630,7 +38817,7 @@ function definePlugin(config) {
|
|
|
38630
38817
|
const start = match.index;
|
|
38631
38818
|
const end = start + match[0].length;
|
|
38632
38819
|
const replacement = '' + replacements[match[1]];
|
|
38633
|
-
s.
|
|
38820
|
+
s.update(start, end, replacement);
|
|
38634
38821
|
}
|
|
38635
38822
|
if (!hasReplaced) {
|
|
38636
38823
|
return null;
|
|
@@ -38648,7 +38835,7 @@ function definePlugin(config) {
|
|
|
38648
38835
|
function ssrRequireHookPlugin(config) {
|
|
38649
38836
|
if (config.command !== 'build' ||
|
|
38650
38837
|
!config.build.ssr ||
|
|
38651
|
-
!config.resolve.dedupe
|
|
38838
|
+
!config.resolve.dedupe.length ||
|
|
38652
38839
|
config.ssr?.noExternal === true ||
|
|
38653
38840
|
config.ssr?.format !== 'cjs' ||
|
|
38654
38841
|
isBuildOutputEsm(config)) {
|
|
@@ -40118,14 +40305,16 @@ function getWorkerType(raw, clean, i) {
|
|
|
40118
40305
|
return 'classic';
|
|
40119
40306
|
}
|
|
40120
40307
|
// need to find in comment code
|
|
40121
|
-
const workerOptString = raw
|
|
40308
|
+
const workerOptString = raw
|
|
40309
|
+
.substring(commaIndex + 1, endIndex)
|
|
40310
|
+
.replace(/}[^]*,/g, '}'); // strip trailing comma for parsing
|
|
40122
40311
|
const hasViteIgnore = ignoreFlagRE.test(workerOptString);
|
|
40123
40312
|
if (hasViteIgnore) {
|
|
40124
40313
|
return 'ignore';
|
|
40125
40314
|
}
|
|
40126
40315
|
// need to find in no comment code
|
|
40127
|
-
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex);
|
|
40128
|
-
if (!cleanWorkerOptString.
|
|
40316
|
+
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex).trim();
|
|
40317
|
+
if (!cleanWorkerOptString.length) {
|
|
40129
40318
|
return 'classic';
|
|
40130
40319
|
}
|
|
40131
40320
|
let workerOpts = { type: 'classic' };
|
|
@@ -40144,6 +40333,7 @@ function getWorkerType(raw, clean, i) {
|
|
|
40144
40333
|
}
|
|
40145
40334
|
function workerImportMetaUrlPlugin(config) {
|
|
40146
40335
|
const isBuild = config.command === 'build';
|
|
40336
|
+
let workerResolver;
|
|
40147
40337
|
return {
|
|
40148
40338
|
name: 'vite:worker-import-meta-url',
|
|
40149
40339
|
async transform(code, id, options) {
|
|
@@ -40169,20 +40359,33 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
40169
40359
|
}
|
|
40170
40360
|
s || (s = new MagicString(code));
|
|
40171
40361
|
const workerType = getWorkerType(code, cleanString, index + allExp.length);
|
|
40172
|
-
const
|
|
40173
|
-
let
|
|
40362
|
+
const url = rawUrl.slice(1, -1);
|
|
40363
|
+
let file;
|
|
40364
|
+
if (url.startsWith('.')) {
|
|
40365
|
+
file = path$n.resolve(path$n.dirname(id), url);
|
|
40366
|
+
}
|
|
40367
|
+
else {
|
|
40368
|
+
workerResolver ?? (workerResolver = config.createResolver({
|
|
40369
|
+
extensions: [],
|
|
40370
|
+
tryIndex: false,
|
|
40371
|
+
preferRelative: true
|
|
40372
|
+
}));
|
|
40373
|
+
file = await workerResolver(url, id);
|
|
40374
|
+
file ?? (file = url.startsWith('/')
|
|
40375
|
+
? slash$1(path$n.join(config.publicDir, url))
|
|
40376
|
+
: slash$1(path$n.resolve(path$n.dirname(id), url)));
|
|
40377
|
+
}
|
|
40378
|
+
let builtUrl;
|
|
40174
40379
|
if (isBuild) {
|
|
40175
40380
|
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
40176
|
-
|
|
40381
|
+
builtUrl = await workerFileToUrl(config, file, query);
|
|
40177
40382
|
}
|
|
40178
40383
|
else {
|
|
40179
|
-
|
|
40180
|
-
|
|
40181
|
-
|
|
40384
|
+
builtUrl = await fileToUrl(cleanUrl(file), config, this);
|
|
40385
|
+
builtUrl = injectQuery(builtUrl, WORKER_FILE_ID);
|
|
40386
|
+
builtUrl = injectQuery(builtUrl, `type=${workerType}`);
|
|
40182
40387
|
}
|
|
40183
|
-
s.
|
|
40184
|
-
contentOnly: true
|
|
40185
|
-
});
|
|
40388
|
+
s.update(urlIndex, urlIndex + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
|
|
40186
40389
|
}
|
|
40187
40390
|
if (s) {
|
|
40188
40391
|
return transformStableResult(s, id, config);
|
|
@@ -40193,6 +40396,119 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
40193
40396
|
};
|
|
40194
40397
|
}
|
|
40195
40398
|
|
|
40399
|
+
/**
|
|
40400
|
+
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
|
|
40401
|
+
*
|
|
40402
|
+
* Supports template string with dynamic segments:
|
|
40403
|
+
* ```
|
|
40404
|
+
* new URL(`./dir/${name}.png`, import.meta.url)
|
|
40405
|
+
* // transformed to
|
|
40406
|
+
* import.meta.glob('./dir/**.png', { eager: true, import: 'default' })[`./dir/${name}.png`]
|
|
40407
|
+
* ```
|
|
40408
|
+
*/
|
|
40409
|
+
function assetImportMetaUrlPlugin(config) {
|
|
40410
|
+
const normalizedPublicDir = normalizePath$3(config.publicDir);
|
|
40411
|
+
let assetResolver;
|
|
40412
|
+
return {
|
|
40413
|
+
name: 'vite:asset-import-meta-url',
|
|
40414
|
+
async transform(code, id, options) {
|
|
40415
|
+
if (!options?.ssr &&
|
|
40416
|
+
id !== preloadHelperId &&
|
|
40417
|
+
code.includes('new URL') &&
|
|
40418
|
+
code.includes(`import.meta.url`)) {
|
|
40419
|
+
let s;
|
|
40420
|
+
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g;
|
|
40421
|
+
const cleanString = stripLiteral(code);
|
|
40422
|
+
let match;
|
|
40423
|
+
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
|
40424
|
+
const { 0: exp, 1: emptyUrl, index } = match;
|
|
40425
|
+
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
40426
|
+
const urlEnd = urlStart + emptyUrl.length;
|
|
40427
|
+
const rawUrl = code.slice(urlStart, urlEnd);
|
|
40428
|
+
if (!s)
|
|
40429
|
+
s = new MagicString(code);
|
|
40430
|
+
// potential dynamic template string
|
|
40431
|
+
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
|
|
40432
|
+
const ast = this.parse(rawUrl);
|
|
40433
|
+
const templateLiteral = ast.body[0].expression;
|
|
40434
|
+
if (templateLiteral.expressions.length) {
|
|
40435
|
+
const pattern = JSON.stringify(buildGlobPattern(templateLiteral));
|
|
40436
|
+
// Note: native import.meta.url is not supported in the baseline
|
|
40437
|
+
// target so we use the global location here. It can be
|
|
40438
|
+
// window.location or self.location in case it is used in a Web Worker.
|
|
40439
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Window/self
|
|
40440
|
+
s.update(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`);
|
|
40441
|
+
continue;
|
|
40442
|
+
}
|
|
40443
|
+
}
|
|
40444
|
+
const url = rawUrl.slice(1, -1);
|
|
40445
|
+
let file;
|
|
40446
|
+
if (url.startsWith('.')) {
|
|
40447
|
+
file = slash$1(path$n.resolve(path$n.dirname(id), url));
|
|
40448
|
+
}
|
|
40449
|
+
else {
|
|
40450
|
+
assetResolver ?? (assetResolver = config.createResolver({
|
|
40451
|
+
extensions: [],
|
|
40452
|
+
mainFields: [],
|
|
40453
|
+
tryIndex: false,
|
|
40454
|
+
preferRelative: true
|
|
40455
|
+
}));
|
|
40456
|
+
file = await assetResolver(url, id);
|
|
40457
|
+
file ?? (file = url.startsWith('/')
|
|
40458
|
+
? slash$1(path$n.join(config.publicDir, url))
|
|
40459
|
+
: slash$1(path$n.resolve(path$n.dirname(id), url)));
|
|
40460
|
+
}
|
|
40461
|
+
// Get final asset URL. If the file does not exist,
|
|
40462
|
+
// we fall back to the initial URL and let it resolve in runtime
|
|
40463
|
+
let builtUrl;
|
|
40464
|
+
if (file) {
|
|
40465
|
+
try {
|
|
40466
|
+
if (isParentDirectory(normalizedPublicDir, file)) {
|
|
40467
|
+
const publicPath = '/' + path$n.posix.relative(normalizedPublicDir, file);
|
|
40468
|
+
builtUrl = await fileToUrl(publicPath, config, this);
|
|
40469
|
+
}
|
|
40470
|
+
else {
|
|
40471
|
+
builtUrl = await fileToUrl(file, config, this);
|
|
40472
|
+
}
|
|
40473
|
+
}
|
|
40474
|
+
catch {
|
|
40475
|
+
// do nothing, we'll log a warning after this
|
|
40476
|
+
}
|
|
40477
|
+
}
|
|
40478
|
+
if (!builtUrl) {
|
|
40479
|
+
const rawExp = code.slice(index, index + exp.length);
|
|
40480
|
+
config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
|
|
40481
|
+
builtUrl = url;
|
|
40482
|
+
}
|
|
40483
|
+
s.update(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
|
|
40484
|
+
}
|
|
40485
|
+
if (s) {
|
|
40486
|
+
return transformStableResult(s, id, config);
|
|
40487
|
+
}
|
|
40488
|
+
}
|
|
40489
|
+
return null;
|
|
40490
|
+
}
|
|
40491
|
+
};
|
|
40492
|
+
}
|
|
40493
|
+
function buildGlobPattern(ast) {
|
|
40494
|
+
let pattern = '';
|
|
40495
|
+
let lastElementIndex = -1;
|
|
40496
|
+
for (const exp of ast.expressions) {
|
|
40497
|
+
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
40498
|
+
const el = ast.quasis[i];
|
|
40499
|
+
if (el.end < exp.start) {
|
|
40500
|
+
pattern += el.value.raw;
|
|
40501
|
+
lastElementIndex = i;
|
|
40502
|
+
}
|
|
40503
|
+
}
|
|
40504
|
+
pattern += '**';
|
|
40505
|
+
}
|
|
40506
|
+
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
40507
|
+
pattern += ast.quasis[i].value.raw;
|
|
40508
|
+
}
|
|
40509
|
+
return pattern;
|
|
40510
|
+
}
|
|
40511
|
+
|
|
40196
40512
|
/**
|
|
40197
40513
|
* plugin to ensure rollup can watch correctly.
|
|
40198
40514
|
*/
|
|
@@ -40374,6 +40690,12 @@ function parseDynamicImportPattern(strings) {
|
|
|
40374
40690
|
if (rawQuery?.raw !== undefined) {
|
|
40375
40691
|
globParams = { as: 'raw' };
|
|
40376
40692
|
}
|
|
40693
|
+
if (rawQuery?.url !== undefined) {
|
|
40694
|
+
globParams = { as: 'url' };
|
|
40695
|
+
}
|
|
40696
|
+
if (rawQuery?.worker !== undefined) {
|
|
40697
|
+
globParams = { as: 'worker' };
|
|
40698
|
+
}
|
|
40377
40699
|
return {
|
|
40378
40700
|
globParams,
|
|
40379
40701
|
userPattern,
|
|
@@ -40493,13 +40815,15 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
40493
40815
|
const buildPlugins = isBuild
|
|
40494
40816
|
? (await Promise.resolve().then(function () { return build$1; })).resolveBuildPlugins(config)
|
|
40495
40817
|
: { pre: [], post: [] };
|
|
40818
|
+
const { modulePreload } = config.build;
|
|
40496
40819
|
return [
|
|
40497
40820
|
isWatch ? ensureWatchPlugin() : null,
|
|
40498
40821
|
isBuild ? metadataPlugin() : null,
|
|
40499
40822
|
preAliasPlugin(config),
|
|
40500
40823
|
alias$1({ entries: config.resolve.alias }),
|
|
40501
40824
|
...prePlugins,
|
|
40502
|
-
|
|
40825
|
+
modulePreload === true ||
|
|
40826
|
+
(typeof modulePreload === 'object' && modulePreload.polyfill)
|
|
40503
40827
|
? modulePreloadPolyfillPlugin(config)
|
|
40504
40828
|
: null,
|
|
40505
40829
|
...(isDepsOptimizerEnabled(config, false) ||
|
|
@@ -40540,6 +40864,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
40540
40864
|
isBuild && config.build.ssr ? ssrRequireHookPlugin(config) : null,
|
|
40541
40865
|
isBuild && buildHtmlPlugin(config),
|
|
40542
40866
|
workerImportMetaUrlPlugin(config),
|
|
40867
|
+
assetImportMetaUrlPlugin(config),
|
|
40543
40868
|
...buildPlugins.pre,
|
|
40544
40869
|
dynamicImportVarsPlugin(config),
|
|
40545
40870
|
importGlobPlugin(config),
|
|
@@ -41470,7 +41795,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
41470
41795
|
// may end with these extensions
|
|
41471
41796
|
// css & json & wasm
|
|
41472
41797
|
build.onResolve({
|
|
41473
|
-
filter: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|json|wasm)$/
|
|
41798
|
+
filter: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss|json|wasm)$/
|
|
41474
41799
|
}, externalUnlessEntry);
|
|
41475
41800
|
// known asset types
|
|
41476
41801
|
build.onResolve({
|
|
@@ -41615,6 +41940,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
41615
41940
|
const sessionTimestamp = Date.now().toString();
|
|
41616
41941
|
const cachedMetadata = loadCachedDepOptimizationMetadata(config, ssr);
|
|
41617
41942
|
let handle;
|
|
41943
|
+
let closed = false;
|
|
41618
41944
|
let metadata = cachedMetadata || initDepsOptimizerMetadata(config, ssr, sessionTimestamp);
|
|
41619
41945
|
const depsOptimizer = {
|
|
41620
41946
|
metadata,
|
|
@@ -41627,6 +41953,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
41627
41953
|
delayDepsOptimizerUntil,
|
|
41628
41954
|
resetRegisteredIds,
|
|
41629
41955
|
ensureFirstRun,
|
|
41956
|
+
close,
|
|
41630
41957
|
options: getDepOptimizationConfig(config, ssr)
|
|
41631
41958
|
};
|
|
41632
41959
|
depsOptimizerMap.set(config, depsOptimizer);
|
|
@@ -41655,6 +41982,12 @@ async function createDepsOptimizer(config, server) {
|
|
|
41655
41982
|
// If there wasn't a cache or it is outdated, we need to prepare a first run
|
|
41656
41983
|
let firstRunCalled = !!cachedMetadata;
|
|
41657
41984
|
let postScanOptimizationResult;
|
|
41985
|
+
let optimizingNewDeps;
|
|
41986
|
+
async function close() {
|
|
41987
|
+
closed = true;
|
|
41988
|
+
await postScanOptimizationResult;
|
|
41989
|
+
await optimizingNewDeps;
|
|
41990
|
+
}
|
|
41658
41991
|
if (!cachedMetadata) {
|
|
41659
41992
|
// Enter processing state until crawl of static imports ends
|
|
41660
41993
|
currentlyProcessing = true;
|
|
@@ -41752,13 +42085,20 @@ async function createDepsOptimizer(config, server) {
|
|
|
41752
42085
|
// Ensure that a rerun will not be issued for current discovered deps
|
|
41753
42086
|
if (handle)
|
|
41754
42087
|
clearTimeout(handle);
|
|
41755
|
-
if (Object.keys(metadata.discovered).length === 0) {
|
|
42088
|
+
if (closed || Object.keys(metadata.discovered).length === 0) {
|
|
41756
42089
|
currentlyProcessing = false;
|
|
41757
42090
|
return;
|
|
41758
42091
|
}
|
|
41759
42092
|
currentlyProcessing = true;
|
|
41760
42093
|
try {
|
|
41761
|
-
const processingResult = preRunResult ?? (await optimizeNewDeps());
|
|
42094
|
+
const processingResult = preRunResult ?? (await (optimizingNewDeps = optimizeNewDeps()));
|
|
42095
|
+
optimizingNewDeps = undefined;
|
|
42096
|
+
if (closed) {
|
|
42097
|
+
currentlyProcessing = false;
|
|
42098
|
+
processingResult.cancel();
|
|
42099
|
+
resolveEnqueuedProcessingPromises();
|
|
42100
|
+
return;
|
|
42101
|
+
}
|
|
41762
42102
|
const newData = processingResult.metadata;
|
|
41763
42103
|
const needsInteropMismatch = findInteropMismatches(metadata.discovered, newData.optimized);
|
|
41764
42104
|
// After a re-optimization, if the internal bundled chunks change a full page reload
|
|
@@ -42027,7 +42367,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
42027
42367
|
function ensureFirstRun() {
|
|
42028
42368
|
if (!firstRunEnsured && !firstRunCalled && registeredIds.length === 0) {
|
|
42029
42369
|
setTimeout(() => {
|
|
42030
|
-
if (registeredIds.length === 0) {
|
|
42370
|
+
if (!closed && registeredIds.length === 0) {
|
|
42031
42371
|
onCrawlEnd();
|
|
42032
42372
|
}
|
|
42033
42373
|
}, runOptimizerIfIdleAfterMs);
|
|
@@ -42058,7 +42398,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
42058
42398
|
waitingOn = next.id;
|
|
42059
42399
|
const afterLoad = () => {
|
|
42060
42400
|
waitingOn = undefined;
|
|
42061
|
-
if (!workersSources.has(next.id)) {
|
|
42401
|
+
if (!closed && !workersSources.has(next.id)) {
|
|
42062
42402
|
if (registeredIds.length > 0) {
|
|
42063
42403
|
runOptimizerWhenIdle();
|
|
42064
42404
|
}
|
|
@@ -42094,6 +42434,7 @@ async function createDevSsrDepsOptimizer(config) {
|
|
|
42094
42434
|
delayDepsOptimizerUntil: (id, done) => { },
|
|
42095
42435
|
resetRegisteredIds: () => { },
|
|
42096
42436
|
ensureFirstRun: () => { },
|
|
42437
|
+
close: async () => { },
|
|
42097
42438
|
options: config.ssr.optimizeDeps
|
|
42098
42439
|
};
|
|
42099
42440
|
devSsrDepsOptimizerMap.set(config, depsOptimizer);
|
|
@@ -42703,7 +43044,12 @@ function needsInterop(config, ssr, id, exportsData, output) {
|
|
|
42703
43044
|
function isSingleDefaultExport(exports) {
|
|
42704
43045
|
return exports.length === 1 && exports[0] === 'default';
|
|
42705
43046
|
}
|
|
42706
|
-
const lockfileFormats = [
|
|
43047
|
+
const lockfileFormats = [
|
|
43048
|
+
'package-lock.json',
|
|
43049
|
+
'yarn.lock',
|
|
43050
|
+
'pnpm-lock.yaml',
|
|
43051
|
+
'bun.lockb'
|
|
43052
|
+
];
|
|
42707
43053
|
function getDepHash(config, ssr) {
|
|
42708
43054
|
let content = lookupFile(config.root, lockfileFormats) || '';
|
|
42709
43055
|
// also take config into account
|
|
@@ -42803,6 +43149,10 @@ const dynamicImportPrefixRE = /import\s*\(/;
|
|
|
42803
43149
|
// TODO: abstract
|
|
42804
43150
|
const optimizedDepChunkRE = /\/chunk-[A-Z0-9]{8}\.js/;
|
|
42805
43151
|
const optimizedDepDynamicRE = /-[A-Z0-9]{8}\.js/;
|
|
43152
|
+
function toRelativePath(filename, importer) {
|
|
43153
|
+
const relPath = path$n.relative(path$n.dirname(importer), filename);
|
|
43154
|
+
return relPath.startsWith('.') ? relPath : `./${relPath}`;
|
|
43155
|
+
}
|
|
42806
43156
|
/**
|
|
42807
43157
|
* Helper for preloading CSS and direct imports of async chunks in parallel to
|
|
42808
43158
|
* the async chunk itself.
|
|
@@ -42820,6 +43170,7 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42820
43170
|
if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {
|
|
42821
43171
|
return baseModule();
|
|
42822
43172
|
}
|
|
43173
|
+
const links = document.getElementsByTagName('link');
|
|
42823
43174
|
return Promise.all(deps.map((dep) => {
|
|
42824
43175
|
// @ts-ignore
|
|
42825
43176
|
dep = assetsURL(dep, importerUrl);
|
|
@@ -42830,8 +43181,21 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42830
43181
|
seen[dep] = true;
|
|
42831
43182
|
const isCss = dep.endsWith('.css');
|
|
42832
43183
|
const cssSelector = isCss ? '[rel="stylesheet"]' : '';
|
|
42833
|
-
|
|
42834
|
-
if
|
|
43184
|
+
const isBaseRelative = !!importerUrl;
|
|
43185
|
+
// check if the file is already preloaded by SSR markup
|
|
43186
|
+
if (isBaseRelative) {
|
|
43187
|
+
// When isBaseRelative is true then we have `importerUrl` and `dep` is
|
|
43188
|
+
// already converted to an absolute URL by the `assetsURL` function
|
|
43189
|
+
for (let i = links.length - 1; i >= 0; i--) {
|
|
43190
|
+
const link = links[i];
|
|
43191
|
+
// The `links[i].href` is an absolute URL thanks to browser doing the work
|
|
43192
|
+
// for us. See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-domstring-5
|
|
43193
|
+
if (link.href === dep && (!isCss || link.rel === 'stylesheet')) {
|
|
43194
|
+
return;
|
|
43195
|
+
}
|
|
43196
|
+
}
|
|
43197
|
+
}
|
|
43198
|
+
else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
|
|
42835
43199
|
return;
|
|
42836
43200
|
}
|
|
42837
43201
|
// @ts-ignore
|
|
@@ -42859,14 +43223,39 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42859
43223
|
function buildImportAnalysisPlugin(config) {
|
|
42860
43224
|
const ssr = !!config.build.ssr;
|
|
42861
43225
|
const isWorker = config.isWorker;
|
|
42862
|
-
const insertPreload = !(ssr ||
|
|
42863
|
-
|
|
42864
|
-
|
|
43226
|
+
const insertPreload = !(ssr ||
|
|
43227
|
+
!!config.build.lib ||
|
|
43228
|
+
isWorker ||
|
|
43229
|
+
config.build.modulePreload === false);
|
|
43230
|
+
const resolveModulePreloadDependencies = config.build.modulePreload && config.build.modulePreload.resolveDependencies;
|
|
43231
|
+
const renderBuiltUrl = config.experimental.renderBuiltUrl;
|
|
43232
|
+
const customModulePreloadPaths = !!(resolveModulePreloadDependencies || renderBuiltUrl);
|
|
43233
|
+
const isRelativeBase = config.base === './' || config.base === '';
|
|
43234
|
+
const optimizeModulePreloadRelativePaths = isRelativeBase && !customModulePreloadPaths;
|
|
43235
|
+
const { modulePreload } = config.build;
|
|
43236
|
+
const scriptRel = modulePreload && modulePreload.polyfill
|
|
42865
43237
|
? `'modulepreload'`
|
|
42866
43238
|
: `(${detectScriptRel.toString()})()`;
|
|
42867
|
-
|
|
42868
|
-
|
|
42869
|
-
|
|
43239
|
+
// There are three different cases for the preload list format in __vitePreload
|
|
43240
|
+
//
|
|
43241
|
+
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
|
|
43242
|
+
//
|
|
43243
|
+
// This is maintained to keep backwards compatibility as some users developed plugins
|
|
43244
|
+
// using regex over this list to workaround the fact that module preload wasn't
|
|
43245
|
+
// configurable.
|
|
43246
|
+
const assetsURL = customModulePreloadPaths
|
|
43247
|
+
? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used
|
|
43248
|
+
// the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
|
|
43249
|
+
// a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
|
|
43250
|
+
`function(dep, importerUrl) { return dep.startsWith('.') ? new URL(dep, importerUrl).href : dep }`
|
|
43251
|
+
: optimizeModulePreloadRelativePaths
|
|
43252
|
+
? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
|
|
43253
|
+
// to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
|
|
43254
|
+
// The importerUrl is passed as third parameter to __vitePreload in this case
|
|
43255
|
+
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
|
|
43256
|
+
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
|
|
43257
|
+
// is appendended inside __vitePreload too.
|
|
43258
|
+
`function(dep) { return ${JSON.stringify(config.base)}+dep }`;
|
|
42870
43259
|
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
|
|
42871
43260
|
return {
|
|
42872
43261
|
name: 'vite:build-import-analysis',
|
|
@@ -42952,7 +43341,9 @@ function buildImportAnalysisPlugin(config) {
|
|
|
42952
43341
|
if (isDynamicImport && insertPreload) {
|
|
42953
43342
|
needPreloadHelper = true;
|
|
42954
43343
|
str().prependLeft(expStart, `${preloadMethod}(() => `);
|
|
42955
|
-
str().appendRight(expEnd, `,${isModernFlag}?"${preloadMarker}":void 0${
|
|
43344
|
+
str().appendRight(expEnd, `,${isModernFlag}?"${preloadMarker}":void 0${optimizeModulePreloadRelativePaths || customModulePreloadPaths
|
|
43345
|
+
? ',import.meta.url'
|
|
43346
|
+
: ''})`);
|
|
42956
43347
|
}
|
|
42957
43348
|
// static import or valid string in dynamic import
|
|
42958
43349
|
// If resolvable, let's resolve it
|
|
@@ -42986,9 +43377,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
42986
43377
|
let rewrittenUrl = JSON.stringify(file);
|
|
42987
43378
|
if (!isDynamicImport)
|
|
42988
43379
|
rewrittenUrl = rewrittenUrl.slice(1, -1);
|
|
42989
|
-
str().
|
|
42990
|
-
contentOnly: true
|
|
42991
|
-
});
|
|
43380
|
+
str().update(start, end, rewrittenUrl);
|
|
42992
43381
|
}
|
|
42993
43382
|
}
|
|
42994
43383
|
}
|
|
@@ -43007,9 +43396,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43007
43396
|
// edge case for package names ending with .css (e.g normalize.css)
|
|
43008
43397
|
!(bareImportRE.test(specifier) && !specifier.includes('/'))) {
|
|
43009
43398
|
const url = specifier.replace(/\?|$/, (m) => `?used${m ? '&' : ''}`);
|
|
43010
|
-
str().
|
|
43011
|
-
contentOnly: true
|
|
43012
|
-
});
|
|
43399
|
+
str().update(start, end, isDynamicImport ? `'${url}'` : url);
|
|
43013
43400
|
}
|
|
43014
43401
|
}
|
|
43015
43402
|
if (needPreloadHelper &&
|
|
@@ -43033,7 +43420,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43033
43420
|
const s = new MagicString(code);
|
|
43034
43421
|
let match;
|
|
43035
43422
|
while ((match = re.exec(code))) {
|
|
43036
|
-
s.
|
|
43423
|
+
s.update(match.index, match.index + isModernFlag.length, isModern);
|
|
43037
43424
|
}
|
|
43038
43425
|
return {
|
|
43039
43426
|
code: s.toString(),
|
|
@@ -43047,7 +43434,10 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43047
43434
|
return null;
|
|
43048
43435
|
},
|
|
43049
43436
|
generateBundle({ format }, bundle) {
|
|
43050
|
-
if (format !== 'es' ||
|
|
43437
|
+
if (format !== 'es' ||
|
|
43438
|
+
ssr ||
|
|
43439
|
+
isWorker ||
|
|
43440
|
+
config.build.modulePreload === false) {
|
|
43051
43441
|
return;
|
|
43052
43442
|
}
|
|
43053
43443
|
for (const file in bundle) {
|
|
@@ -43056,7 +43446,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43056
43446
|
// dynamic import to constant json may get inlined.
|
|
43057
43447
|
if (chunk.type === 'chunk' && chunk.code.indexOf(preloadMarker) > -1) {
|
|
43058
43448
|
const code = chunk.code;
|
|
43059
|
-
let imports
|
|
43449
|
+
let imports;
|
|
43060
43450
|
try {
|
|
43061
43451
|
imports = parse$b(code)[0].filter((i) => i.d > -1);
|
|
43062
43452
|
}
|
|
@@ -43078,7 +43468,9 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43078
43468
|
}
|
|
43079
43469
|
const deps = new Set();
|
|
43080
43470
|
let hasRemovedPureCssChunk = false;
|
|
43471
|
+
let normalizedFile = undefined;
|
|
43081
43472
|
if (url) {
|
|
43473
|
+
normalizedFile = path$n.posix.join(path$n.posix.dirname(chunk.fileName), url);
|
|
43082
43474
|
const ownerFilename = chunk.fileName;
|
|
43083
43475
|
// literal import - trace direct imports and add to deps
|
|
43084
43476
|
const analyzed = new Set();
|
|
@@ -43091,10 +43483,12 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43091
43483
|
const chunk = bundle[filename];
|
|
43092
43484
|
if (chunk) {
|
|
43093
43485
|
deps.add(chunk.fileName);
|
|
43486
|
+
chunk.imports.forEach(addDeps);
|
|
43487
|
+
// Ensure that the css imported by current chunk is loaded after the dependencies.
|
|
43488
|
+
// So the style of current chunk won't be overwritten unexpectedly.
|
|
43094
43489
|
chunk.viteMetadata.importedCss.forEach((file) => {
|
|
43095
43490
|
deps.add(file);
|
|
43096
43491
|
});
|
|
43097
|
-
chunk.imports.forEach(addDeps);
|
|
43098
43492
|
}
|
|
43099
43493
|
else {
|
|
43100
43494
|
const removedPureCssFiles = removedPureCssFilesCache.get(config);
|
|
@@ -43106,13 +43500,10 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43106
43500
|
});
|
|
43107
43501
|
hasRemovedPureCssChunk = true;
|
|
43108
43502
|
}
|
|
43109
|
-
s.
|
|
43110
|
-
contentOnly: true
|
|
43111
|
-
});
|
|
43503
|
+
s.update(expStart, expEnd, 'Promise.resolve({})');
|
|
43112
43504
|
}
|
|
43113
43505
|
}
|
|
43114
43506
|
};
|
|
43115
|
-
const normalizedFile = path$n.posix.join(path$n.posix.dirname(chunk.fileName), url);
|
|
43116
43507
|
addDeps(normalizedFile);
|
|
43117
43508
|
}
|
|
43118
43509
|
let markerStartPos = code.indexOf(preloadMarkerWithQuote, end);
|
|
@@ -43121,19 +43512,53 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43121
43512
|
markerStartPos = code.indexOf(preloadMarkerWithQuote);
|
|
43122
43513
|
}
|
|
43123
43514
|
if (markerStartPos > 0) {
|
|
43124
|
-
|
|
43125
|
-
|
|
43126
|
-
// actual other deps. Don't include the assets dir if the default asset file names
|
|
43127
|
-
// are used, the path will be reconstructed by the import preload helper
|
|
43128
|
-
deps.size > 1 ||
|
|
43515
|
+
// the dep list includes the main chunk, so only need to reload when there are actual other deps.
|
|
43516
|
+
const depsArray = deps.size > 1 ||
|
|
43129
43517
|
// main chunk is removed
|
|
43130
43518
|
(hasRemovedPureCssChunk && deps.size > 0)
|
|
43131
|
-
?
|
|
43132
|
-
|
|
43133
|
-
|
|
43134
|
-
|
|
43135
|
-
|
|
43136
|
-
|
|
43519
|
+
? [...deps]
|
|
43520
|
+
: [];
|
|
43521
|
+
let renderedDeps;
|
|
43522
|
+
if (normalizedFile && customModulePreloadPaths) {
|
|
43523
|
+
const { modulePreload } = config.build;
|
|
43524
|
+
const resolveDependencies = modulePreload && modulePreload.resolveDependencies;
|
|
43525
|
+
let resolvedDeps;
|
|
43526
|
+
if (resolveDependencies) {
|
|
43527
|
+
// We can't let the user remove css deps as these aren't really preloads, they are just using
|
|
43528
|
+
// the same mechanism as module preloads for this chunk
|
|
43529
|
+
const cssDeps = [];
|
|
43530
|
+
const otherDeps = [];
|
|
43531
|
+
for (const dep of depsArray) {
|
|
43532
|
+
(dep.endsWith('.css') ? cssDeps : otherDeps).push(dep);
|
|
43533
|
+
}
|
|
43534
|
+
resolvedDeps = [
|
|
43535
|
+
...resolveDependencies(normalizedFile, otherDeps, {
|
|
43536
|
+
hostId: file,
|
|
43537
|
+
hostType: 'js'
|
|
43538
|
+
}),
|
|
43539
|
+
...cssDeps
|
|
43540
|
+
];
|
|
43541
|
+
}
|
|
43542
|
+
else {
|
|
43543
|
+
resolvedDeps = depsArray;
|
|
43544
|
+
}
|
|
43545
|
+
renderedDeps = resolvedDeps.map((dep) => {
|
|
43546
|
+
const replacement = toOutputFilePathInJS(dep, 'asset', chunk.fileName, 'js', config, toRelativePath);
|
|
43547
|
+
const replacementString = typeof replacement === 'string'
|
|
43548
|
+
? JSON.stringify(replacement)
|
|
43549
|
+
: replacement.runtime;
|
|
43550
|
+
return replacementString;
|
|
43551
|
+
});
|
|
43552
|
+
}
|
|
43553
|
+
else {
|
|
43554
|
+
renderedDeps = depsArray.map((d) =>
|
|
43555
|
+
// Don't include the assets dir if the default asset file names
|
|
43556
|
+
// are used, the path will be reconstructed by the import preload helper
|
|
43557
|
+
JSON.stringify(optimizeModulePreloadRelativePaths
|
|
43558
|
+
? toRelativePath(d, file)
|
|
43559
|
+
: d));
|
|
43560
|
+
}
|
|
43561
|
+
s.update(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, `[${renderedDeps.join(',')}]`);
|
|
43137
43562
|
rewroteMarkerStartPos.add(markerStartPos);
|
|
43138
43563
|
}
|
|
43139
43564
|
}
|
|
@@ -43143,7 +43568,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43143
43568
|
let markerStartPos = code.indexOf(preloadMarkerWithQuote);
|
|
43144
43569
|
while (markerStartPos >= 0) {
|
|
43145
43570
|
if (!rewroteMarkerStartPos.has(markerStartPos)) {
|
|
43146
|
-
s.
|
|
43571
|
+
s.update(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, 'void 0');
|
|
43147
43572
|
}
|
|
43148
43573
|
markerStartPos = code.indexOf(preloadMarkerWithQuote, markerStartPos + preloadMarkerWithQuote.length);
|
|
43149
43574
|
}
|
|
@@ -43328,6 +43753,8 @@ function getScriptInfo(node) {
|
|
|
43328
43753
|
let isModule = false;
|
|
43329
43754
|
let isAsync = false;
|
|
43330
43755
|
for (const p of node.attrs) {
|
|
43756
|
+
if (p.prefix !== undefined)
|
|
43757
|
+
continue;
|
|
43331
43758
|
if (p.name === 'src') {
|
|
43332
43759
|
if (!src) {
|
|
43333
43760
|
src = p;
|
|
@@ -43353,7 +43780,7 @@ function overwriteAttrValue(s, sourceCodeLocation, newValue) {
|
|
|
43353
43780
|
}
|
|
43354
43781
|
const wrapOffset = valueStart[1] === '"' || valueStart[1] === "'" ? 1 : 0;
|
|
43355
43782
|
const valueOffset = valueStart.index + valueStart[0].length - 1;
|
|
43356
|
-
s.
|
|
43783
|
+
s.update(sourceCodeLocation.startOffset + valueOffset + wrapOffset, sourceCodeLocation.endOffset - wrapOffset, newValue);
|
|
43357
43784
|
return s;
|
|
43358
43785
|
}
|
|
43359
43786
|
/**
|
|
@@ -43494,15 +43921,17 @@ function buildHtmlPlugin(config) {
|
|
|
43494
43921
|
const assetAttrs = assetAttrsConfig[node.nodeName];
|
|
43495
43922
|
if (assetAttrs) {
|
|
43496
43923
|
for (const p of node.attrs) {
|
|
43497
|
-
|
|
43498
|
-
|
|
43924
|
+
const attrKey = getAttrKey(p);
|
|
43925
|
+
if (p.value && assetAttrs.includes(attrKey)) {
|
|
43926
|
+
const attrSourceCodeLocation = node.sourceCodeLocation.attrs[attrKey];
|
|
43499
43927
|
// assetsUrl may be encodeURI
|
|
43500
43928
|
const url = decodeURI(p.value);
|
|
43501
43929
|
if (!isExcludedUrl(url)) {
|
|
43502
43930
|
if (node.nodeName === 'link' &&
|
|
43503
43931
|
isCSSRequest(url) &&
|
|
43504
43932
|
// should not be converted if following attributes are present (#6748)
|
|
43505
|
-
!node.attrs.some((p) => p.
|
|
43933
|
+
!node.attrs.some((p) => p.prefix === undefined &&
|
|
43934
|
+
(p.name === 'media' || p.name === 'disabled'))) {
|
|
43506
43935
|
// CSS references, convert to import
|
|
43507
43936
|
const importExpression = `\nimport ${JSON.stringify(url)}`;
|
|
43508
43937
|
styleUrls.push({
|
|
@@ -43527,7 +43956,9 @@ function buildHtmlPlugin(config) {
|
|
|
43527
43956
|
}
|
|
43528
43957
|
// <tag style="... url(...) ..."></tag>
|
|
43529
43958
|
// extract inline styles as virtual css and add class attribute to tag for selecting
|
|
43530
|
-
const inlineStyle = node.attrs.find((prop) => prop.
|
|
43959
|
+
const inlineStyle = node.attrs.find((prop) => prop.prefix === undefined &&
|
|
43960
|
+
prop.name === 'style' &&
|
|
43961
|
+
prop.value.includes('url(') // only url(...) in css need to emit file
|
|
43531
43962
|
);
|
|
43532
43963
|
if (inlineStyle) {
|
|
43533
43964
|
inlineModuleIndex++;
|
|
@@ -43554,7 +43985,7 @@ function buildHtmlPlugin(config) {
|
|
|
43554
43985
|
js += `\nimport "${id}?html-proxy&inline-css&index=${inlineModuleIndex}.css"`;
|
|
43555
43986
|
const hash = getHash(cleanUrl(id));
|
|
43556
43987
|
// will transform in `applyHtmlTransforms`
|
|
43557
|
-
s.
|
|
43988
|
+
s.update(styleNode.sourceCodeLocation.startOffset, styleNode.sourceCodeLocation.endOffset, `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`);
|
|
43558
43989
|
}
|
|
43559
43990
|
if (shouldRemove) {
|
|
43560
43991
|
// remove the script tag from the html. we are going to inject new
|
|
@@ -43578,7 +44009,7 @@ function buildHtmlPlugin(config) {
|
|
|
43578
44009
|
!namedOutput.includes(content.replace(/^\//, '')) // Allow for absolute references as named output can't be an absolute path
|
|
43579
44010
|
) {
|
|
43580
44011
|
try {
|
|
43581
|
-
const url = attr.name === 'srcset'
|
|
44012
|
+
const url = attr.prefix === undefined && attr.name === 'srcset'
|
|
43582
44013
|
? await processSrcSet(content, ({ url }) => urlToBuiltUrl(url, id, config, this))
|
|
43583
44014
|
: await urlToBuiltUrl(content, id, config, this);
|
|
43584
44015
|
overwriteAttrValue(s, sourceCodeLocation, url);
|
|
@@ -43593,12 +44024,10 @@ function buildHtmlPlugin(config) {
|
|
|
43593
44024
|
// emit <script>import("./aaa")</script> asset
|
|
43594
44025
|
for (const { start, end, url } of scriptUrls) {
|
|
43595
44026
|
if (!isExcludedUrl(url)) {
|
|
43596
|
-
s.
|
|
44027
|
+
s.update(start, end, await urlToBuiltUrl(url, id, config, this));
|
|
43597
44028
|
}
|
|
43598
44029
|
else if (checkPublicFile(url, config)) {
|
|
43599
|
-
s.
|
|
43600
|
-
contentOnly: true
|
|
43601
|
-
});
|
|
44030
|
+
s.update(start, end, toOutputPublicFilePath(url));
|
|
43602
44031
|
}
|
|
43603
44032
|
}
|
|
43604
44033
|
// ignore <link rel="stylesheet"> if its url can't be resolved
|
|
@@ -43618,7 +44047,9 @@ function buildHtmlPlugin(config) {
|
|
|
43618
44047
|
}
|
|
43619
44048
|
processedHtml.set(id, s.toString());
|
|
43620
44049
|
// inject module preload polyfill only when configured and needed
|
|
43621
|
-
|
|
44050
|
+
const { modulePreload } = config.build;
|
|
44051
|
+
if ((modulePreload === true ||
|
|
44052
|
+
(typeof modulePreload === 'object' && modulePreload.polyfill)) &&
|
|
43622
44053
|
(someScriptsAreAsync || someScriptsAreDefer)) {
|
|
43623
44054
|
js = `import "${modulePreloadPolyfillId}";\n${js}`;
|
|
43624
44055
|
}
|
|
@@ -43649,12 +44080,12 @@ function buildHtmlPlugin(config) {
|
|
|
43649
44080
|
src: toOutputPath(chunk.fileName)
|
|
43650
44081
|
}
|
|
43651
44082
|
});
|
|
43652
|
-
const toPreloadTag = (
|
|
44083
|
+
const toPreloadTag = (filename, toOutputPath) => ({
|
|
43653
44084
|
tag: 'link',
|
|
43654
44085
|
attrs: {
|
|
43655
44086
|
rel: 'modulepreload',
|
|
43656
44087
|
crossorigin: true,
|
|
43657
|
-
href: toOutputPath(
|
|
44088
|
+
href: toOutputPath(filename)
|
|
43658
44089
|
}
|
|
43659
44090
|
});
|
|
43660
44091
|
const getCssTagsForChunk = (chunk, toOutputPath, seen = new Set()) => {
|
|
@@ -43713,12 +44144,26 @@ function buildHtmlPlugin(config) {
|
|
|
43713
44144
|
// when not inlined, inject <script> for entry and modulepreload its dependencies
|
|
43714
44145
|
// when inlined, discard entry chunk and inject <script> for everything in post-order
|
|
43715
44146
|
const imports = getImportedChunks(chunk);
|
|
43716
|
-
|
|
43717
|
-
|
|
43718
|
-
|
|
44147
|
+
let assetTags;
|
|
44148
|
+
if (canInlineEntry) {
|
|
44149
|
+
assetTags = imports.map((chunk) => toScriptTag(chunk, toOutputAssetFilePath, isAsync));
|
|
44150
|
+
}
|
|
44151
|
+
else {
|
|
44152
|
+
const { modulePreload } = config.build;
|
|
44153
|
+
const resolveDependencies = typeof modulePreload === 'object' &&
|
|
44154
|
+
modulePreload.resolveDependencies;
|
|
44155
|
+
const importsFileNames = imports.map((chunk) => chunk.fileName);
|
|
44156
|
+
const resolvedDeps = resolveDependencies
|
|
44157
|
+
? resolveDependencies(chunk.fileName, importsFileNames, {
|
|
44158
|
+
hostId: relativeUrlPath,
|
|
44159
|
+
hostType: 'html'
|
|
44160
|
+
})
|
|
44161
|
+
: importsFileNames;
|
|
44162
|
+
assetTags = [
|
|
43719
44163
|
toScriptTag(chunk, toOutputAssetFilePath, isAsync),
|
|
43720
|
-
...
|
|
44164
|
+
...resolvedDeps.map((i) => toPreloadTag(i, toOutputAssetFilePath))
|
|
43721
44165
|
];
|
|
44166
|
+
}
|
|
43722
44167
|
assetTags.push(...getCssTagsForChunk(chunk, toOutputAssetFilePath));
|
|
43723
44168
|
result = injectToHead(result, assetTags);
|
|
43724
44169
|
}
|
|
@@ -43744,7 +44189,7 @@ function buildHtmlPlugin(config) {
|
|
|
43744
44189
|
s || (s = new MagicString(result));
|
|
43745
44190
|
const { 0: full, 1: scopedName } = match;
|
|
43746
44191
|
const cssTransformedCode = htmlProxyResult.get(scopedName);
|
|
43747
|
-
s.
|
|
44192
|
+
s.update(match.index, match.index + full.length, cssTransformedCode);
|
|
43748
44193
|
}
|
|
43749
44194
|
if (s) {
|
|
43750
44195
|
result = s.toString();
|
|
@@ -43984,8 +44429,11 @@ function serializeAttrs(attrs) {
|
|
|
43984
44429
|
function incrementIndent(indent = '') {
|
|
43985
44430
|
return `${indent}${indent[0] === '\t' ? '\t' : ' '}`;
|
|
43986
44431
|
}
|
|
44432
|
+
function getAttrKey(attr) {
|
|
44433
|
+
return attr.prefix === undefined ? attr.name : `${attr.prefix}:${attr.name}`;
|
|
44434
|
+
}
|
|
43987
44435
|
|
|
43988
|
-
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
|
|
44436
|
+
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`;
|
|
43989
44437
|
const cssLangRE = new RegExp(cssLangs);
|
|
43990
44438
|
const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
|
|
43991
44439
|
const directRequestRE = /(\?|&)direct\b/;
|
|
@@ -44002,7 +44450,7 @@ const isDirectRequest = (request) => directRequestRE.test(request);
|
|
|
44002
44450
|
const cssModulesCache = new WeakMap();
|
|
44003
44451
|
const removedPureCssFilesCache = new WeakMap();
|
|
44004
44452
|
const cssEntryFilesCache = new WeakMap();
|
|
44005
|
-
const postcssConfigCache =
|
|
44453
|
+
const postcssConfigCache = {};
|
|
44006
44454
|
function encodePublicUrlsInCSS(config) {
|
|
44007
44455
|
return config.command === 'build';
|
|
44008
44456
|
}
|
|
@@ -44440,8 +44888,8 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44440
44888
|
// crawl them in order to register watch dependencies.
|
|
44441
44889
|
const needInlineImport = code.includes('@import');
|
|
44442
44890
|
const hasUrl = cssUrlRE.test(code) || cssImageSetRE.test(code);
|
|
44443
|
-
const postcssConfig = await resolvePostcssConfig(config);
|
|
44444
44891
|
const lang = id.match(cssLangRE)?.[1];
|
|
44892
|
+
const postcssConfig = await resolvePostcssConfig(config, getCssDialect(lang));
|
|
44445
44893
|
// 1. plain css that needs no processing
|
|
44446
44894
|
if (lang === 'css' &&
|
|
44447
44895
|
!postcssConfig &&
|
|
@@ -44496,9 +44944,13 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44496
44944
|
}
|
|
44497
44945
|
// 3. postcss
|
|
44498
44946
|
const postcssOptions = (postcssConfig && postcssConfig.options) || {};
|
|
44947
|
+
// for sugarss change parser
|
|
44948
|
+
if (lang === 'sss') {
|
|
44949
|
+
postcssOptions.parser = loadPreprocessor("sugarss" /* sss */, config.root);
|
|
44950
|
+
}
|
|
44499
44951
|
const postcssPlugins = postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [];
|
|
44500
44952
|
if (needInlineImport) {
|
|
44501
|
-
postcssPlugins.unshift((await import('./dep-
|
|
44953
|
+
postcssPlugins.unshift((await import('./dep-39e6741e.js').then(function (n) { return n.i; })).default({
|
|
44502
44954
|
async resolve(id, basedir) {
|
|
44503
44955
|
const publicFile = checkPublicFile(id, config);
|
|
44504
44956
|
if (publicFile) {
|
|
@@ -44520,7 +44972,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44520
44972
|
logger: config.logger
|
|
44521
44973
|
}));
|
|
44522
44974
|
if (isModule) {
|
|
44523
|
-
postcssPlugins.unshift((await import('./dep-
|
|
44975
|
+
postcssPlugins.unshift((await import('./dep-46ac452b.js').then(function (n) { return n.i; })).default({
|
|
44524
44976
|
...modulesOptions,
|
|
44525
44977
|
getJSON(cssFileName, _modules, outputFileName) {
|
|
44526
44978
|
modules = _modules;
|
|
@@ -44668,8 +45120,9 @@ async function finalizeCss(css, minify, config) {
|
|
|
44668
45120
|
}
|
|
44669
45121
|
return css;
|
|
44670
45122
|
}
|
|
44671
|
-
async function resolvePostcssConfig(config) {
|
|
44672
|
-
|
|
45123
|
+
async function resolvePostcssConfig(config, dialect = 'css') {
|
|
45124
|
+
postcssConfigCache[dialect] ?? (postcssConfigCache[dialect] = new WeakMap());
|
|
45125
|
+
let result = postcssConfigCache[dialect].get(config);
|
|
44673
45126
|
if (result !== undefined) {
|
|
44674
45127
|
return result;
|
|
44675
45128
|
}
|
|
@@ -44705,7 +45158,7 @@ async function resolvePostcssConfig(config) {
|
|
|
44705
45158
|
result = null;
|
|
44706
45159
|
}
|
|
44707
45160
|
}
|
|
44708
|
-
postcssConfigCache.set(config, result);
|
|
45161
|
+
postcssConfigCache[dialect].set(config, result);
|
|
44709
45162
|
return result;
|
|
44710
45163
|
}
|
|
44711
45164
|
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
|
|
@@ -44930,8 +45383,8 @@ const scss = async (source, root, options, resolvers) => {
|
|
|
44930
45383
|
const importer = [internalImporter];
|
|
44931
45384
|
if (options.importer) {
|
|
44932
45385
|
Array.isArray(options.importer)
|
|
44933
|
-
? importer.
|
|
44934
|
-
: importer.
|
|
45386
|
+
? importer.unshift(...options.importer)
|
|
45387
|
+
: importer.unshift(options.importer);
|
|
44935
45388
|
}
|
|
44936
45389
|
const { content: data, map: additionalMap } = await getSource(source, options.filename, options.additionalData, options.enableSourcemap);
|
|
44937
45390
|
const finalOptions = {
|
|
@@ -45204,6 +45657,9 @@ const preProcessors = Object.freeze({
|
|
|
45204
45657
|
function isPreProcessor(lang) {
|
|
45205
45658
|
return lang && lang in preProcessors;
|
|
45206
45659
|
}
|
|
45660
|
+
function getCssDialect(lang) {
|
|
45661
|
+
return lang === 'sss' ? 'sss' : 'css';
|
|
45662
|
+
}
|
|
45207
45663
|
|
|
45208
45664
|
function manifestPlugin(config) {
|
|
45209
45665
|
const manifest = {};
|
|
@@ -45290,6 +45746,10 @@ function manifestPlugin(config) {
|
|
|
45290
45746
|
manifest[chunk.name] = createAsset(chunk);
|
|
45291
45747
|
}
|
|
45292
45748
|
}
|
|
45749
|
+
duplicateAssets.get(config).forEach((asset) => {
|
|
45750
|
+
const chunk = createAsset(asset);
|
|
45751
|
+
manifest[asset.name] = chunk;
|
|
45752
|
+
});
|
|
45293
45753
|
outputCount++;
|
|
45294
45754
|
const output = config.build.rollupOptions?.output;
|
|
45295
45755
|
const outputLength = Array.isArray(output) ? output.length : 1;
|
|
@@ -45429,87 +45889,6 @@ function ssrManifestPlugin(config) {
|
|
|
45429
45889
|
};
|
|
45430
45890
|
}
|
|
45431
45891
|
|
|
45432
|
-
/**
|
|
45433
|
-
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
|
|
45434
|
-
*
|
|
45435
|
-
* Supports template string with dynamic segments:
|
|
45436
|
-
* ```
|
|
45437
|
-
* new URL(`./dir/${name}.png`, import.meta.url)
|
|
45438
|
-
* // transformed to
|
|
45439
|
-
* import.meta.glob('./dir/**.png', { eager: true, import: 'default' })[`./dir/${name}.png`]
|
|
45440
|
-
* ```
|
|
45441
|
-
*/
|
|
45442
|
-
function assetImportMetaUrlPlugin(config) {
|
|
45443
|
-
return {
|
|
45444
|
-
name: 'vite:asset-import-meta-url',
|
|
45445
|
-
async transform(code, id, options) {
|
|
45446
|
-
if (!options?.ssr &&
|
|
45447
|
-
id !== preloadHelperId &&
|
|
45448
|
-
code.includes('new URL') &&
|
|
45449
|
-
code.includes(`import.meta.url`)) {
|
|
45450
|
-
let s;
|
|
45451
|
-
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g;
|
|
45452
|
-
const cleanString = stripLiteral(code);
|
|
45453
|
-
let match;
|
|
45454
|
-
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
|
45455
|
-
const { 0: exp, 1: emptyUrl, index } = match;
|
|
45456
|
-
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
45457
|
-
const urlEnd = urlStart + emptyUrl.length;
|
|
45458
|
-
const rawUrl = code.slice(urlStart, urlEnd);
|
|
45459
|
-
if (!s)
|
|
45460
|
-
s = new MagicString(code);
|
|
45461
|
-
// potential dynamic template string
|
|
45462
|
-
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
|
|
45463
|
-
const ast = this.parse(rawUrl);
|
|
45464
|
-
const templateLiteral = ast.body[0].expression;
|
|
45465
|
-
if (templateLiteral.expressions.length) {
|
|
45466
|
-
const pattern = JSON.stringify(buildGlobPattern(templateLiteral));
|
|
45467
|
-
// Note: native import.meta.url is not supported in the baseline
|
|
45468
|
-
// target so we use the global location here. It can be
|
|
45469
|
-
// window.location or self.location in case it is used in a Web Worker.
|
|
45470
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Window/self
|
|
45471
|
-
s.overwrite(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, { contentOnly: true });
|
|
45472
|
-
continue;
|
|
45473
|
-
}
|
|
45474
|
-
}
|
|
45475
|
-
const url = rawUrl.slice(1, -1);
|
|
45476
|
-
const file = path$n.resolve(path$n.dirname(id), url);
|
|
45477
|
-
// Get final asset URL. Catch error if the file does not exist,
|
|
45478
|
-
// in which we can resort to the initial URL and let it resolve in runtime
|
|
45479
|
-
const builtUrl = await fileToUrl(file, config, this).catch(() => {
|
|
45480
|
-
const rawExp = code.slice(index, index + exp.length);
|
|
45481
|
-
config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
|
|
45482
|
-
return url;
|
|
45483
|
-
});
|
|
45484
|
-
s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
|
|
45485
|
-
}
|
|
45486
|
-
if (s) {
|
|
45487
|
-
return transformStableResult(s, id, config);
|
|
45488
|
-
}
|
|
45489
|
-
}
|
|
45490
|
-
return null;
|
|
45491
|
-
}
|
|
45492
|
-
};
|
|
45493
|
-
}
|
|
45494
|
-
function buildGlobPattern(ast) {
|
|
45495
|
-
let pattern = '';
|
|
45496
|
-
let lastElementIndex = -1;
|
|
45497
|
-
for (const exp of ast.expressions) {
|
|
45498
|
-
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
45499
|
-
const el = ast.quasis[i];
|
|
45500
|
-
if (el.end < exp.start) {
|
|
45501
|
-
pattern += el.value.raw;
|
|
45502
|
-
lastElementIndex = i;
|
|
45503
|
-
}
|
|
45504
|
-
}
|
|
45505
|
-
pattern += '**';
|
|
45506
|
-
}
|
|
45507
|
-
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
45508
|
-
pattern += ast.quasis[i].value.raw;
|
|
45509
|
-
}
|
|
45510
|
-
return pattern;
|
|
45511
|
-
}
|
|
45512
|
-
|
|
45513
45892
|
/**
|
|
45514
45893
|
* A plugin to provide build load fallback for arbitrary request with queries.
|
|
45515
45894
|
*/
|
|
@@ -45563,9 +45942,24 @@ function completeSystemWrapPlugin() {
|
|
|
45563
45942
|
}
|
|
45564
45943
|
|
|
45565
45944
|
function resolveBuildOptions(raw, isBuild, logger) {
|
|
45945
|
+
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload;
|
|
45946
|
+
if (raw) {
|
|
45947
|
+
const { polyfillModulePreload, ...rest } = raw;
|
|
45948
|
+
raw = rest;
|
|
45949
|
+
if (deprecatedPolyfillModulePreload !== undefined) {
|
|
45950
|
+
logger.warn('polyfillModulePreload is deprecated. Use modulePreload.polyfill instead.');
|
|
45951
|
+
}
|
|
45952
|
+
if (deprecatedPolyfillModulePreload === false &&
|
|
45953
|
+
raw.modulePreload === undefined) {
|
|
45954
|
+
raw.modulePreload = { polyfill: false };
|
|
45955
|
+
}
|
|
45956
|
+
}
|
|
45957
|
+
const modulePreload = raw?.modulePreload;
|
|
45958
|
+
const defaultModulePreload = {
|
|
45959
|
+
polyfill: true
|
|
45960
|
+
};
|
|
45566
45961
|
const resolved = {
|
|
45567
45962
|
target: 'modules',
|
|
45568
|
-
polyfillModulePreload: true,
|
|
45569
45963
|
outDir: 'dist',
|
|
45570
45964
|
assetsDir: 'assets',
|
|
45571
45965
|
assetsInlineLimit: 4096,
|
|
@@ -45594,7 +45988,16 @@ function resolveBuildOptions(raw, isBuild, logger) {
|
|
|
45594
45988
|
warnOnError: true,
|
|
45595
45989
|
exclude: [/node_modules/],
|
|
45596
45990
|
...raw?.dynamicImportVarsOptions
|
|
45597
|
-
}
|
|
45991
|
+
},
|
|
45992
|
+
// Resolve to false | object
|
|
45993
|
+
modulePreload: modulePreload === false
|
|
45994
|
+
? false
|
|
45995
|
+
: typeof modulePreload === 'object'
|
|
45996
|
+
? {
|
|
45997
|
+
...defaultModulePreload,
|
|
45998
|
+
...modulePreload
|
|
45999
|
+
}
|
|
46000
|
+
: defaultModulePreload
|
|
45598
46001
|
};
|
|
45599
46002
|
// handle special build targets
|
|
45600
46003
|
if (resolved.target === 'modules') {
|
|
@@ -45628,7 +46031,6 @@ function resolveBuildPlugins(config) {
|
|
|
45628
46031
|
watchPackageDataPlugin(config),
|
|
45629
46032
|
...(usePluginCommonjs ? [commonjs(options.commonjsOptions)] : []),
|
|
45630
46033
|
dataURIPlugin(),
|
|
45631
|
-
assetImportMetaUrlPlugin(config),
|
|
45632
46034
|
...(options.rollupOptions.plugins
|
|
45633
46035
|
? options.rollupOptions.plugins.filter(Boolean)
|
|
45634
46036
|
: [])
|
|
@@ -45677,7 +46079,15 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45677
46079
|
config.logger.info(picocolors.exports.cyan(`vite v${VERSION} ${picocolors.exports.green(`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`)}`));
|
|
45678
46080
|
const resolve = (p) => path$n.resolve(config.root, p);
|
|
45679
46081
|
const input = libOptions
|
|
45680
|
-
? options.rollupOptions?.input ||
|
|
46082
|
+
? options.rollupOptions?.input ||
|
|
46083
|
+
(typeof libOptions.entry === 'string'
|
|
46084
|
+
? resolve(libOptions.entry)
|
|
46085
|
+
: Array.isArray(libOptions.entry)
|
|
46086
|
+
? libOptions.entry.map(resolve)
|
|
46087
|
+
: Object.fromEntries(Object.entries(libOptions.entry).map(([alias, file]) => [
|
|
46088
|
+
alias,
|
|
46089
|
+
resolve(file)
|
|
46090
|
+
])))
|
|
45681
46091
|
: typeof options.ssr === 'string'
|
|
45682
46092
|
? resolve(options.ssr)
|
|
45683
46093
|
: options.rollupOptions?.input || resolve('index.html');
|
|
@@ -45754,7 +46164,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45754
46164
|
entryFileNames: ssr
|
|
45755
46165
|
? `[name].${jsExt}`
|
|
45756
46166
|
: libOptions
|
|
45757
|
-
? resolveLibFilename(libOptions, format, config.root, jsExt)
|
|
46167
|
+
? ({ name }) => resolveLibFilename(libOptions, format, name, config.root, jsExt)
|
|
45758
46168
|
: path$n.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
|
|
45759
46169
|
chunkFileNames: libOptions
|
|
45760
46170
|
? `[name].[hash].${jsExt}`
|
|
@@ -45771,23 +46181,24 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45771
46181
|
};
|
|
45772
46182
|
// resolve lib mode outputs
|
|
45773
46183
|
const outputs = resolveBuildOutputs(options.rollupOptions?.output, libOptions, config.logger);
|
|
46184
|
+
const normalizedOutputs = [];
|
|
46185
|
+
if (Array.isArray(outputs)) {
|
|
46186
|
+
for (const resolvedOutput of outputs) {
|
|
46187
|
+
normalizedOutputs.push(buildOutputOptions(resolvedOutput));
|
|
46188
|
+
}
|
|
46189
|
+
}
|
|
46190
|
+
else {
|
|
46191
|
+
normalizedOutputs.push(buildOutputOptions(outputs));
|
|
46192
|
+
}
|
|
46193
|
+
const outDirs = normalizedOutputs.map(({ dir }) => resolve(dir));
|
|
45774
46194
|
// watch file changes with rollup
|
|
45775
46195
|
if (config.build.watch) {
|
|
45776
46196
|
config.logger.info(picocolors.exports.cyan(`\nwatching for file changes...`));
|
|
45777
|
-
const output = [];
|
|
45778
|
-
if (Array.isArray(outputs)) {
|
|
45779
|
-
for (const resolvedOutput of outputs) {
|
|
45780
|
-
output.push(buildOutputOptions(resolvedOutput));
|
|
45781
|
-
}
|
|
45782
|
-
}
|
|
45783
|
-
else {
|
|
45784
|
-
output.push(buildOutputOptions(outputs));
|
|
45785
|
-
}
|
|
45786
46197
|
const resolvedChokidarOptions = resolveChokidarOptions(config.build.watch.chokidar);
|
|
45787
46198
|
const { watch } = await import('rollup');
|
|
45788
46199
|
const watcher = watch({
|
|
45789
46200
|
...rollupOptions,
|
|
45790
|
-
output,
|
|
46201
|
+
output: normalizedOutputs,
|
|
45791
46202
|
watch: {
|
|
45792
46203
|
...config.build.watch,
|
|
45793
46204
|
chokidar: resolvedChokidarOptions
|
|
@@ -45797,7 +46208,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45797
46208
|
if (event.code === 'BUNDLE_START') {
|
|
45798
46209
|
config.logger.info(picocolors.exports.cyan(`\nbuild started...`));
|
|
45799
46210
|
if (options.write) {
|
|
45800
|
-
prepareOutDir(
|
|
46211
|
+
prepareOutDir(outDirs, options.emptyOutDir, config);
|
|
45801
46212
|
}
|
|
45802
46213
|
}
|
|
45803
46214
|
else if (event.code === 'BUNDLE_END') {
|
|
@@ -45815,41 +46226,56 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45815
46226
|
const bundle = await rollup(rollupOptions);
|
|
45816
46227
|
parallelBuilds.push(bundle);
|
|
45817
46228
|
const generate = (output = {}) => {
|
|
45818
|
-
return bundle[options.write ? 'write' : 'generate'](
|
|
46229
|
+
return bundle[options.write ? 'write' : 'generate'](output);
|
|
45819
46230
|
};
|
|
45820
46231
|
if (options.write) {
|
|
45821
|
-
prepareOutDir(
|
|
45822
|
-
}
|
|
45823
|
-
if (Array.isArray(outputs)) {
|
|
45824
|
-
const res = [];
|
|
45825
|
-
for (const output of outputs) {
|
|
45826
|
-
res.push(await generate(output));
|
|
45827
|
-
}
|
|
45828
|
-
return res;
|
|
46232
|
+
prepareOutDir(outDirs, options.emptyOutDir, config);
|
|
45829
46233
|
}
|
|
45830
|
-
|
|
45831
|
-
|
|
46234
|
+
const res = [];
|
|
46235
|
+
for (const output of normalizedOutputs) {
|
|
46236
|
+
res.push(await generate(output));
|
|
45832
46237
|
}
|
|
46238
|
+
return Array.isArray(outputs) ? res : res[0];
|
|
45833
46239
|
}
|
|
45834
46240
|
catch (e) {
|
|
45835
46241
|
outputBuildError(e);
|
|
45836
46242
|
throw e;
|
|
45837
46243
|
}
|
|
45838
46244
|
}
|
|
45839
|
-
function prepareOutDir(
|
|
45840
|
-
|
|
45841
|
-
|
|
45842
|
-
|
|
45843
|
-
|
|
45844
|
-
|
|
45845
|
-
|
|
45846
|
-
|
|
45847
|
-
|
|
45848
|
-
|
|
46245
|
+
function prepareOutDir(outDirs, emptyOutDir, config) {
|
|
46246
|
+
const nonDuplicateDirs = new Set(outDirs);
|
|
46247
|
+
let outside = false;
|
|
46248
|
+
if (emptyOutDir == null) {
|
|
46249
|
+
for (const outDir of nonDuplicateDirs) {
|
|
46250
|
+
if (fs$l.existsSync(outDir) &&
|
|
46251
|
+
!normalizePath$3(outDir).startsWith(config.root + '/')) {
|
|
46252
|
+
// warn if outDir is outside of root
|
|
46253
|
+
config.logger.warn(picocolors.exports.yellow(`\n${picocolors.exports.bold(`(!)`)} outDir ${picocolors.exports.white(picocolors.exports.dim(outDir))} is not inside project root and will not be emptied.\n` +
|
|
46254
|
+
`Use --emptyOutDir to override.\n`));
|
|
46255
|
+
outside = true;
|
|
46256
|
+
break;
|
|
46257
|
+
}
|
|
45849
46258
|
}
|
|
45850
46259
|
}
|
|
45851
|
-
|
|
45852
|
-
|
|
46260
|
+
for (const outDir of nonDuplicateDirs) {
|
|
46261
|
+
if (!outside && emptyOutDir !== false && fs$l.existsSync(outDir)) {
|
|
46262
|
+
// skip those other outDirs which are nested in current outDir
|
|
46263
|
+
const skipDirs = outDirs
|
|
46264
|
+
.map((dir) => {
|
|
46265
|
+
const relative = path$n.relative(outDir, dir);
|
|
46266
|
+
if (relative &&
|
|
46267
|
+
!relative.startsWith('..') &&
|
|
46268
|
+
!path$n.isAbsolute(relative)) {
|
|
46269
|
+
return relative;
|
|
46270
|
+
}
|
|
46271
|
+
return '';
|
|
46272
|
+
})
|
|
46273
|
+
.filter(Boolean);
|
|
46274
|
+
emptyDir(outDir, [...skipDirs, '.git']);
|
|
46275
|
+
}
|
|
46276
|
+
if (config.publicDir && fs$l.existsSync(config.publicDir)) {
|
|
46277
|
+
copyDir(config.publicDir, outDir);
|
|
46278
|
+
}
|
|
45853
46279
|
}
|
|
45854
46280
|
}
|
|
45855
46281
|
function getPkgJson(root) {
|
|
@@ -45866,12 +46292,15 @@ function resolveOutputJsExtension(format, type = 'commonjs') {
|
|
|
45866
46292
|
return format === 'es' ? 'mjs' : 'js';
|
|
45867
46293
|
}
|
|
45868
46294
|
}
|
|
45869
|
-
function resolveLibFilename(libOptions, format, root, extension) {
|
|
46295
|
+
function resolveLibFilename(libOptions, format, entryName, root, extension) {
|
|
45870
46296
|
if (typeof libOptions.fileName === 'function') {
|
|
45871
|
-
return libOptions.fileName(format);
|
|
46297
|
+
return libOptions.fileName(format, entryName);
|
|
45872
46298
|
}
|
|
45873
46299
|
const packageJson = getPkgJson(root);
|
|
45874
|
-
const name = libOptions.fileName ||
|
|
46300
|
+
const name = libOptions.fileName ||
|
|
46301
|
+
(typeof libOptions.entry === 'string'
|
|
46302
|
+
? getPkgName(packageJson.name)
|
|
46303
|
+
: entryName);
|
|
45875
46304
|
if (!name)
|
|
45876
46305
|
throw new Error('Name in package.json is required if option "build.lib.fileName" is not provided.');
|
|
45877
46306
|
extension ?? (extension = resolveOutputJsExtension(format, packageJson.type));
|
|
@@ -45882,11 +46311,17 @@ function resolveLibFilename(libOptions, format, root, extension) {
|
|
|
45882
46311
|
}
|
|
45883
46312
|
function resolveBuildOutputs(outputs, libOptions, logger) {
|
|
45884
46313
|
if (libOptions) {
|
|
45885
|
-
const
|
|
45886
|
-
|
|
45887
|
-
|
|
45888
|
-
|
|
45889
|
-
|
|
46314
|
+
const hasMultipleEntries = typeof libOptions.entry !== 'string' &&
|
|
46315
|
+
Object.values(libOptions.entry).length > 1;
|
|
46316
|
+
const formats = libOptions.formats || (hasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']);
|
|
46317
|
+
if (formats.includes('umd') || formats.includes('iife')) {
|
|
46318
|
+
if (hasMultipleEntries) {
|
|
46319
|
+
throw new Error(`Multiple entry points are not supported when output formats include "umd" or "iife".`);
|
|
46320
|
+
}
|
|
46321
|
+
if (!libOptions.name) {
|
|
46322
|
+
throw new Error(`Option "build.lib.name" is required when output formats ` +
|
|
46323
|
+
`include "umd" or "iife".`);
|
|
46324
|
+
}
|
|
45890
46325
|
}
|
|
45891
46326
|
if (!outputs) {
|
|
45892
46327
|
return formats.map((format) => ({ format }));
|
|
@@ -46070,7 +46505,7 @@ const relativeUrlMechanisms = {
|
|
|
46070
46505
|
system: (relativePath) => getResolveUrl(`'${relativePath}', module.meta.url`),
|
|
46071
46506
|
umd: (relativePath) => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getResolveUrl(`'file:' + __dirname + '/${relativePath}'`, `(require('u' + 'rl').URL)`)} : ${getRelativeUrlFromDocument(relativePath, true)})`
|
|
46072
46507
|
};
|
|
46073
|
-
function
|
|
46508
|
+
function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
|
|
46074
46509
|
const { renderBuiltUrl } = config.experimental;
|
|
46075
46510
|
let relative = config.base === '' || config.base === './';
|
|
46076
46511
|
if (renderBuiltUrl) {
|
|
@@ -46097,7 +46532,7 @@ function toOutputFilePathInString(filename, type, hostId, hostType, config, form
|
|
|
46097
46532
|
}
|
|
46098
46533
|
return config.base + filename;
|
|
46099
46534
|
}
|
|
46100
|
-
function
|
|
46535
|
+
function createToImportMetaURLBasedRelativeRuntime(format) {
|
|
46101
46536
|
const toRelativePath = relativeUrlMechanisms[format];
|
|
46102
46537
|
return (filename, importer) => ({
|
|
46103
46538
|
runtime: toRelativePath(path$n.posix.relative(path$n.dirname(importer), filename))
|
|
@@ -46141,8 +46576,10 @@ var build$1 = {
|
|
|
46141
46576
|
resolveBuildPlugins: resolveBuildPlugins,
|
|
46142
46577
|
build: build,
|
|
46143
46578
|
resolveLibFilename: resolveLibFilename,
|
|
46579
|
+
resolveBuildOutputs: resolveBuildOutputs,
|
|
46144
46580
|
onRollupWarning: onRollupWarning,
|
|
46145
|
-
|
|
46581
|
+
toOutputFilePathInJS: toOutputFilePathInJS,
|
|
46582
|
+
createToImportMetaURLBasedRelativeRuntime: createToImportMetaURLBasedRelativeRuntime,
|
|
46146
46583
|
toOutputFilePathWithoutRuntime: toOutputFilePathWithoutRuntime,
|
|
46147
46584
|
toOutputFilePathInCss: toOutputFilePathInCss,
|
|
46148
46585
|
toOutputFilePathInHtml: toOutputFilePathInHtml
|
|
@@ -48945,7 +49382,7 @@ const fs$9 = require$$0__default;
|
|
|
48945
49382
|
const { Readable } = require$$0$7;
|
|
48946
49383
|
const sysPath$3 = require$$0$4;
|
|
48947
49384
|
const { promisify: promisify$3 } = require$$0$6;
|
|
48948
|
-
const picomatch$1 = picomatch$
|
|
49385
|
+
const picomatch$1 = picomatch$5.exports;
|
|
48949
49386
|
|
|
48950
49387
|
const readdir$1 = promisify$3(fs$9.readdir);
|
|
48951
49388
|
const stat$3 = promisify$3(fs$9.stat);
|
|
@@ -49267,7 +49704,7 @@ var normalizePath$2 = function(path, stripTrailing) {
|
|
|
49267
49704
|
|
|
49268
49705
|
Object.defineProperty(anymatch$2.exports, "__esModule", { value: true });
|
|
49269
49706
|
|
|
49270
|
-
const picomatch = picomatch$
|
|
49707
|
+
const picomatch = picomatch$5.exports;
|
|
49271
49708
|
const normalizePath$1 = normalizePath$2;
|
|
49272
49709
|
|
|
49273
49710
|
/**
|
|
@@ -52509,7 +52946,7 @@ async function resolveHttpServer({ proxy }, app, httpsOptions) {
|
|
|
52509
52946
|
app);
|
|
52510
52947
|
}
|
|
52511
52948
|
}
|
|
52512
|
-
async function resolveHttpsConfig(https
|
|
52949
|
+
async function resolveHttpsConfig(https) {
|
|
52513
52950
|
if (!https)
|
|
52514
52951
|
return undefined;
|
|
52515
52952
|
const httpsOption = isObject$2(https) ? { ...https } : {};
|
|
@@ -52964,7 +53401,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
|
|
|
52964
53401
|
}
|
|
52965
53402
|
else {
|
|
52966
53403
|
// anonymous default exports
|
|
52967
|
-
s.
|
|
53404
|
+
s.update(node.start, node.start + 14 /* 'export default'.length */, `${ssrModuleExportsKey}.default =`);
|
|
52968
53405
|
}
|
|
52969
53406
|
}
|
|
52970
53407
|
// export * from './foo'
|
|
@@ -53007,16 +53444,14 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
|
|
|
53007
53444
|
}
|
|
53008
53445
|
}
|
|
53009
53446
|
else {
|
|
53010
|
-
s.
|
|
53447
|
+
s.update(id.start, id.end, binding);
|
|
53011
53448
|
}
|
|
53012
53449
|
},
|
|
53013
53450
|
onImportMeta(node) {
|
|
53014
|
-
s.
|
|
53451
|
+
s.update(node.start, node.end, ssrImportMetaKey);
|
|
53015
53452
|
},
|
|
53016
53453
|
onDynamicImport(node) {
|
|
53017
|
-
s.
|
|
53018
|
-
contentOnly: true
|
|
53019
|
-
});
|
|
53454
|
+
s.update(node.start, node.start + 6, ssrDynamicImportKey);
|
|
53020
53455
|
if (node.type === 'ImportExpression' && node.source.type === 'Literal') {
|
|
53021
53456
|
dynamicDeps.add(node.source.value);
|
|
53022
53457
|
}
|
|
@@ -53382,13 +53817,15 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
|
|
|
53382
53817
|
// CommonJS modules are preferred. We want to avoid ESM->ESM imports
|
|
53383
53818
|
// whenever possible, because `hookNodeResolve` can't intercept them.
|
|
53384
53819
|
const resolveOptions = {
|
|
53385
|
-
|
|
53820
|
+
mainFields: ['main'],
|
|
53821
|
+
browserField: true,
|
|
53822
|
+
conditions: [],
|
|
53386
53823
|
extensions: ['.js', '.cjs', '.json'],
|
|
53824
|
+
dedupe,
|
|
53825
|
+
preserveSymlinks,
|
|
53387
53826
|
isBuild: true,
|
|
53388
53827
|
isProduction,
|
|
53389
53828
|
isRequire: true,
|
|
53390
|
-
mainFields: ['main'],
|
|
53391
|
-
preserveSymlinks,
|
|
53392
53829
|
root
|
|
53393
53830
|
};
|
|
53394
53831
|
// Since dynamic imports can happen in parallel, we need to
|
|
@@ -56607,20 +57044,20 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56607
57044
|
}
|
|
56608
57045
|
|
|
56609
57046
|
const isSecure = parsedUrl.protocol === 'wss:';
|
|
56610
|
-
const
|
|
56611
|
-
let
|
|
57047
|
+
const isIpcUrl = parsedUrl.protocol === 'ws+unix:';
|
|
57048
|
+
let invalidUrlMessage;
|
|
56612
57049
|
|
|
56613
|
-
if (parsedUrl.protocol !== 'ws:' && !isSecure && !
|
|
56614
|
-
|
|
57050
|
+
if (parsedUrl.protocol !== 'ws:' && !isSecure && !isIpcUrl) {
|
|
57051
|
+
invalidUrlMessage =
|
|
56615
57052
|
'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"';
|
|
56616
|
-
} else if (
|
|
56617
|
-
|
|
57053
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
57054
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
56618
57055
|
} else if (parsedUrl.hash) {
|
|
56619
|
-
|
|
57056
|
+
invalidUrlMessage = 'The URL contains a fragment identifier';
|
|
56620
57057
|
}
|
|
56621
57058
|
|
|
56622
|
-
if (
|
|
56623
|
-
const err = new SyntaxError(
|
|
57059
|
+
if (invalidUrlMessage) {
|
|
57060
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
56624
57061
|
|
|
56625
57062
|
if (websocket._redirects === 0) {
|
|
56626
57063
|
throw err;
|
|
@@ -56690,7 +57127,7 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56690
57127
|
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
56691
57128
|
}
|
|
56692
57129
|
|
|
56693
|
-
if (
|
|
57130
|
+
if (isIpcUrl) {
|
|
56694
57131
|
const parts = opts.path.split(':');
|
|
56695
57132
|
|
|
56696
57133
|
opts.socketPath = parts[0];
|
|
@@ -56701,9 +57138,9 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56701
57138
|
|
|
56702
57139
|
if (opts.followRedirects) {
|
|
56703
57140
|
if (websocket._redirects === 0) {
|
|
56704
|
-
websocket.
|
|
57141
|
+
websocket._originalIpc = isIpcUrl;
|
|
56705
57142
|
websocket._originalSecure = isSecure;
|
|
56706
|
-
websocket._originalHostOrSocketPath =
|
|
57143
|
+
websocket._originalHostOrSocketPath = isIpcUrl
|
|
56707
57144
|
? opts.socketPath
|
|
56708
57145
|
: parsedUrl.host;
|
|
56709
57146
|
|
|
@@ -56721,11 +57158,11 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56721
57158
|
}
|
|
56722
57159
|
}
|
|
56723
57160
|
} else if (websocket.listenerCount('redirect') === 0) {
|
|
56724
|
-
const isSameHost =
|
|
56725
|
-
? websocket.
|
|
57161
|
+
const isSameHost = isIpcUrl
|
|
57162
|
+
? websocket._originalIpc
|
|
56726
57163
|
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
56727
57164
|
: false
|
|
56728
|
-
: websocket.
|
|
57165
|
+
: websocket._originalIpc
|
|
56729
57166
|
? false
|
|
56730
57167
|
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
56731
57168
|
|
|
@@ -60315,9 +60752,9 @@ var lib = {exports: {}};
|
|
|
60315
60752
|
|
|
60316
60753
|
var history = lib.exports;
|
|
60317
60754
|
|
|
60318
|
-
function
|
|
60319
|
-
const
|
|
60320
|
-
logger: createDebugger('vite:
|
|
60755
|
+
function htmlFallbackMiddleware(root, spaFallback) {
|
|
60756
|
+
const historyHtmlFallbackMiddleware = history({
|
|
60757
|
+
logger: createDebugger('vite:html-fallback'),
|
|
60321
60758
|
// support /dir/ without explicit index.html
|
|
60322
60759
|
rewrites: [
|
|
60323
60760
|
{
|
|
@@ -60328,15 +60765,17 @@ function spaFallbackMiddleware(root) {
|
|
|
60328
60765
|
return rewritten;
|
|
60329
60766
|
}
|
|
60330
60767
|
else {
|
|
60331
|
-
|
|
60768
|
+
if (spaFallback) {
|
|
60769
|
+
return `/index.html`;
|
|
60770
|
+
}
|
|
60332
60771
|
}
|
|
60333
60772
|
}
|
|
60334
60773
|
}
|
|
60335
60774
|
]
|
|
60336
60775
|
});
|
|
60337
60776
|
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
60338
|
-
return function
|
|
60339
|
-
return
|
|
60777
|
+
return function viteHtmlFallbackMiddleware(req, res, next) {
|
|
60778
|
+
return historyHtmlFallbackMiddleware(req, res, next);
|
|
60340
60779
|
};
|
|
60341
60780
|
}
|
|
60342
60781
|
|
|
@@ -60586,7 +61025,7 @@ const processNodeUrl = (attr, sourceCodeLocation, s, config, htmlPath, originalU
|
|
|
60586
61025
|
// path will add `/a/` prefix, it will caused 404.
|
|
60587
61026
|
// rewrite before `./index.js` -> `localhost:5173/a/index.js`.
|
|
60588
61027
|
// rewrite after `../index.js` -> `localhost:5173/index.js`.
|
|
60589
|
-
const processedUrl = attr.name === 'srcset'
|
|
61028
|
+
const processedUrl = attr.name === 'srcset' && attr.prefix === undefined
|
|
60590
61029
|
? processSrcSetSync(url, ({ url }) => replacer(url))
|
|
60591
61030
|
: replacer(url);
|
|
60592
61031
|
overwriteAttrValue(s, sourceCodeLocation, processedUrl);
|
|
@@ -60637,7 +61076,7 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
60637
61076
|
if (module) {
|
|
60638
61077
|
server?.moduleGraph.invalidateModule(module);
|
|
60639
61078
|
}
|
|
60640
|
-
s.
|
|
61079
|
+
s.update(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset, `<script type="module" src="${modulePath}"></script>`);
|
|
60641
61080
|
};
|
|
60642
61081
|
await traverseHtml(html, htmlPath, (node) => {
|
|
60643
61082
|
if (!nodeIsElement(node)) {
|
|
@@ -60665,8 +61104,9 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
60665
61104
|
const assetAttrs = assetAttrsConfig[node.nodeName];
|
|
60666
61105
|
if (assetAttrs) {
|
|
60667
61106
|
for (const p of node.attrs) {
|
|
60668
|
-
|
|
60669
|
-
|
|
61107
|
+
const attrKey = getAttrKey(p);
|
|
61108
|
+
if (p.value && assetAttrs.includes(attrKey)) {
|
|
61109
|
+
processNodeUrl(p, node.sourceCodeLocation.attrs[attrKey], s, config, htmlPath, originalUrl);
|
|
60670
61110
|
}
|
|
60671
61111
|
}
|
|
60672
61112
|
}
|
|
@@ -60701,7 +61141,7 @@ function indexHtmlMiddleware(server) {
|
|
|
60701
61141
|
return next();
|
|
60702
61142
|
}
|
|
60703
61143
|
const url = req.url && cleanUrl(req.url);
|
|
60704
|
-
//
|
|
61144
|
+
// htmlFallbackMiddleware appends '.html' to URLs
|
|
60705
61145
|
if (url?.endsWith('.html') && req.headers['sec-fetch-dest'] !== 'script') {
|
|
60706
61146
|
const filename = getHtmlFilename(url, server);
|
|
60707
61147
|
if (fs$l.existsSync(filename)) {
|
|
@@ -62160,6 +62600,8 @@ async function createServer(inlineConfig = {}) {
|
|
|
62160
62600
|
watcher.close(),
|
|
62161
62601
|
ws.close(),
|
|
62162
62602
|
container.close(),
|
|
62603
|
+
getDepsOptimizer(server.config)?.close(),
|
|
62604
|
+
getDepsOptimizer(server.config, true)?.close(),
|
|
62163
62605
|
closeHttpServer()
|
|
62164
62606
|
]);
|
|
62165
62607
|
server.resolvedUrls = null;
|
|
@@ -62189,7 +62631,8 @@ async function createServer(inlineConfig = {}) {
|
|
|
62189
62631
|
_restartPromise: null,
|
|
62190
62632
|
_importGlobMap: new Map(),
|
|
62191
62633
|
_forceOptimizeOnRestart: false,
|
|
62192
|
-
_pendingRequests: new Map()
|
|
62634
|
+
_pendingRequests: new Map(),
|
|
62635
|
+
_fsDenyGlob: picomatch$3(config.server.fs.deny, { matchBase: true })
|
|
62193
62636
|
};
|
|
62194
62637
|
server.transformIndexHtml = createDevHtmlTransformFn(server);
|
|
62195
62638
|
if (!middlewareMode) {
|
|
@@ -62239,6 +62682,13 @@ async function createServer(inlineConfig = {}) {
|
|
|
62239
62682
|
watcher.on('unlink', (file) => {
|
|
62240
62683
|
handleFileAddUnlink(normalizePath$3(file), server);
|
|
62241
62684
|
});
|
|
62685
|
+
ws.on('vite:invalidate', async ({ path }) => {
|
|
62686
|
+
const mod = moduleGraph.urlToModuleMap.get(path);
|
|
62687
|
+
if (mod && mod.isSelfAccepting && mod.lastHMRTimestamp > 0) {
|
|
62688
|
+
const file = getShortName(mod.file, config.root);
|
|
62689
|
+
updateModules(file, [...mod.importers], mod.lastHMRTimestamp, server);
|
|
62690
|
+
}
|
|
62691
|
+
});
|
|
62242
62692
|
if (!middlewareMode && httpServer) {
|
|
62243
62693
|
httpServer.once('listening', () => {
|
|
62244
62694
|
// update actual port since this may be different from initial value
|
|
@@ -62283,9 +62733,9 @@ async function createServer(inlineConfig = {}) {
|
|
|
62283
62733
|
// serve static files
|
|
62284
62734
|
middlewares.use(serveRawFsMiddleware(server));
|
|
62285
62735
|
middlewares.use(serveStaticMiddleware(root, server));
|
|
62286
|
-
//
|
|
62287
|
-
if (config.appType === 'spa') {
|
|
62288
|
-
middlewares.use(
|
|
62736
|
+
// html fallback
|
|
62737
|
+
if (config.appType === 'spa' || config.appType === 'mpa') {
|
|
62738
|
+
middlewares.use(htmlFallbackMiddleware(root, config.appType === 'spa'));
|
|
62289
62739
|
}
|
|
62290
62740
|
// run post config hooks
|
|
62291
62741
|
// This is applied before the html middleware so that user middleware can
|
|
@@ -62914,10 +63364,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
|
62914
63364
|
prefixes = arraify(prefixes);
|
|
62915
63365
|
const env = {};
|
|
62916
63366
|
const envFiles = [
|
|
62917
|
-
/**
|
|
62918
|
-
/** mode file */ `.env.${mode}`,
|
|
63367
|
+
/** default file */ `.env`,
|
|
62919
63368
|
/** local file */ `.env.local`,
|
|
62920
|
-
/**
|
|
63369
|
+
/** mode file */ `.env.${mode}`,
|
|
63370
|
+
/** mode local file */ `.env.${mode}.local`
|
|
62921
63371
|
];
|
|
62922
63372
|
// check if there are actual env variables starting with VITE_*
|
|
62923
63373
|
// these are typically provided inline and should be prioritized
|
|
@@ -62927,30 +63377,32 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
|
62927
63377
|
env[key] = process.env[key];
|
|
62928
63378
|
}
|
|
62929
63379
|
}
|
|
62930
|
-
|
|
62931
|
-
const path = lookupFile(envDir, [file], {
|
|
62932
|
-
|
|
62933
|
-
|
|
62934
|
-
|
|
62935
|
-
|
|
62936
|
-
|
|
62937
|
-
|
|
62938
|
-
|
|
62939
|
-
|
|
62940
|
-
|
|
62941
|
-
|
|
62942
|
-
|
|
62943
|
-
|
|
62944
|
-
|
|
62945
|
-
|
|
62946
|
-
|
|
62947
|
-
|
|
62948
|
-
|
|
62949
|
-
|
|
62950
|
-
|
|
62951
|
-
|
|
62952
|
-
|
|
62953
|
-
|
|
63380
|
+
const parsed = Object.fromEntries(envFiles.flatMap((file) => {
|
|
63381
|
+
const path = lookupFile(envDir, [file], {
|
|
63382
|
+
pathOnly: true,
|
|
63383
|
+
rootDir: envDir
|
|
63384
|
+
});
|
|
63385
|
+
if (!path)
|
|
63386
|
+
return [];
|
|
63387
|
+
return Object.entries(main$1.exports.parse(fs$l.readFileSync(path), {
|
|
63388
|
+
debug: process.env.DEBUG?.includes('vite:dotenv')
|
|
63389
|
+
}));
|
|
63390
|
+
}));
|
|
63391
|
+
// let environment variables use each other
|
|
63392
|
+
main({
|
|
63393
|
+
parsed,
|
|
63394
|
+
// prevent process.env mutation
|
|
63395
|
+
ignoreProcessEnv: true
|
|
63396
|
+
});
|
|
63397
|
+
// only keys that start with prefix are exposed to client
|
|
63398
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
63399
|
+
if (prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
63400
|
+
env[key] = value;
|
|
63401
|
+
}
|
|
63402
|
+
else if (key === 'NODE_ENV' &&
|
|
63403
|
+
process.env.VITE_USER_NODE_ENV === undefined) {
|
|
63404
|
+
// NODE_ENV override in .env file
|
|
63405
|
+
process.env.VITE_USER_NODE_ENV = value;
|
|
62954
63406
|
}
|
|
62955
63407
|
}
|
|
62956
63408
|
return env;
|
|
@@ -62963,7 +63415,7 @@ function resolveEnvPrefix({ envPrefix = 'VITE_' }) {
|
|
|
62963
63415
|
return envPrefix;
|
|
62964
63416
|
}
|
|
62965
63417
|
|
|
62966
|
-
function resolveSSROptions(ssr,
|
|
63418
|
+
function resolveSSROptions(ssr, preserveSymlinks, buildSsrCjsExternalHeuristics) {
|
|
62967
63419
|
ssr ?? (ssr = {});
|
|
62968
63420
|
const optimizeDeps = ssr.optimizeDeps ?? {};
|
|
62969
63421
|
let format = 'esm';
|
|
@@ -63094,7 +63546,12 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63094
63546
|
// replacement, but its implementation does work with function values.
|
|
63095
63547
|
clientAlias, config.resolve?.alias || []));
|
|
63096
63548
|
const resolveOptions = {
|
|
63097
|
-
|
|
63549
|
+
mainFields: config.resolve?.mainFields ?? DEFAULT_MAIN_FIELDS,
|
|
63550
|
+
browserField: config.resolve?.browserField ?? true,
|
|
63551
|
+
conditions: config.resolve?.conditions ?? [],
|
|
63552
|
+
extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS$1,
|
|
63553
|
+
dedupe: config.resolve?.dedupe ?? [],
|
|
63554
|
+
preserveSymlinks: config.resolve?.preserveSymlinks ?? false,
|
|
63098
63555
|
alias: resolvedAlias
|
|
63099
63556
|
};
|
|
63100
63557
|
// load .env files
|
|
@@ -63123,7 +63580,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63123
63580
|
? '/'
|
|
63124
63581
|
: './'
|
|
63125
63582
|
: resolveBaseUrl(config.base, isBuild, logger) ?? '/';
|
|
63126
|
-
const resolvedBuildOptions = resolveBuildOptions(config.build);
|
|
63583
|
+
const resolvedBuildOptions = resolveBuildOptions(config.build, isBuild, logger);
|
|
63127
63584
|
// resolve cache directory
|
|
63128
63585
|
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true });
|
|
63129
63586
|
const cacheDir = config.cacheDir
|
|
@@ -63178,7 +63635,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63178
63635
|
? path$n.resolve(resolvedRoot, typeof publicDir === 'string' ? publicDir : 'public')
|
|
63179
63636
|
: '';
|
|
63180
63637
|
const server = resolveServerOptions(resolvedRoot, config.server, logger);
|
|
63181
|
-
const ssr = resolveSSROptions(config.ssr,
|
|
63638
|
+
const ssr = resolveSSROptions(config.ssr, resolveOptions.preserveSymlinks, config.legacy?.buildSsrCjsExternalHeuristics);
|
|
63182
63639
|
const middlewareMode = config?.server?.middlewareMode;
|
|
63183
63640
|
const optimizeDeps = config.optimizeDeps || {};
|
|
63184
63641
|
const BASE_URL = resolvedBase;
|
|
@@ -63235,7 +63692,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63235
63692
|
disabled: 'build',
|
|
63236
63693
|
...optimizeDeps,
|
|
63237
63694
|
esbuildOptions: {
|
|
63238
|
-
preserveSymlinks:
|
|
63695
|
+
preserveSymlinks: resolveOptions.preserveSymlinks,
|
|
63239
63696
|
...optimizeDeps.esbuildOptions
|
|
63240
63697
|
}
|
|
63241
63698
|
},
|
|
@@ -63457,6 +63914,7 @@ async function bundleConfigFile(fileName, isESM) {
|
|
|
63457
63914
|
preferRelative: false,
|
|
63458
63915
|
tryIndex: true,
|
|
63459
63916
|
mainFields: [],
|
|
63917
|
+
browserField: false,
|
|
63460
63918
|
conditions: [],
|
|
63461
63919
|
dedupe: [],
|
|
63462
63920
|
extensions: DEFAULT_EXTENSIONS$1,
|