vite 3.1.3 → 3.2.0-beta.0
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-42c2c4e4.js → dep-39e6741e.js} +0 -0
- package/dist/node/chunks/{dep-0fc42251.js → dep-553f6a62.js} +1 -1
- package/dist/node/chunks/{dep-557f29e6.js → dep-92763d7a.js} +1073 -655
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -1
- package/dist/node/index.d.ts +85 -164
- package/dist/node/index.js +1 -1
- package/dist/node-cjs/publicUtils.cjs +30 -28
- package/package.json +23 -16
- 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/terser.d.ts +1 -250
- package/types/ws.d.ts +1 -553
- package/types/package.json +0 -3
- package/types/shims.d.ts +0 -96
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs$l, { promises as promises$2 } from 'node:fs';
|
|
2
|
-
import path$n, { posix as posix$2, isAbsolute as isAbsolute$
|
|
2
|
+
import path$n, { posix as posix$2, isAbsolute as isAbsolute$3, resolve as resolve$6, join as join$2, relative as relative$2, dirname as dirname$2, basename as basename$2, extname as extname$1 } from 'node:path';
|
|
3
3
|
import { URL as URL$3, pathToFileURL, URLSearchParams, parse as parse$k } from 'node:url';
|
|
4
4
|
import { performance } from 'node:perf_hooks';
|
|
5
5
|
import { createRequire as createRequire$1, builtinModules } from 'node:module';
|
|
6
6
|
import require$$0$3 from 'tty';
|
|
7
7
|
import { transform as transform$2, build as build$3, formatMessages } from 'esbuild';
|
|
8
|
-
import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$
|
|
8
|
+
import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$2, normalize } from 'path';
|
|
9
9
|
import * as require$$0$2 from 'fs';
|
|
10
10
|
import require$$0__default, { existsSync, readFileSync, statSync as statSync$1, promises as promises$1, readdirSync } from 'fs';
|
|
11
11
|
import require$$0$5 from 'events';
|
|
@@ -22,7 +22,7 @@ import { createHash as createHash$2 } from 'node:crypto';
|
|
|
22
22
|
import { promisify as promisify$4 } from 'node:util';
|
|
23
23
|
import { promises } from 'node:dns';
|
|
24
24
|
import resolve$5 from 'resolve';
|
|
25
|
-
import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, DEFAULT_EXTENSIONS as DEFAULT_EXTENSIONS$1, wildcardHosts, loopbackHosts, VALID_ID_PREFIX, NULL_BYTE_PLACEHOLDER, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, ENV_ENTRY, DEFAULT_MAIN_FIELDS,
|
|
25
|
+
import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, DEFAULT_EXTENSIONS as DEFAULT_EXTENSIONS$1, wildcardHosts, loopbackHosts, VALID_ID_PREFIX, NULL_BYTE_PLACEHOLDER, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, ENV_ENTRY, DEFAULT_MAIN_FIELDS, SPECIAL_QUERY_RE, DEP_VERSION_RE, KNOWN_ASSET_TYPES, CLIENT_DIR, JS_TYPES_RE, ESBUILD_MODULES_TARGET, VERSION, VITE_PACKAGE_DIR, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
|
|
26
26
|
import require$$5 from 'crypto';
|
|
27
27
|
import require$$0$a from 'buffer';
|
|
28
28
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
@@ -210,7 +210,7 @@ function alias$1(options = {}) {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
var picomatch$
|
|
213
|
+
var picomatch$5 = {exports: {}};
|
|
214
214
|
|
|
215
215
|
var utils$k = {};
|
|
216
216
|
|
|
@@ -1960,9 +1960,9 @@ const isObject$4 = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
|
1960
1960
|
* @api public
|
|
1961
1961
|
*/
|
|
1962
1962
|
|
|
1963
|
-
const picomatch$
|
|
1963
|
+
const picomatch$4 = (glob, options, returnState = false) => {
|
|
1964
1964
|
if (Array.isArray(glob)) {
|
|
1965
|
-
const fns = glob.map(input => picomatch$
|
|
1965
|
+
const fns = glob.map(input => picomatch$4(input, options, returnState));
|
|
1966
1966
|
const arrayMatcher = str => {
|
|
1967
1967
|
for (const isMatch of fns) {
|
|
1968
1968
|
const state = isMatch(str);
|
|
@@ -1982,8 +1982,8 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
1982
1982
|
const opts = options || {};
|
|
1983
1983
|
const posix = utils$h.isWindows(options);
|
|
1984
1984
|
const regex = isState
|
|
1985
|
-
? picomatch$
|
|
1986
|
-
: picomatch$
|
|
1985
|
+
? picomatch$4.compileRe(glob, options)
|
|
1986
|
+
: picomatch$4.makeRe(glob, options, false, true);
|
|
1987
1987
|
|
|
1988
1988
|
const state = regex.state;
|
|
1989
1989
|
delete regex.state;
|
|
@@ -1991,11 +1991,11 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
1991
1991
|
let isIgnored = () => false;
|
|
1992
1992
|
if (opts.ignore) {
|
|
1993
1993
|
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1994
|
-
isIgnored = picomatch$
|
|
1994
|
+
isIgnored = picomatch$4(opts.ignore, ignoreOpts, returnState);
|
|
1995
1995
|
}
|
|
1996
1996
|
|
|
1997
1997
|
const matcher = (input, returnObject = false) => {
|
|
1998
|
-
const { isMatch, match, output } = picomatch$
|
|
1998
|
+
const { isMatch, match, output } = picomatch$4.test(input, regex, options, { glob, posix });
|
|
1999
1999
|
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
2000
2000
|
|
|
2001
2001
|
if (typeof opts.onResult === 'function') {
|
|
@@ -2045,7 +2045,7 @@ const picomatch$3 = (glob, options, returnState = false) => {
|
|
|
2045
2045
|
* @api public
|
|
2046
2046
|
*/
|
|
2047
2047
|
|
|
2048
|
-
picomatch$
|
|
2048
|
+
picomatch$4.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2049
2049
|
if (typeof input !== 'string') {
|
|
2050
2050
|
throw new TypeError('Expected input to be a string');
|
|
2051
2051
|
}
|
|
@@ -2066,7 +2066,7 @@ picomatch$3.test = (input, regex, options, { glob, posix } = {}) => {
|
|
|
2066
2066
|
|
|
2067
2067
|
if (match === false || opts.capture === true) {
|
|
2068
2068
|
if (opts.matchBase === true || opts.basename === true) {
|
|
2069
|
-
match = picomatch$
|
|
2069
|
+
match = picomatch$4.matchBase(input, regex, options, posix);
|
|
2070
2070
|
} else {
|
|
2071
2071
|
match = regex.exec(output);
|
|
2072
2072
|
}
|
|
@@ -2089,8 +2089,8 @@ picomatch$3.test = (input, regex, options, { glob, posix } = {}) => {
|
|
|
2089
2089
|
* @api public
|
|
2090
2090
|
*/
|
|
2091
2091
|
|
|
2092
|
-
picomatch$
|
|
2093
|
-
const regex = glob instanceof RegExp ? glob : picomatch$
|
|
2092
|
+
picomatch$4.matchBase = (input, glob, options, posix = utils$h.isWindows(options)) => {
|
|
2093
|
+
const regex = glob instanceof RegExp ? glob : picomatch$4.makeRe(glob, options);
|
|
2094
2094
|
return regex.test(path$l.basename(input));
|
|
2095
2095
|
};
|
|
2096
2096
|
|
|
@@ -2111,7 +2111,7 @@ picomatch$3.matchBase = (input, glob, options, posix = utils$h.isWindows(options
|
|
|
2111
2111
|
* @api public
|
|
2112
2112
|
*/
|
|
2113
2113
|
|
|
2114
|
-
picomatch$
|
|
2114
|
+
picomatch$4.isMatch = (str, patterns, options) => picomatch$4(patterns, options)(str);
|
|
2115
2115
|
|
|
2116
2116
|
/**
|
|
2117
2117
|
* Parse a glob pattern to create the source string for a regular
|
|
@@ -2127,8 +2127,8 @@ picomatch$3.isMatch = (str, patterns, options) => picomatch$3(patterns, options)
|
|
|
2127
2127
|
* @api public
|
|
2128
2128
|
*/
|
|
2129
2129
|
|
|
2130
|
-
picomatch$
|
|
2131
|
-
if (Array.isArray(pattern)) return pattern.map(p => picomatch$
|
|
2130
|
+
picomatch$4.parse = (pattern, options) => {
|
|
2131
|
+
if (Array.isArray(pattern)) return pattern.map(p => picomatch$4.parse(p, options));
|
|
2132
2132
|
return parse$i(pattern, { ...options, fastpaths: false });
|
|
2133
2133
|
};
|
|
2134
2134
|
|
|
@@ -2159,7 +2159,7 @@ picomatch$3.parse = (pattern, options) => {
|
|
|
2159
2159
|
* @api public
|
|
2160
2160
|
*/
|
|
2161
2161
|
|
|
2162
|
-
picomatch$
|
|
2162
|
+
picomatch$4.scan = (input, options) => scan$1(input, options);
|
|
2163
2163
|
|
|
2164
2164
|
/**
|
|
2165
2165
|
* Compile a regular expression from the `state` object returned by the
|
|
@@ -2173,7 +2173,7 @@ picomatch$3.scan = (input, options) => scan$1(input, options);
|
|
|
2173
2173
|
* @api public
|
|
2174
2174
|
*/
|
|
2175
2175
|
|
|
2176
|
-
picomatch$
|
|
2176
|
+
picomatch$4.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2177
2177
|
if (returnOutput === true) {
|
|
2178
2178
|
return state.output;
|
|
2179
2179
|
}
|
|
@@ -2187,7 +2187,7 @@ picomatch$3.compileRe = (state, options, returnOutput = false, returnState = fal
|
|
|
2187
2187
|
source = `^(?!${source}).*$`;
|
|
2188
2188
|
}
|
|
2189
2189
|
|
|
2190
|
-
const regex = picomatch$
|
|
2190
|
+
const regex = picomatch$4.toRegex(source, options);
|
|
2191
2191
|
if (returnState === true) {
|
|
2192
2192
|
regex.state = state;
|
|
2193
2193
|
}
|
|
@@ -2214,7 +2214,7 @@ picomatch$3.compileRe = (state, options, returnOutput = false, returnState = fal
|
|
|
2214
2214
|
* @api public
|
|
2215
2215
|
*/
|
|
2216
2216
|
|
|
2217
|
-
picomatch$
|
|
2217
|
+
picomatch$4.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2218
2218
|
if (!input || typeof input !== 'string') {
|
|
2219
2219
|
throw new TypeError('Expected a non-empty string');
|
|
2220
2220
|
}
|
|
@@ -2229,7 +2229,7 @@ picomatch$3.makeRe = (input, options = {}, returnOutput = false, returnState = f
|
|
|
2229
2229
|
parsed = parse$i(input, options);
|
|
2230
2230
|
}
|
|
2231
2231
|
|
|
2232
|
-
return picomatch$
|
|
2232
|
+
return picomatch$4.compileRe(parsed, options, returnOutput, returnState);
|
|
2233
2233
|
};
|
|
2234
2234
|
|
|
2235
2235
|
/**
|
|
@@ -2249,7 +2249,7 @@ picomatch$3.makeRe = (input, options = {}, returnOutput = false, returnState = f
|
|
|
2249
2249
|
* @api public
|
|
2250
2250
|
*/
|
|
2251
2251
|
|
|
2252
|
-
picomatch$
|
|
2252
|
+
picomatch$4.toRegex = (source, options) => {
|
|
2253
2253
|
try {
|
|
2254
2254
|
const opts = options || {};
|
|
2255
2255
|
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
|
@@ -2264,20 +2264,20 @@ picomatch$3.toRegex = (source, options) => {
|
|
|
2264
2264
|
* @return {Object}
|
|
2265
2265
|
*/
|
|
2266
2266
|
|
|
2267
|
-
picomatch$
|
|
2267
|
+
picomatch$4.constants = constants$4;
|
|
2268
2268
|
|
|
2269
2269
|
/**
|
|
2270
2270
|
* Expose "picomatch"
|
|
2271
2271
|
*/
|
|
2272
2272
|
|
|
2273
|
-
var picomatch_1 = picomatch$
|
|
2273
|
+
var picomatch_1 = picomatch$4;
|
|
2274
2274
|
|
|
2275
2275
|
(function (module) {
|
|
2276
2276
|
|
|
2277
2277
|
module.exports = picomatch_1;
|
|
2278
|
-
} (picomatch$
|
|
2278
|
+
} (picomatch$5));
|
|
2279
2279
|
|
|
2280
|
-
var
|
|
2280
|
+
var picomatch$3 = /*@__PURE__*/getDefaultExportFromCjs(picomatch$5.exports);
|
|
2281
2281
|
|
|
2282
2282
|
function walk$4(ast, { enter, leave }) {
|
|
2283
2283
|
return visit$2(ast, null, enter, leave);
|
|
@@ -2576,7 +2576,7 @@ const createFilter$2 = function createFilter(include, exclude, options) {
|
|
|
2576
2576
|
test: (what) => {
|
|
2577
2577
|
// this refactor is a tad overly verbose but makes for easy debugging
|
|
2578
2578
|
const pattern = getMatcherString$1(id, resolutionBase);
|
|
2579
|
-
const fn =
|
|
2579
|
+
const fn = picomatch$3(pattern, { dot: true });
|
|
2580
2580
|
const result = fn(what);
|
|
2581
2581
|
return result;
|
|
2582
2582
|
}
|
|
@@ -4327,7 +4327,7 @@ function ownProp (obj, field) {
|
|
|
4327
4327
|
var fs$i = require$$0__default;
|
|
4328
4328
|
var path$i = require$$0$4;
|
|
4329
4329
|
var minimatch = minimatch_1;
|
|
4330
|
-
var isAbsolute = pathIsAbsolute.exports;
|
|
4330
|
+
var isAbsolute$1 = pathIsAbsolute.exports;
|
|
4331
4331
|
var Minimatch = minimatch.Minimatch;
|
|
4332
4332
|
|
|
4333
4333
|
function alphasort (a, b) {
|
|
@@ -4415,7 +4415,7 @@ function setopts (self, pattern, options) {
|
|
|
4415
4415
|
|
|
4416
4416
|
// TODO: is an absolute `cwd` supposed to be resolved against `root`?
|
|
4417
4417
|
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
|
|
4418
|
-
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
|
|
4418
|
+
self.cwdAbs = isAbsolute$1(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
|
|
4419
4419
|
if (process.platform === "win32")
|
|
4420
4420
|
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
|
|
4421
4421
|
self.nomount = !!options.nomount;
|
|
@@ -4514,7 +4514,7 @@ function makeAbs (self, f) {
|
|
|
4514
4514
|
var abs = f;
|
|
4515
4515
|
if (f.charAt(0) === '/') {
|
|
4516
4516
|
abs = path$i.join(self.root, f);
|
|
4517
|
-
} else if (isAbsolute(f) || f === '') {
|
|
4517
|
+
} else if (isAbsolute$1(f) || f === '') {
|
|
4518
4518
|
abs = f;
|
|
4519
4519
|
} else if (self.changedCwd) {
|
|
4520
4520
|
abs = path$i.resolve(self.cwd, f);
|
|
@@ -11473,7 +11473,7 @@ const normalizePath$4 = function normalizePath(filename) {
|
|
|
11473
11473
|
};
|
|
11474
11474
|
|
|
11475
11475
|
function getMatcherString(id, resolutionBase) {
|
|
11476
|
-
if (resolutionBase === false || isAbsolute$
|
|
11476
|
+
if (resolutionBase === false || isAbsolute$2(id) || id.startsWith('*')) {
|
|
11477
11477
|
return normalizePath$4(id);
|
|
11478
11478
|
}
|
|
11479
11479
|
// resolve('') is valid and will default to process.cwd()
|
|
@@ -11494,7 +11494,7 @@ const createFilter$1 = function createFilter(include, exclude, options) {
|
|
|
11494
11494
|
test: (what) => {
|
|
11495
11495
|
// this refactor is a tad overly verbose but makes for easy debugging
|
|
11496
11496
|
const pattern = getMatcherString(id, resolutionBase);
|
|
11497
|
-
const fn =
|
|
11497
|
+
const fn = picomatch$3(pattern, { dot: true });
|
|
11498
11498
|
const result = fn(what);
|
|
11499
11499
|
return result;
|
|
11500
11500
|
}
|
|
@@ -11995,16 +11995,46 @@ function isFileReadable(filename) {
|
|
|
11995
11995
|
return false;
|
|
11996
11996
|
}
|
|
11997
11997
|
}
|
|
11998
|
+
const splitFirstDirRE = /(.+?)[\\/](.+)/;
|
|
11998
11999
|
/**
|
|
11999
12000
|
* Delete every file and subdirectory. **The given directory must exist.**
|
|
12000
|
-
* Pass an optional `skip` array to preserve files
|
|
12001
|
+
* Pass an optional `skip` array to preserve files under the root directory.
|
|
12001
12002
|
*/
|
|
12002
12003
|
function emptyDir(dir, skip) {
|
|
12004
|
+
const skipInDir = [];
|
|
12005
|
+
let nested = null;
|
|
12006
|
+
if (skip?.length) {
|
|
12007
|
+
for (const file of skip) {
|
|
12008
|
+
if (path$n.dirname(file) !== '.') {
|
|
12009
|
+
const matched = file.match(splitFirstDirRE);
|
|
12010
|
+
if (matched) {
|
|
12011
|
+
nested ?? (nested = new Map());
|
|
12012
|
+
const [, nestedDir, skipPath] = matched;
|
|
12013
|
+
let nestedSkip = nested.get(nestedDir);
|
|
12014
|
+
if (!nestedSkip) {
|
|
12015
|
+
nestedSkip = [];
|
|
12016
|
+
nested.set(nestedDir, nestedSkip);
|
|
12017
|
+
}
|
|
12018
|
+
if (!nestedSkip.includes(skipPath)) {
|
|
12019
|
+
nestedSkip.push(skipPath);
|
|
12020
|
+
}
|
|
12021
|
+
}
|
|
12022
|
+
}
|
|
12023
|
+
else {
|
|
12024
|
+
skipInDir.push(file);
|
|
12025
|
+
}
|
|
12026
|
+
}
|
|
12027
|
+
}
|
|
12003
12028
|
for (const file of fs$l.readdirSync(dir)) {
|
|
12004
|
-
if (
|
|
12029
|
+
if (skipInDir.includes(file)) {
|
|
12005
12030
|
continue;
|
|
12006
12031
|
}
|
|
12007
|
-
|
|
12032
|
+
if (nested?.has(file)) {
|
|
12033
|
+
emptyDir(path$n.resolve(dir, file), nested.get(file));
|
|
12034
|
+
}
|
|
12035
|
+
else {
|
|
12036
|
+
fs$l.rmSync(path$n.resolve(dir, file), { recursive: true, force: true });
|
|
12037
|
+
}
|
|
12008
12038
|
}
|
|
12009
12039
|
}
|
|
12010
12040
|
function copyDir(srcDir, destDir) {
|
|
@@ -13363,6 +13393,7 @@ function esbuildPlugin(options = {}) {
|
|
|
13363
13393
|
// Remove optimization options for dev as we only need to transpile them,
|
|
13364
13394
|
// and for build as the final optimization is in `buildEsbuildPlugin`
|
|
13365
13395
|
const transformOptions = {
|
|
13396
|
+
target: 'esnext',
|
|
13366
13397
|
...options,
|
|
13367
13398
|
minify: false,
|
|
13368
13399
|
minifyIdentifiers: false,
|
|
@@ -15502,7 +15533,7 @@ var braces_1 = braces$2;
|
|
|
15502
15533
|
|
|
15503
15534
|
const util$1 = require$$0$6;
|
|
15504
15535
|
const braces$1 = braces_1;
|
|
15505
|
-
const picomatch$2 = picomatch$
|
|
15536
|
+
const picomatch$2 = picomatch$5.exports;
|
|
15506
15537
|
const utils$b = utils$k;
|
|
15507
15538
|
const isEmptyString = val => val === '' || val === './';
|
|
15508
15539
|
|
|
@@ -26126,11 +26157,10 @@ class Chunk {
|
|
|
26126
26157
|
this.storeName = false;
|
|
26127
26158
|
this.edited = false;
|
|
26128
26159
|
|
|
26129
|
-
|
|
26130
|
-
|
|
26131
|
-
|
|
26132
|
-
|
|
26133
|
-
});
|
|
26160
|
+
{
|
|
26161
|
+
this.previous = null;
|
|
26162
|
+
this.next = null;
|
|
26163
|
+
}
|
|
26134
26164
|
}
|
|
26135
26165
|
|
|
26136
26166
|
appendLeft(content) {
|
|
@@ -27141,7 +27171,7 @@ class MagicString {
|
|
|
27141
27171
|
return this.original !== this.toString();
|
|
27142
27172
|
}
|
|
27143
27173
|
|
|
27144
|
-
|
|
27174
|
+
_replaceRegexp(searchValue, replacement) {
|
|
27145
27175
|
function getReplacement(match, str) {
|
|
27146
27176
|
if (typeof replacement === 'string') {
|
|
27147
27177
|
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
@@ -27164,7 +27194,7 @@ class MagicString {
|
|
|
27164
27194
|
}
|
|
27165
27195
|
return matches;
|
|
27166
27196
|
}
|
|
27167
|
-
if (
|
|
27197
|
+
if (searchValue.global) {
|
|
27168
27198
|
const matches = matchAll(searchValue, this.original);
|
|
27169
27199
|
matches.forEach((match) => {
|
|
27170
27200
|
if (match.index != null)
|
|
@@ -27185,6 +27215,53 @@ class MagicString {
|
|
|
27185
27215
|
}
|
|
27186
27216
|
return this;
|
|
27187
27217
|
}
|
|
27218
|
+
|
|
27219
|
+
_replaceString(string, replacement) {
|
|
27220
|
+
const { original } = this;
|
|
27221
|
+
const index = original.indexOf(string);
|
|
27222
|
+
|
|
27223
|
+
if (index !== -1) {
|
|
27224
|
+
this.overwrite(index, index + string.length, replacement);
|
|
27225
|
+
}
|
|
27226
|
+
|
|
27227
|
+
return this;
|
|
27228
|
+
}
|
|
27229
|
+
|
|
27230
|
+
replace(searchValue, replacement) {
|
|
27231
|
+
if (typeof searchValue === 'string') {
|
|
27232
|
+
return this._replaceString(searchValue, replacement);
|
|
27233
|
+
}
|
|
27234
|
+
|
|
27235
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
27236
|
+
}
|
|
27237
|
+
|
|
27238
|
+
_replaceAllString(string, replacement) {
|
|
27239
|
+
const { original } = this;
|
|
27240
|
+
const stringLength = string.length;
|
|
27241
|
+
for (
|
|
27242
|
+
let index = original.indexOf(string);
|
|
27243
|
+
index !== -1;
|
|
27244
|
+
index = original.indexOf(string, index + stringLength)
|
|
27245
|
+
) {
|
|
27246
|
+
this.overwrite(index, index + stringLength, replacement);
|
|
27247
|
+
}
|
|
27248
|
+
|
|
27249
|
+
return this;
|
|
27250
|
+
}
|
|
27251
|
+
|
|
27252
|
+
replaceAll(searchValue, replacement) {
|
|
27253
|
+
if (typeof searchValue === 'string') {
|
|
27254
|
+
return this._replaceAllString(searchValue, replacement);
|
|
27255
|
+
}
|
|
27256
|
+
|
|
27257
|
+
if (!searchValue.global) {
|
|
27258
|
+
throw new TypeError(
|
|
27259
|
+
'MagicString.prototype.replaceAll called with a non-global RegExp argument'
|
|
27260
|
+
);
|
|
27261
|
+
}
|
|
27262
|
+
|
|
27263
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
27264
|
+
}
|
|
27188
27265
|
}
|
|
27189
27266
|
|
|
27190
27267
|
const isDebug$6 = !!process.env.DEBUG;
|
|
@@ -32874,7 +32951,7 @@ function stripLiteralAcorn(code) {
|
|
|
32874
32951
|
}
|
|
32875
32952
|
|
|
32876
32953
|
const multilineCommentsRE = /\/\*.*?\*\//gms;
|
|
32877
|
-
const singlelineCommentsRE =
|
|
32954
|
+
const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm;
|
|
32878
32955
|
const templateLiteralRE = /\$\{(\s*(?:(?!\$\{).|\n|\r)*?\s*)\}/g;
|
|
32879
32956
|
const quotesRE = [
|
|
32880
32957
|
/(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm,
|
|
@@ -33322,6 +33399,7 @@ function lookup(extn) {
|
|
|
33322
33399
|
}
|
|
33323
33400
|
|
|
33324
33401
|
const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g;
|
|
33402
|
+
const duplicateAssets = new WeakMap();
|
|
33325
33403
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
33326
33404
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
33327
33405
|
const assetCache = new WeakMap();
|
|
@@ -33340,6 +33418,7 @@ function registerCustomMime() {
|
|
|
33340
33418
|
mimes$1['eot'] = 'application/vnd.ms-fontobject';
|
|
33341
33419
|
}
|
|
33342
33420
|
function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
33421
|
+
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(opts.format);
|
|
33343
33422
|
let match;
|
|
33344
33423
|
let s;
|
|
33345
33424
|
// Urls added with JS using e.g.
|
|
@@ -33355,7 +33434,7 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
|
33355
33434
|
const file = getAssetFilename(hash, config) || ctx.getFileName(hash);
|
|
33356
33435
|
chunk.viteMetadata.importedAssets.add(cleanUrl(file));
|
|
33357
33436
|
const filename = file + postfix;
|
|
33358
|
-
const replacement =
|
|
33437
|
+
const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
33359
33438
|
const replacementString = typeof replacement === 'string'
|
|
33360
33439
|
? JSON.stringify(replacement).slice(1, -1)
|
|
33361
33440
|
: `"+${replacement.runtime}+"`;
|
|
@@ -33369,7 +33448,7 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
|
|
|
33369
33448
|
s || (s = new MagicString(code));
|
|
33370
33449
|
const [full, hash] = match;
|
|
33371
33450
|
const publicUrl = publicAssetUrlMap.get(hash).slice(1);
|
|
33372
|
-
const replacement =
|
|
33451
|
+
const replacement = toOutputFilePathInJS(publicUrl, 'public', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
33373
33452
|
const replacementString = typeof replacement === 'string'
|
|
33374
33453
|
? JSON.stringify(replacement).slice(1, -1)
|
|
33375
33454
|
: `"+${replacement.runtime}+"`;
|
|
@@ -33391,6 +33470,7 @@ function assetPlugin(config) {
|
|
|
33391
33470
|
buildStart() {
|
|
33392
33471
|
assetCache.set(config, new Map());
|
|
33393
33472
|
emittedHashMap.set(config, new Set());
|
|
33473
|
+
duplicateAssets.set(config, new Map());
|
|
33394
33474
|
},
|
|
33395
33475
|
resolveId(id) {
|
|
33396
33476
|
if (!config.assetsInclude(cleanUrl(id))) {
|
|
@@ -33650,8 +33730,9 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
|
33650
33730
|
map.set(contentHash, fileName);
|
|
33651
33731
|
}
|
|
33652
33732
|
const emittedSet = emittedHashMap.get(config);
|
|
33733
|
+
const duplicates = duplicateAssets.get(config);
|
|
33734
|
+
const name = normalizePath$3(path$n.relative(config.root, file));
|
|
33653
33735
|
if (!emittedSet.has(contentHash)) {
|
|
33654
|
-
const name = normalizePath$3(path$n.relative(config.root, file));
|
|
33655
33736
|
pluginContext.emitFile({
|
|
33656
33737
|
name,
|
|
33657
33738
|
fileName,
|
|
@@ -33660,6 +33741,15 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
|
|
|
33660
33741
|
});
|
|
33661
33742
|
emittedSet.add(contentHash);
|
|
33662
33743
|
}
|
|
33744
|
+
else {
|
|
33745
|
+
duplicates.set(name, {
|
|
33746
|
+
name,
|
|
33747
|
+
fileName: map.get(contentHash),
|
|
33748
|
+
type: 'asset',
|
|
33749
|
+
source: content,
|
|
33750
|
+
isAsset: true
|
|
33751
|
+
});
|
|
33752
|
+
}
|
|
33663
33753
|
url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
|
|
33664
33754
|
}
|
|
33665
33755
|
cache.set(id, url);
|
|
@@ -34183,6 +34273,284 @@ function watchPackageDataPlugin(config) {
|
|
|
34183
34273
|
};
|
|
34184
34274
|
}
|
|
34185
34275
|
|
|
34276
|
+
const WORKER_FILE_ID = 'worker_file';
|
|
34277
|
+
const workerCache = new WeakMap();
|
|
34278
|
+
function isWorkerRequest(id) {
|
|
34279
|
+
const query = parseRequest(id);
|
|
34280
|
+
if (query && query[WORKER_FILE_ID] != null) {
|
|
34281
|
+
return true;
|
|
34282
|
+
}
|
|
34283
|
+
return false;
|
|
34284
|
+
}
|
|
34285
|
+
function saveEmitWorkerAsset(config, asset) {
|
|
34286
|
+
const fileName = asset.fileName;
|
|
34287
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34288
|
+
workerMap.assets.set(fileName, asset);
|
|
34289
|
+
}
|
|
34290
|
+
async function bundleWorkerEntry(config, id, query) {
|
|
34291
|
+
// bundle the file as entry to support imports
|
|
34292
|
+
const { rollup } = await import('rollup');
|
|
34293
|
+
const { plugins, rollupOptions, format } = config.worker;
|
|
34294
|
+
const bundle = await rollup({
|
|
34295
|
+
...rollupOptions,
|
|
34296
|
+
input: cleanUrl(id),
|
|
34297
|
+
plugins,
|
|
34298
|
+
onwarn(warning, warn) {
|
|
34299
|
+
onRollupWarning(warning, warn, config);
|
|
34300
|
+
},
|
|
34301
|
+
preserveEntrySignatures: false
|
|
34302
|
+
});
|
|
34303
|
+
let chunk;
|
|
34304
|
+
try {
|
|
34305
|
+
const workerOutputConfig = config.worker.rollupOptions.output;
|
|
34306
|
+
const workerConfig = workerOutputConfig
|
|
34307
|
+
? Array.isArray(workerOutputConfig)
|
|
34308
|
+
? workerOutputConfig[0] || {}
|
|
34309
|
+
: workerOutputConfig
|
|
34310
|
+
: {};
|
|
34311
|
+
const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
|
|
34312
|
+
entryFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
34313
|
+
chunkFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
34314
|
+
assetFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].[ext]'),
|
|
34315
|
+
...workerConfig,
|
|
34316
|
+
format,
|
|
34317
|
+
sourcemap: config.build.sourcemap
|
|
34318
|
+
});
|
|
34319
|
+
chunk = outputChunk;
|
|
34320
|
+
outputChunks.forEach((outputChunk) => {
|
|
34321
|
+
if (outputChunk.type === 'asset') {
|
|
34322
|
+
saveEmitWorkerAsset(config, outputChunk);
|
|
34323
|
+
}
|
|
34324
|
+
else if (outputChunk.type === 'chunk') {
|
|
34325
|
+
saveEmitWorkerAsset(config, {
|
|
34326
|
+
fileName: outputChunk.fileName,
|
|
34327
|
+
source: outputChunk.code,
|
|
34328
|
+
type: 'asset'
|
|
34329
|
+
});
|
|
34330
|
+
}
|
|
34331
|
+
});
|
|
34332
|
+
}
|
|
34333
|
+
finally {
|
|
34334
|
+
await bundle.close();
|
|
34335
|
+
}
|
|
34336
|
+
return emitSourcemapForWorkerEntry(config, query, chunk);
|
|
34337
|
+
}
|
|
34338
|
+
function emitSourcemapForWorkerEntry(config, query, chunk) {
|
|
34339
|
+
const { map: sourcemap } = chunk;
|
|
34340
|
+
if (sourcemap) {
|
|
34341
|
+
if (config.build.sourcemap === 'inline') {
|
|
34342
|
+
// Manually add the sourcemap to the code if configured for inline sourcemaps.
|
|
34343
|
+
// TODO: Remove when https://github.com/rollup/rollup/issues/3913 is resolved
|
|
34344
|
+
// Currently seems that it won't be resolved until Rollup 3
|
|
34345
|
+
const dataUrl = sourcemap.toUrl();
|
|
34346
|
+
chunk.code += `//# sourceMappingURL=${dataUrl}`;
|
|
34347
|
+
}
|
|
34348
|
+
else if (config.build.sourcemap === 'hidden' ||
|
|
34349
|
+
config.build.sourcemap === true) {
|
|
34350
|
+
const data = sourcemap.toString();
|
|
34351
|
+
const mapFileName = chunk.fileName + '.map';
|
|
34352
|
+
saveEmitWorkerAsset(config, {
|
|
34353
|
+
fileName: mapFileName,
|
|
34354
|
+
type: 'asset',
|
|
34355
|
+
source: data
|
|
34356
|
+
});
|
|
34357
|
+
// Emit the comment that tells the JS debugger where it can find the
|
|
34358
|
+
// sourcemap file.
|
|
34359
|
+
// 'hidden' causes the sourcemap file to be created but
|
|
34360
|
+
// the comment in the file to be omitted.
|
|
34361
|
+
if (config.build.sourcemap === true) {
|
|
34362
|
+
// inline web workers need to use the full sourcemap path
|
|
34363
|
+
// non-inline web workers can use a relative path
|
|
34364
|
+
const sourceMapUrl = query?.inline != null
|
|
34365
|
+
? mapFileName
|
|
34366
|
+
: path$n.relative(config.build.assetsDir, mapFileName);
|
|
34367
|
+
chunk.code += `//# sourceMappingURL=${sourceMapUrl}`;
|
|
34368
|
+
}
|
|
34369
|
+
}
|
|
34370
|
+
}
|
|
34371
|
+
return chunk;
|
|
34372
|
+
}
|
|
34373
|
+
const workerAssetUrlRE = /__VITE_WORKER_ASSET__([a-z\d]{8})__/g;
|
|
34374
|
+
function encodeWorkerAssetFileName(fileName, workerCache) {
|
|
34375
|
+
const { fileNameHash } = workerCache;
|
|
34376
|
+
const hash = getHash(fileName);
|
|
34377
|
+
if (!fileNameHash.get(hash)) {
|
|
34378
|
+
fileNameHash.set(hash, fileName);
|
|
34379
|
+
}
|
|
34380
|
+
return `__VITE_WORKER_ASSET__${hash}__`;
|
|
34381
|
+
}
|
|
34382
|
+
async function workerFileToUrl(config, id, query) {
|
|
34383
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34384
|
+
let fileName = workerMap.bundle.get(id);
|
|
34385
|
+
if (!fileName) {
|
|
34386
|
+
const outputChunk = await bundleWorkerEntry(config, id, query);
|
|
34387
|
+
fileName = outputChunk.fileName;
|
|
34388
|
+
saveEmitWorkerAsset(config, {
|
|
34389
|
+
fileName,
|
|
34390
|
+
source: outputChunk.code,
|
|
34391
|
+
type: 'asset'
|
|
34392
|
+
});
|
|
34393
|
+
workerMap.bundle.set(id, fileName);
|
|
34394
|
+
}
|
|
34395
|
+
return encodeWorkerAssetFileName(fileName, workerMap);
|
|
34396
|
+
}
|
|
34397
|
+
function webWorkerPlugin(config) {
|
|
34398
|
+
const isBuild = config.command === 'build';
|
|
34399
|
+
let server;
|
|
34400
|
+
const isWorker = config.isWorker;
|
|
34401
|
+
return {
|
|
34402
|
+
name: 'vite:worker',
|
|
34403
|
+
configureServer(_server) {
|
|
34404
|
+
server = _server;
|
|
34405
|
+
},
|
|
34406
|
+
buildStart() {
|
|
34407
|
+
if (isWorker) {
|
|
34408
|
+
return;
|
|
34409
|
+
}
|
|
34410
|
+
workerCache.set(config, {
|
|
34411
|
+
assets: new Map(),
|
|
34412
|
+
bundle: new Map(),
|
|
34413
|
+
fileNameHash: new Map()
|
|
34414
|
+
});
|
|
34415
|
+
},
|
|
34416
|
+
load(id) {
|
|
34417
|
+
if (isBuild) {
|
|
34418
|
+
const parsedQuery = parseRequest(id);
|
|
34419
|
+
if (parsedQuery &&
|
|
34420
|
+
(parsedQuery.worker ?? parsedQuery.sharedworker) != null) {
|
|
34421
|
+
return '';
|
|
34422
|
+
}
|
|
34423
|
+
}
|
|
34424
|
+
},
|
|
34425
|
+
async transform(raw, id, options) {
|
|
34426
|
+
const ssr = options?.ssr === true;
|
|
34427
|
+
const query = parseRequest(id);
|
|
34428
|
+
if (query && query[WORKER_FILE_ID] != null) {
|
|
34429
|
+
// if import worker by worker constructor will have query.type
|
|
34430
|
+
// other type will be import worker by esm
|
|
34431
|
+
const workerType = query['type'];
|
|
34432
|
+
let injectEnv = '';
|
|
34433
|
+
if (workerType === 'classic') {
|
|
34434
|
+
injectEnv = `importScripts('${ENV_PUBLIC_PATH}')\n`;
|
|
34435
|
+
}
|
|
34436
|
+
else if (workerType === 'module') {
|
|
34437
|
+
injectEnv = `import '${ENV_PUBLIC_PATH}'\n`;
|
|
34438
|
+
}
|
|
34439
|
+
else if (workerType === 'ignore') {
|
|
34440
|
+
if (isBuild) {
|
|
34441
|
+
injectEnv = '';
|
|
34442
|
+
}
|
|
34443
|
+
else if (server) {
|
|
34444
|
+
// dynamic worker type we can't know how import the env
|
|
34445
|
+
// so we copy /@vite/env code of server transform result into file header
|
|
34446
|
+
const { moduleGraph } = server;
|
|
34447
|
+
const module = moduleGraph.getModuleById(ENV_ENTRY);
|
|
34448
|
+
injectEnv = module?.transformResult?.code || '';
|
|
34449
|
+
}
|
|
34450
|
+
}
|
|
34451
|
+
return {
|
|
34452
|
+
code: injectEnv + raw
|
|
34453
|
+
};
|
|
34454
|
+
}
|
|
34455
|
+
if (query == null ||
|
|
34456
|
+
(query && (query.worker ?? query.sharedworker) == null)) {
|
|
34457
|
+
return;
|
|
34458
|
+
}
|
|
34459
|
+
// stringified url or `new URL(...)`
|
|
34460
|
+
let url;
|
|
34461
|
+
const { format } = config.worker;
|
|
34462
|
+
const workerConstructor = query.sharedworker != null ? 'SharedWorker' : 'Worker';
|
|
34463
|
+
const workerType = isBuild
|
|
34464
|
+
? format === 'es'
|
|
34465
|
+
? 'module'
|
|
34466
|
+
: 'classic'
|
|
34467
|
+
: 'module';
|
|
34468
|
+
const workerOptions = workerType === 'classic' ? '' : ',{type: "module"}';
|
|
34469
|
+
if (isBuild) {
|
|
34470
|
+
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
34471
|
+
if (query.inline != null) {
|
|
34472
|
+
const chunk = await bundleWorkerEntry(config, id, query);
|
|
34473
|
+
// inline as blob data url
|
|
34474
|
+
return {
|
|
34475
|
+
code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
|
|
34476
|
+
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
|
|
34477
|
+
export default function WorkerWrapper() {
|
|
34478
|
+
const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
|
|
34479
|
+
try {
|
|
34480
|
+
return objURL ? new ${workerConstructor}(objURL) : new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
|
|
34481
|
+
} finally {
|
|
34482
|
+
objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
|
|
34483
|
+
}
|
|
34484
|
+
}`,
|
|
34485
|
+
// Empty sourcemap to suppress Rollup warning
|
|
34486
|
+
map: { mappings: '' }
|
|
34487
|
+
};
|
|
34488
|
+
}
|
|
34489
|
+
else {
|
|
34490
|
+
url = await workerFileToUrl(config, id, query);
|
|
34491
|
+
}
|
|
34492
|
+
}
|
|
34493
|
+
else {
|
|
34494
|
+
url = await fileToUrl(cleanUrl(id), config, this);
|
|
34495
|
+
url = injectQuery(url, WORKER_FILE_ID);
|
|
34496
|
+
url = injectQuery(url, `type=${workerType}`);
|
|
34497
|
+
}
|
|
34498
|
+
if (query.url != null) {
|
|
34499
|
+
return {
|
|
34500
|
+
code: `export default ${JSON.stringify(url)}`,
|
|
34501
|
+
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
34502
|
+
};
|
|
34503
|
+
}
|
|
34504
|
+
return {
|
|
34505
|
+
code: `export default function WorkerWrapper() {
|
|
34506
|
+
return new ${workerConstructor}(${JSON.stringify(url)}${workerOptions})
|
|
34507
|
+
}`,
|
|
34508
|
+
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
34509
|
+
};
|
|
34510
|
+
},
|
|
34511
|
+
renderChunk(code, chunk, outputOptions) {
|
|
34512
|
+
let s;
|
|
34513
|
+
const result = () => {
|
|
34514
|
+
return (s && {
|
|
34515
|
+
code: s.toString(),
|
|
34516
|
+
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
34517
|
+
});
|
|
34518
|
+
};
|
|
34519
|
+
if (code.match(workerAssetUrlRE) || code.includes('import.meta.url')) {
|
|
34520
|
+
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format);
|
|
34521
|
+
let match;
|
|
34522
|
+
s = new MagicString(code);
|
|
34523
|
+
// Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
|
|
34524
|
+
const workerMap = workerCache.get(config.mainConfig || config);
|
|
34525
|
+
const { fileNameHash } = workerMap;
|
|
34526
|
+
while ((match = workerAssetUrlRE.exec(code))) {
|
|
34527
|
+
const [full, hash] = match;
|
|
34528
|
+
const filename = fileNameHash.get(hash);
|
|
34529
|
+
const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
|
|
34530
|
+
const replacementString = typeof replacement === 'string'
|
|
34531
|
+
? JSON.stringify(replacement).slice(1, -1)
|
|
34532
|
+
: `"+${replacement.runtime}+"`;
|
|
34533
|
+
s.overwrite(match.index, match.index + full.length, replacementString, {
|
|
34534
|
+
contentOnly: true
|
|
34535
|
+
});
|
|
34536
|
+
}
|
|
34537
|
+
}
|
|
34538
|
+
return result();
|
|
34539
|
+
},
|
|
34540
|
+
generateBundle(opts) {
|
|
34541
|
+
// @ts-ignore asset emits are skipped in legacy bundle
|
|
34542
|
+
if (opts.__vite_skip_asset_emit__ || isWorker) {
|
|
34543
|
+
return;
|
|
34544
|
+
}
|
|
34545
|
+
const workerMap = workerCache.get(config);
|
|
34546
|
+
workerMap.assets.forEach((asset) => {
|
|
34547
|
+
this.emitFile(asset);
|
|
34548
|
+
workerMap.assets.delete(asset.fileName);
|
|
34549
|
+
});
|
|
34550
|
+
}
|
|
34551
|
+
};
|
|
34552
|
+
}
|
|
34553
|
+
|
|
34186
34554
|
const normalizedClientEntry$1 = normalizePath$3(CLIENT_ENTRY);
|
|
34187
34555
|
const normalizedEnvEntry$1 = normalizePath$3(ENV_ENTRY);
|
|
34188
34556
|
// special id for paths marked with browser: false
|
|
@@ -34217,12 +34585,15 @@ function resolvePlugin(resolveOptions) {
|
|
|
34217
34585
|
scan: resolveOpts?.scan ?? resolveOptions.scan
|
|
34218
34586
|
};
|
|
34219
34587
|
if (importer) {
|
|
34220
|
-
|
|
34588
|
+
const _importer = isWorkerRequest(importer)
|
|
34589
|
+
? splitFileAndPostfix(importer).file
|
|
34590
|
+
: importer;
|
|
34591
|
+
if (isTsRequest(_importer) ||
|
|
34221
34592
|
resolveOpts.custom?.depScan?.loader?.startsWith('ts')) {
|
|
34222
34593
|
options.isFromTsImporter = true;
|
|
34223
34594
|
}
|
|
34224
34595
|
else {
|
|
34225
|
-
const moduleLang = this.getModuleInfo(
|
|
34596
|
+
const moduleLang = this.getModuleInfo(_importer)?.meta?.vite?.lang;
|
|
34226
34597
|
options.isFromTsImporter = moduleLang && isTsRequest(`.${moduleLang}`);
|
|
34227
34598
|
}
|
|
34228
34599
|
}
|
|
@@ -34293,6 +34664,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
34293
34664
|
return normalizedFsPath;
|
|
34294
34665
|
}
|
|
34295
34666
|
if (targetWeb &&
|
|
34667
|
+
options.browserField &&
|
|
34296
34668
|
(res = tryResolveBrowserMapping(fsPath, importer, options, true))) {
|
|
34297
34669
|
return res;
|
|
34298
34670
|
}
|
|
@@ -34350,6 +34722,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
34350
34722
|
return res;
|
|
34351
34723
|
}
|
|
34352
34724
|
if (targetWeb &&
|
|
34725
|
+
options.browserField &&
|
|
34353
34726
|
(res = tryResolveBrowserMapping(id, importer, options, false, external))) {
|
|
34354
34727
|
return res;
|
|
34355
34728
|
}
|
|
@@ -34437,7 +34810,7 @@ function tryFsResolve(fsPath, options, tryIndex = true, targetWeb = true) {
|
|
|
34437
34810
|
if ((res = tryResolveFile(file, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
34438
34811
|
return res;
|
|
34439
34812
|
}
|
|
34440
|
-
for (const ext of options.extensions
|
|
34813
|
+
for (const ext of options.extensions) {
|
|
34441
34814
|
if (postfix &&
|
|
34442
34815
|
(res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
34443
34816
|
return res;
|
|
@@ -34617,7 +34990,9 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
|
|
|
34617
34990
|
let resolvedId = id;
|
|
34618
34991
|
if (isDeepImport) {
|
|
34619
34992
|
if (!pkg?.data.exports && path$n.extname(id) !== resolvedExt) {
|
|
34620
|
-
resolvedId
|
|
34993
|
+
resolvedId = resolved.id.slice(resolved.id.indexOf(id));
|
|
34994
|
+
isDebug$4 &&
|
|
34995
|
+
debug$c(`[processResult] ${picocolors.exports.cyan(id)} -> ${picocolors.exports.dim(resolvedId)}`);
|
|
34621
34996
|
}
|
|
34622
34997
|
}
|
|
34623
34998
|
return { ...resolved, id: resolvedId, external: true };
|
|
@@ -34758,7 +35133,9 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34758
35133
|
// This is because .mjs files can technically import .cjs files which would
|
|
34759
35134
|
// make them invalid for pure ESM environments - so if other module/browser
|
|
34760
35135
|
// fields are present, prioritize those instead.
|
|
34761
|
-
if (targetWeb &&
|
|
35136
|
+
if (targetWeb &&
|
|
35137
|
+
options.browserField &&
|
|
35138
|
+
(!entryPoint || entryPoint.endsWith('.mjs'))) {
|
|
34762
35139
|
// check browser field
|
|
34763
35140
|
// https://github.com/defunctzombie/package-browser-field-spec
|
|
34764
35141
|
const browserEntry = typeof data.browser === 'string'
|
|
@@ -34767,6 +35144,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34767
35144
|
if (browserEntry) {
|
|
34768
35145
|
// check if the package also has a "module" field.
|
|
34769
35146
|
if (!options.isRequire &&
|
|
35147
|
+
options.mainFields.includes('module') &&
|
|
34770
35148
|
typeof data.module === 'string' &&
|
|
34771
35149
|
data.module !== browserEntry) {
|
|
34772
35150
|
// if both are present, we may have a problem: some package points both
|
|
@@ -34794,7 +35172,9 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34794
35172
|
}
|
|
34795
35173
|
}
|
|
34796
35174
|
if (!entryPoint || entryPoint.endsWith('.mjs')) {
|
|
34797
|
-
for (const field of options.mainFields
|
|
35175
|
+
for (const field of options.mainFields) {
|
|
35176
|
+
if (field === 'browser')
|
|
35177
|
+
continue; // already checked above
|
|
34798
35178
|
if (typeof data[field] === 'string') {
|
|
34799
35179
|
entryPoint = data[field];
|
|
34800
35180
|
break;
|
|
@@ -34809,14 +35189,14 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
34809
35189
|
: ['index.js', 'index.json', 'index.node'];
|
|
34810
35190
|
for (let entry of entryPoints) {
|
|
34811
35191
|
// make sure we don't get scripts when looking for sass
|
|
34812
|
-
if (options.mainFields
|
|
34813
|
-
!options.extensions
|
|
35192
|
+
if (options.mainFields[0] === 'sass' &&
|
|
35193
|
+
!options.extensions.includes(path$n.extname(entry))) {
|
|
34814
35194
|
entry = '';
|
|
34815
35195
|
options.skipPackageJson = true;
|
|
34816
35196
|
}
|
|
34817
35197
|
// resolve object browser field in package.json
|
|
34818
35198
|
const { browser: browserField } = data;
|
|
34819
|
-
if (targetWeb && isObject$2(browserField)) {
|
|
35199
|
+
if (targetWeb && options.browserField && isObject$2(browserField)) {
|
|
34820
35200
|
entry = mapWithBrowserField(entry, browserField) || entry;
|
|
34821
35201
|
}
|
|
34822
35202
|
const entryPointPath = path$n.join(dir, entry);
|
|
@@ -34844,12 +35224,12 @@ function resolveExports(pkg, key, options, targetWeb) {
|
|
|
34844
35224
|
if (!options.isRequire) {
|
|
34845
35225
|
conditions.push('module');
|
|
34846
35226
|
}
|
|
34847
|
-
if (options.conditions) {
|
|
35227
|
+
if (options.conditions.length > 0) {
|
|
34848
35228
|
conditions.push(...options.conditions);
|
|
34849
35229
|
}
|
|
34850
35230
|
return resolve(pkg, key, {
|
|
34851
|
-
browser: targetWeb,
|
|
34852
|
-
require: options.isRequire,
|
|
35231
|
+
browser: targetWeb && !conditions.includes('node'),
|
|
35232
|
+
require: options.isRequire && !conditions.includes('import'),
|
|
34853
35233
|
conditions
|
|
34854
35234
|
});
|
|
34855
35235
|
}
|
|
@@ -34882,7 +35262,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
34882
35262
|
`${path$n.join(dir, 'package.json')}.`);
|
|
34883
35263
|
}
|
|
34884
35264
|
}
|
|
34885
|
-
else if (targetWeb && isObject$2(browserField)) {
|
|
35265
|
+
else if (targetWeb && options.browserField && isObject$2(browserField)) {
|
|
34886
35266
|
// resolve without postfix (see #7098)
|
|
34887
35267
|
const { file, postfix } = splitFileAndPostfix(relativeId);
|
|
34888
35268
|
const mapped = mapWithBrowserField(file, browserField);
|
|
@@ -34906,7 +35286,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
34906
35286
|
}
|
|
34907
35287
|
function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize) {
|
|
34908
35288
|
let res;
|
|
34909
|
-
const pkg = importer && idToPkgMap.get(importer);
|
|
35289
|
+
const pkg = importer && (idToPkgMap.get(importer) || resolvePkg(importer, options));
|
|
34910
35290
|
if (pkg && isObject$2(pkg.data.browser)) {
|
|
34911
35291
|
const mapId = isFilePath ? './' + slash$1(path$n.relative(pkg.dir, id)) : id;
|
|
34912
35292
|
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
|
|
@@ -34957,6 +35337,36 @@ function getRealPath(resolved, preserveSymlinks) {
|
|
|
34957
35337
|
}
|
|
34958
35338
|
return normalizePath$3(resolved);
|
|
34959
35339
|
}
|
|
35340
|
+
/**
|
|
35341
|
+
* if importer was not resolved by vite's resolver previously
|
|
35342
|
+
* (when esbuild resolved it)
|
|
35343
|
+
* resolve importer's pkg and add to idToPkgMap
|
|
35344
|
+
*/
|
|
35345
|
+
function resolvePkg(importer, options) {
|
|
35346
|
+
const { root, preserveSymlinks, packageCache } = options;
|
|
35347
|
+
if (importer.includes('\x00')) {
|
|
35348
|
+
return null;
|
|
35349
|
+
}
|
|
35350
|
+
const possiblePkgIds = [];
|
|
35351
|
+
for (let prevSlashIndex = -1;;) {
|
|
35352
|
+
const slashIndex = importer.indexOf(isWindows$4 ? '\\' : '/', prevSlashIndex);
|
|
35353
|
+
if (slashIndex < 0) {
|
|
35354
|
+
break;
|
|
35355
|
+
}
|
|
35356
|
+
prevSlashIndex = slashIndex + 1;
|
|
35357
|
+
const possiblePkgId = importer.slice(0, slashIndex);
|
|
35358
|
+
possiblePkgIds.push(possiblePkgId);
|
|
35359
|
+
}
|
|
35360
|
+
let pkg;
|
|
35361
|
+
possiblePkgIds.reverse().find((pkgId) => {
|
|
35362
|
+
pkg = resolvePackageData(pkgId, root, preserveSymlinks, packageCache);
|
|
35363
|
+
return pkg;
|
|
35364
|
+
});
|
|
35365
|
+
if (pkg) {
|
|
35366
|
+
idToPkgMap.set(importer, pkg);
|
|
35367
|
+
}
|
|
35368
|
+
return pkg;
|
|
35369
|
+
}
|
|
34960
35370
|
|
|
34961
35371
|
const externalWithConversionNamespace = 'vite:dep-pre-bundle:external-conversion';
|
|
34962
35372
|
const convertedExternalPrefix = 'vite-dep-pre-bundle-external:';
|
|
@@ -35253,7 +35663,7 @@ function cjsSsrResolveExternals(config, knownImports) {
|
|
|
35253
35663
|
ssrExternals.add(id);
|
|
35254
35664
|
seen.add(id);
|
|
35255
35665
|
});
|
|
35256
|
-
cjsSsrCollectExternals(config.root, config.resolve
|
|
35666
|
+
cjsSsrCollectExternals(config.root, config.resolve, ssrExternals, seen, config.logger);
|
|
35257
35667
|
const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
|
|
35258
35668
|
for (const dep of importedDeps) {
|
|
35259
35669
|
// Assume external if not yet seen
|
|
@@ -35291,8 +35701,8 @@ function createIsConfiguredAsSsrExternal(config) {
|
|
|
35291
35701
|
typeof noExternal !== 'boolean' &&
|
|
35292
35702
|
createFilter(undefined, noExternal, { resolve: false });
|
|
35293
35703
|
const resolveOptions = {
|
|
35704
|
+
...config.resolve,
|
|
35294
35705
|
root,
|
|
35295
|
-
preserveSymlinks: config.resolve.preserveSymlinks,
|
|
35296
35706
|
isProduction: false,
|
|
35297
35707
|
isBuild: true
|
|
35298
35708
|
};
|
|
@@ -35363,7 +35773,7 @@ function createIsSsrExternal(config) {
|
|
|
35363
35773
|
}
|
|
35364
35774
|
// When config.experimental.buildSsrCjsExternalHeuristics is enabled, this function
|
|
35365
35775
|
// is used reverting to the Vite 2.9 SSR externalization heuristics
|
|
35366
|
-
function cjsSsrCollectExternals(root,
|
|
35776
|
+
function cjsSsrCollectExternals(root, resolveOptions, ssrExternals, seen, logger) {
|
|
35367
35777
|
const rootPkgContent = lookupFile(root, ['package.json']);
|
|
35368
35778
|
if (!rootPkgContent) {
|
|
35369
35779
|
return;
|
|
@@ -35373,9 +35783,9 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35373
35783
|
...rootPkg.devDependencies,
|
|
35374
35784
|
...rootPkg.dependencies
|
|
35375
35785
|
};
|
|
35376
|
-
const
|
|
35786
|
+
const internalResolveOptions = {
|
|
35787
|
+
...resolveOptions,
|
|
35377
35788
|
root,
|
|
35378
|
-
preserveSymlinks,
|
|
35379
35789
|
isProduction: false,
|
|
35380
35790
|
isBuild: true
|
|
35381
35791
|
};
|
|
@@ -35387,7 +35797,7 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35387
35797
|
let esmEntry;
|
|
35388
35798
|
let requireEntry;
|
|
35389
35799
|
try {
|
|
35390
|
-
esmEntry = tryNodeResolve(id, undefined,
|
|
35800
|
+
esmEntry = tryNodeResolve(id, undefined, internalResolveOptions, true, // we set `targetWeb` to `true` to get the ESM entry
|
|
35391
35801
|
undefined, true)?.id;
|
|
35392
35802
|
// normalizePath required for windows. tryNodeResolve uses normalizePath
|
|
35393
35803
|
// which returns with '/', require.resolve returns with '\\'
|
|
@@ -35447,7 +35857,7 @@ function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logg
|
|
|
35447
35857
|
}
|
|
35448
35858
|
}
|
|
35449
35859
|
for (const depRoot of depsToTrace) {
|
|
35450
|
-
cjsSsrCollectExternals(depRoot,
|
|
35860
|
+
cjsSsrCollectExternals(depRoot, resolveOptions, ssrExternals, seen, logger);
|
|
35451
35861
|
}
|
|
35452
35862
|
}
|
|
35453
35863
|
function cjsShouldExternalizeForSSR(id, externals) {
|
|
@@ -35679,11 +36089,11 @@ function throwOutdatedRequest(id) {
|
|
|
35679
36089
|
throw err;
|
|
35680
36090
|
}
|
|
35681
36091
|
|
|
35682
|
-
const { isMatch: isMatch$
|
|
36092
|
+
const { isMatch: isMatch$1, scan } = micromatch_1;
|
|
35683
36093
|
function getAffectedGlobModules(file, server) {
|
|
35684
36094
|
const modules = [];
|
|
35685
36095
|
for (const [id, allGlobs] of server._importGlobMap) {
|
|
35686
|
-
if (allGlobs.some((glob) => isMatch$
|
|
36096
|
+
if (allGlobs.some((glob) => isMatch$1(file, glob)))
|
|
35687
36097
|
modules.push(...(server.moduleGraph.getModulesByFile(id) || []));
|
|
35688
36098
|
}
|
|
35689
36099
|
modules.forEach((i) => {
|
|
@@ -36035,7 +36445,7 @@ async function toAbsoluteGlob(glob, root, importer, resolveId) {
|
|
|
36035
36445
|
if (glob.startsWith('**'))
|
|
36036
36446
|
return pre + glob;
|
|
36037
36447
|
const resolved = normalizePath$3((await resolveId(glob, importer)) || glob);
|
|
36038
|
-
if (isAbsolute$
|
|
36448
|
+
if (isAbsolute$3(resolved)) {
|
|
36039
36449
|
return pre + globSafeResolvedPath(resolved, glob);
|
|
36040
36450
|
}
|
|
36041
36451
|
throw new Error(`Invalid glob: "${glob}" (resolved: "${resolved}"). It must start with '/' or './'`);
|
|
@@ -36160,11 +36570,11 @@ function updateModules(file, modules, timestamp, { config, ws }) {
|
|
|
36160
36570
|
updates.push(...[...boundaries].map(({ boundary, acceptedVia }) => ({
|
|
36161
36571
|
type: `${boundary.type}-update`,
|
|
36162
36572
|
timestamp,
|
|
36163
|
-
path: boundary.url,
|
|
36573
|
+
path: normalizeHmrUrl(boundary.url),
|
|
36164
36574
|
explicitImportRequired: boundary.type === 'js'
|
|
36165
36575
|
? isExplicitImportRequired(acceptedVia.url)
|
|
36166
36576
|
: undefined,
|
|
36167
|
-
acceptedPath: acceptedVia.url
|
|
36577
|
+
acceptedPath: normalizeHmrUrl(acceptedVia.url)
|
|
36168
36578
|
})));
|
|
36169
36579
|
}
|
|
36170
36580
|
if (needFullReload) {
|
|
@@ -36432,6 +36842,12 @@ function lexAcceptedHmrExports(code, start, exportNames) {
|
|
|
36432
36842
|
}
|
|
36433
36843
|
return urls.size > 0;
|
|
36434
36844
|
}
|
|
36845
|
+
function normalizeHmrUrl(url) {
|
|
36846
|
+
if (!url.startsWith('.') && !url.startsWith('/')) {
|
|
36847
|
+
url = wrapId(url);
|
|
36848
|
+
}
|
|
36849
|
+
return url;
|
|
36850
|
+
}
|
|
36435
36851
|
function error$1(pos) {
|
|
36436
36852
|
const err = new Error(`import.meta.hot.accept() can only accept string literals or an ` +
|
|
36437
36853
|
`Array of string literals.`);
|
|
@@ -36858,7 +37274,7 @@ function parse$a(req) {
|
|
|
36858
37274
|
|
|
36859
37275
|
const noop$2 = () => {};
|
|
36860
37276
|
|
|
36861
|
-
function isMatch
|
|
37277
|
+
function isMatch(uri, arr) {
|
|
36862
37278
|
for (let i=0; i < arr.length; i++) {
|
|
36863
37279
|
if (arr[i].test(uri)) return true;
|
|
36864
37280
|
}
|
|
@@ -37024,7 +37440,7 @@ function sirv (dir, opts={}) {
|
|
|
37024
37440
|
catch (err) { /* malform uri */ }
|
|
37025
37441
|
}
|
|
37026
37442
|
|
|
37027
|
-
let data = lookup(pathname, extns) || isSPA && !isMatch
|
|
37443
|
+
let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
|
|
37028
37444
|
if (!data) return next ? next() : isNotFound(req, res);
|
|
37029
37445
|
|
|
37030
37446
|
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
|
|
@@ -37041,7 +37457,6 @@ function sirv (dir, opts={}) {
|
|
|
37041
37457
|
};
|
|
37042
37458
|
}
|
|
37043
37459
|
|
|
37044
|
-
const { isMatch } = micromatch_1;
|
|
37045
37460
|
const sirvOptions = (headers) => {
|
|
37046
37461
|
return {
|
|
37047
37462
|
dev: true,
|
|
@@ -37150,12 +37565,11 @@ function serveRawFsMiddleware(server) {
|
|
|
37150
37565
|
}
|
|
37151
37566
|
};
|
|
37152
37567
|
}
|
|
37153
|
-
const _matchOptions = { matchBase: true };
|
|
37154
37568
|
function isFileServingAllowed(url, server) {
|
|
37155
37569
|
if (!server.config.server.fs.strict)
|
|
37156
37570
|
return true;
|
|
37157
37571
|
const file = fsPathFromUrl(url);
|
|
37158
|
-
if (server.
|
|
37572
|
+
if (server._fsDenyGlob(file))
|
|
37159
37573
|
return false;
|
|
37160
37574
|
if (server.moduleGraph.safeModulesPath.has(file))
|
|
37161
37575
|
return true;
|
|
@@ -37470,7 +37884,7 @@ function extractImportedBindings(id, source, importSpec, importedBindings) {
|
|
|
37470
37884
|
* ```
|
|
37471
37885
|
*
|
|
37472
37886
|
* - CSS imports are appended with `.js` since both the js module and the actual
|
|
37473
|
-
* css (referenced via
|
|
37887
|
+
* css (referenced via `<link>`) may go through the transform pipeline:
|
|
37474
37888
|
*
|
|
37475
37889
|
* ```js
|
|
37476
37890
|
* import './style.css'
|
|
@@ -37504,8 +37918,8 @@ function importAnalysisPlugin(config) {
|
|
|
37504
37918
|
}
|
|
37505
37919
|
const start = performance.now();
|
|
37506
37920
|
await init;
|
|
37507
|
-
let imports
|
|
37508
|
-
let exports
|
|
37921
|
+
let imports;
|
|
37922
|
+
let exports;
|
|
37509
37923
|
source = stripBomTag(source);
|
|
37510
37924
|
try {
|
|
37511
37925
|
[imports, exports] = parse$b(source);
|
|
@@ -37827,7 +38241,7 @@ function importAnalysisPlugin(config) {
|
|
|
37827
38241
|
: `[detected api usage]`} ${prettyImporter}`);
|
|
37828
38242
|
// inject hot context
|
|
37829
38243
|
str().prepend(`import { createHotContext as __vite__createHotContext } from "${clientPublicPath}";` +
|
|
37830
|
-
`import.meta.hot = __vite__createHotContext(${JSON.stringify(importerModule.url)});`);
|
|
38244
|
+
`import.meta.hot = __vite__createHotContext(${JSON.stringify(normalizeHmrUrl(importerModule.url))});`);
|
|
37831
38245
|
}
|
|
37832
38246
|
if (needQueryInjectHelper) {
|
|
37833
38247
|
str().prepend(`import { injectQuery as __vite__injectQuery } from "${clientPublicPath}";`);
|
|
@@ -38154,276 +38568,6 @@ const wasmFallbackPlugin = () => {
|
|
|
38154
38568
|
};
|
|
38155
38569
|
};
|
|
38156
38570
|
|
|
38157
|
-
const WORKER_FILE_ID = 'worker_file';
|
|
38158
|
-
const workerCache = new WeakMap();
|
|
38159
|
-
function saveEmitWorkerAsset(config, asset) {
|
|
38160
|
-
const fileName = asset.fileName;
|
|
38161
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38162
|
-
workerMap.assets.set(fileName, asset);
|
|
38163
|
-
}
|
|
38164
|
-
async function bundleWorkerEntry(config, id, query) {
|
|
38165
|
-
// bundle the file as entry to support imports
|
|
38166
|
-
const { rollup } = await import('rollup');
|
|
38167
|
-
const { plugins, rollupOptions, format } = config.worker;
|
|
38168
|
-
const bundle = await rollup({
|
|
38169
|
-
...rollupOptions,
|
|
38170
|
-
input: cleanUrl(id),
|
|
38171
|
-
plugins,
|
|
38172
|
-
onwarn(warning, warn) {
|
|
38173
|
-
onRollupWarning(warning, warn, config);
|
|
38174
|
-
},
|
|
38175
|
-
preserveEntrySignatures: false
|
|
38176
|
-
});
|
|
38177
|
-
let chunk;
|
|
38178
|
-
try {
|
|
38179
|
-
const workerOutputConfig = config.worker.rollupOptions.output;
|
|
38180
|
-
const workerConfig = workerOutputConfig
|
|
38181
|
-
? Array.isArray(workerOutputConfig)
|
|
38182
|
-
? workerOutputConfig[0] || {}
|
|
38183
|
-
: workerOutputConfig
|
|
38184
|
-
: {};
|
|
38185
|
-
const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
|
|
38186
|
-
entryFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
38187
|
-
chunkFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].js'),
|
|
38188
|
-
assetFileNames: path$n.posix.join(config.build.assetsDir, '[name].[hash].[ext]'),
|
|
38189
|
-
...workerConfig,
|
|
38190
|
-
format,
|
|
38191
|
-
sourcemap: config.build.sourcemap
|
|
38192
|
-
});
|
|
38193
|
-
chunk = outputChunk;
|
|
38194
|
-
outputChunks.forEach((outputChunk) => {
|
|
38195
|
-
if (outputChunk.type === 'asset') {
|
|
38196
|
-
saveEmitWorkerAsset(config, outputChunk);
|
|
38197
|
-
}
|
|
38198
|
-
else if (outputChunk.type === 'chunk') {
|
|
38199
|
-
saveEmitWorkerAsset(config, {
|
|
38200
|
-
fileName: outputChunk.fileName,
|
|
38201
|
-
source: outputChunk.code,
|
|
38202
|
-
type: 'asset'
|
|
38203
|
-
});
|
|
38204
|
-
}
|
|
38205
|
-
});
|
|
38206
|
-
}
|
|
38207
|
-
finally {
|
|
38208
|
-
await bundle.close();
|
|
38209
|
-
}
|
|
38210
|
-
return emitSourcemapForWorkerEntry(config, query, chunk);
|
|
38211
|
-
}
|
|
38212
|
-
function emitSourcemapForWorkerEntry(config, query, chunk) {
|
|
38213
|
-
const { map: sourcemap } = chunk;
|
|
38214
|
-
if (sourcemap) {
|
|
38215
|
-
if (config.build.sourcemap === 'inline') {
|
|
38216
|
-
// Manually add the sourcemap to the code if configured for inline sourcemaps.
|
|
38217
|
-
// TODO: Remove when https://github.com/rollup/rollup/issues/3913 is resolved
|
|
38218
|
-
// Currently seems that it won't be resolved until Rollup 3
|
|
38219
|
-
const dataUrl = sourcemap.toUrl();
|
|
38220
|
-
chunk.code += `//# sourceMappingURL=${dataUrl}`;
|
|
38221
|
-
}
|
|
38222
|
-
else if (config.build.sourcemap === 'hidden' ||
|
|
38223
|
-
config.build.sourcemap === true) {
|
|
38224
|
-
const data = sourcemap.toString();
|
|
38225
|
-
const mapFileName = chunk.fileName + '.map';
|
|
38226
|
-
saveEmitWorkerAsset(config, {
|
|
38227
|
-
fileName: mapFileName,
|
|
38228
|
-
type: 'asset',
|
|
38229
|
-
source: data
|
|
38230
|
-
});
|
|
38231
|
-
// Emit the comment that tells the JS debugger where it can find the
|
|
38232
|
-
// sourcemap file.
|
|
38233
|
-
// 'hidden' causes the sourcemap file to be created but
|
|
38234
|
-
// the comment in the file to be omitted.
|
|
38235
|
-
if (config.build.sourcemap === true) {
|
|
38236
|
-
// inline web workers need to use the full sourcemap path
|
|
38237
|
-
// non-inline web workers can use a relative path
|
|
38238
|
-
const sourceMapUrl = query?.inline != null
|
|
38239
|
-
? mapFileName
|
|
38240
|
-
: path$n.relative(config.build.assetsDir, mapFileName);
|
|
38241
|
-
chunk.code += `//# sourceMappingURL=${sourceMapUrl}`;
|
|
38242
|
-
}
|
|
38243
|
-
}
|
|
38244
|
-
}
|
|
38245
|
-
return chunk;
|
|
38246
|
-
}
|
|
38247
|
-
const workerAssetUrlRE = /__VITE_WORKER_ASSET__([a-z\d]{8})__/g;
|
|
38248
|
-
function encodeWorkerAssetFileName(fileName, workerCache) {
|
|
38249
|
-
const { fileNameHash } = workerCache;
|
|
38250
|
-
const hash = getHash(fileName);
|
|
38251
|
-
if (!fileNameHash.get(hash)) {
|
|
38252
|
-
fileNameHash.set(hash, fileName);
|
|
38253
|
-
}
|
|
38254
|
-
return `__VITE_WORKER_ASSET__${hash}__`;
|
|
38255
|
-
}
|
|
38256
|
-
async function workerFileToUrl(config, id, query) {
|
|
38257
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38258
|
-
let fileName = workerMap.bundle.get(id);
|
|
38259
|
-
if (!fileName) {
|
|
38260
|
-
const outputChunk = await bundleWorkerEntry(config, id, query);
|
|
38261
|
-
fileName = outputChunk.fileName;
|
|
38262
|
-
saveEmitWorkerAsset(config, {
|
|
38263
|
-
fileName,
|
|
38264
|
-
source: outputChunk.code,
|
|
38265
|
-
type: 'asset'
|
|
38266
|
-
});
|
|
38267
|
-
workerMap.bundle.set(id, fileName);
|
|
38268
|
-
}
|
|
38269
|
-
return encodeWorkerAssetFileName(fileName, workerMap);
|
|
38270
|
-
}
|
|
38271
|
-
function webWorkerPlugin(config) {
|
|
38272
|
-
const isBuild = config.command === 'build';
|
|
38273
|
-
let server;
|
|
38274
|
-
const isWorker = config.isWorker;
|
|
38275
|
-
return {
|
|
38276
|
-
name: 'vite:worker',
|
|
38277
|
-
configureServer(_server) {
|
|
38278
|
-
server = _server;
|
|
38279
|
-
},
|
|
38280
|
-
buildStart() {
|
|
38281
|
-
if (isWorker) {
|
|
38282
|
-
return;
|
|
38283
|
-
}
|
|
38284
|
-
workerCache.set(config, {
|
|
38285
|
-
assets: new Map(),
|
|
38286
|
-
bundle: new Map(),
|
|
38287
|
-
fileNameHash: new Map()
|
|
38288
|
-
});
|
|
38289
|
-
},
|
|
38290
|
-
load(id) {
|
|
38291
|
-
if (isBuild) {
|
|
38292
|
-
const parsedQuery = parseRequest(id);
|
|
38293
|
-
if (parsedQuery &&
|
|
38294
|
-
(parsedQuery.worker ?? parsedQuery.sharedworker) != null) {
|
|
38295
|
-
return '';
|
|
38296
|
-
}
|
|
38297
|
-
}
|
|
38298
|
-
},
|
|
38299
|
-
async transform(raw, id, options) {
|
|
38300
|
-
const ssr = options?.ssr === true;
|
|
38301
|
-
const query = parseRequest(id);
|
|
38302
|
-
if (query && query[WORKER_FILE_ID] != null) {
|
|
38303
|
-
// if import worker by worker constructor will have query.type
|
|
38304
|
-
// other type will be import worker by esm
|
|
38305
|
-
const workerType = query['type'];
|
|
38306
|
-
let injectEnv = '';
|
|
38307
|
-
if (workerType === 'classic') {
|
|
38308
|
-
injectEnv = `importScripts('${ENV_PUBLIC_PATH}')\n`;
|
|
38309
|
-
}
|
|
38310
|
-
else if (workerType === 'module') {
|
|
38311
|
-
injectEnv = `import '${ENV_PUBLIC_PATH}'\n`;
|
|
38312
|
-
}
|
|
38313
|
-
else if (workerType === 'ignore') {
|
|
38314
|
-
if (isBuild) {
|
|
38315
|
-
injectEnv = '';
|
|
38316
|
-
}
|
|
38317
|
-
else if (server) {
|
|
38318
|
-
// dynamic worker type we can't know how import the env
|
|
38319
|
-
// so we copy /@vite/env code of server transform result into file header
|
|
38320
|
-
const { moduleGraph } = server;
|
|
38321
|
-
const module = moduleGraph.getModuleById(ENV_ENTRY);
|
|
38322
|
-
injectEnv = module?.transformResult?.code || '';
|
|
38323
|
-
}
|
|
38324
|
-
}
|
|
38325
|
-
return {
|
|
38326
|
-
code: injectEnv + raw
|
|
38327
|
-
};
|
|
38328
|
-
}
|
|
38329
|
-
if (query == null ||
|
|
38330
|
-
(query && (query.worker ?? query.sharedworker) == null)) {
|
|
38331
|
-
return;
|
|
38332
|
-
}
|
|
38333
|
-
// stringified url or `new URL(...)`
|
|
38334
|
-
let url;
|
|
38335
|
-
const { format } = config.worker;
|
|
38336
|
-
const workerConstructor = query.sharedworker != null ? 'SharedWorker' : 'Worker';
|
|
38337
|
-
const workerType = isBuild
|
|
38338
|
-
? format === 'es'
|
|
38339
|
-
? 'module'
|
|
38340
|
-
: 'classic'
|
|
38341
|
-
: 'module';
|
|
38342
|
-
const workerOptions = workerType === 'classic' ? '' : ',{type: "module"}';
|
|
38343
|
-
if (isBuild) {
|
|
38344
|
-
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
38345
|
-
if (query.inline != null) {
|
|
38346
|
-
const chunk = await bundleWorkerEntry(config, id, query);
|
|
38347
|
-
// inline as blob data url
|
|
38348
|
-
return {
|
|
38349
|
-
code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
|
|
38350
|
-
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
|
|
38351
|
-
export default function WorkerWrapper() {
|
|
38352
|
-
const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
|
|
38353
|
-
try {
|
|
38354
|
-
return objURL ? new ${workerConstructor}(objURL) : new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
|
|
38355
|
-
} finally {
|
|
38356
|
-
objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
|
|
38357
|
-
}
|
|
38358
|
-
}`,
|
|
38359
|
-
// Empty sourcemap to suppress Rollup warning
|
|
38360
|
-
map: { mappings: '' }
|
|
38361
|
-
};
|
|
38362
|
-
}
|
|
38363
|
-
else {
|
|
38364
|
-
url = await workerFileToUrl(config, id, query);
|
|
38365
|
-
}
|
|
38366
|
-
}
|
|
38367
|
-
else {
|
|
38368
|
-
url = await fileToUrl(cleanUrl(id), config, this);
|
|
38369
|
-
url = injectQuery(url, WORKER_FILE_ID);
|
|
38370
|
-
url = injectQuery(url, `type=${workerType}`);
|
|
38371
|
-
}
|
|
38372
|
-
if (query.url != null) {
|
|
38373
|
-
return {
|
|
38374
|
-
code: `export default ${JSON.stringify(url)}`,
|
|
38375
|
-
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
38376
|
-
};
|
|
38377
|
-
}
|
|
38378
|
-
return {
|
|
38379
|
-
code: `export default function WorkerWrapper() {
|
|
38380
|
-
return new ${workerConstructor}(${JSON.stringify(url)}${workerOptions})
|
|
38381
|
-
}`,
|
|
38382
|
-
map: { mappings: '' } // Empty sourcemap to suppress Rollup warning
|
|
38383
|
-
};
|
|
38384
|
-
},
|
|
38385
|
-
renderChunk(code, chunk, outputOptions) {
|
|
38386
|
-
let s;
|
|
38387
|
-
const result = () => {
|
|
38388
|
-
return (s && {
|
|
38389
|
-
code: s.toString(),
|
|
38390
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
38391
|
-
});
|
|
38392
|
-
};
|
|
38393
|
-
if (code.match(workerAssetUrlRE) || code.includes('import.meta.url')) {
|
|
38394
|
-
let match;
|
|
38395
|
-
s = new MagicString(code);
|
|
38396
|
-
// Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
|
|
38397
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
38398
|
-
const { fileNameHash } = workerMap;
|
|
38399
|
-
while ((match = workerAssetUrlRE.exec(code))) {
|
|
38400
|
-
const [full, hash] = match;
|
|
38401
|
-
const filename = fileNameHash.get(hash);
|
|
38402
|
-
const replacement = toOutputFilePathInString(filename, 'asset', chunk.fileName, 'js', config, outputOptions.format);
|
|
38403
|
-
const replacementString = typeof replacement === 'string'
|
|
38404
|
-
? JSON.stringify(replacement).slice(1, -1)
|
|
38405
|
-
: `"+${replacement.runtime}+"`;
|
|
38406
|
-
s.overwrite(match.index, match.index + full.length, replacementString, {
|
|
38407
|
-
contentOnly: true
|
|
38408
|
-
});
|
|
38409
|
-
}
|
|
38410
|
-
}
|
|
38411
|
-
return result();
|
|
38412
|
-
},
|
|
38413
|
-
generateBundle(opts) {
|
|
38414
|
-
// @ts-ignore asset emits are skipped in legacy bundle
|
|
38415
|
-
if (opts.__vite_skip_asset_emit__ || isWorker) {
|
|
38416
|
-
return;
|
|
38417
|
-
}
|
|
38418
|
-
const workerMap = workerCache.get(config);
|
|
38419
|
-
workerMap.assets.forEach((asset) => {
|
|
38420
|
-
this.emitFile(asset);
|
|
38421
|
-
workerMap.assets.delete(asset.fileName);
|
|
38422
|
-
});
|
|
38423
|
-
}
|
|
38424
|
-
};
|
|
38425
|
-
}
|
|
38426
|
-
|
|
38427
38571
|
/**
|
|
38428
38572
|
* A plugin to avoid an aliased AND optimized dep from being aliased in src
|
|
38429
38573
|
*/
|
|
@@ -38639,7 +38783,7 @@ function definePlugin(config) {
|
|
|
38639
38783
|
function ssrRequireHookPlugin(config) {
|
|
38640
38784
|
if (config.command !== 'build' ||
|
|
38641
38785
|
!config.build.ssr ||
|
|
38642
|
-
!config.resolve.dedupe
|
|
38786
|
+
!config.resolve.dedupe.length ||
|
|
38643
38787
|
config.ssr?.noExternal === true ||
|
|
38644
38788
|
config.ssr?.format !== 'cjs' ||
|
|
38645
38789
|
isBuildOutputEsm(config)) {
|
|
@@ -40109,14 +40253,16 @@ function getWorkerType(raw, clean, i) {
|
|
|
40109
40253
|
return 'classic';
|
|
40110
40254
|
}
|
|
40111
40255
|
// need to find in comment code
|
|
40112
|
-
const workerOptString = raw
|
|
40256
|
+
const workerOptString = raw
|
|
40257
|
+
.substring(commaIndex + 1, endIndex)
|
|
40258
|
+
.replace(/}[^]*,/g, '}'); // strip trailing comma for parsing
|
|
40113
40259
|
const hasViteIgnore = ignoreFlagRE.test(workerOptString);
|
|
40114
40260
|
if (hasViteIgnore) {
|
|
40115
40261
|
return 'ignore';
|
|
40116
40262
|
}
|
|
40117
40263
|
// need to find in no comment code
|
|
40118
|
-
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex);
|
|
40119
|
-
if (!cleanWorkerOptString.
|
|
40264
|
+
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex).trim();
|
|
40265
|
+
if (!cleanWorkerOptString.length) {
|
|
40120
40266
|
return 'classic';
|
|
40121
40267
|
}
|
|
40122
40268
|
let workerOpts = { type: 'classic' };
|
|
@@ -40135,6 +40281,7 @@ function getWorkerType(raw, clean, i) {
|
|
|
40135
40281
|
}
|
|
40136
40282
|
function workerImportMetaUrlPlugin(config) {
|
|
40137
40283
|
const isBuild = config.command === 'build';
|
|
40284
|
+
let workerResolver;
|
|
40138
40285
|
return {
|
|
40139
40286
|
name: 'vite:worker-import-meta-url',
|
|
40140
40287
|
async transform(code, id, options) {
|
|
@@ -40160,20 +40307,33 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
40160
40307
|
}
|
|
40161
40308
|
s || (s = new MagicString(code));
|
|
40162
40309
|
const workerType = getWorkerType(code, cleanString, index + allExp.length);
|
|
40163
|
-
const
|
|
40164
|
-
let
|
|
40310
|
+
const url = rawUrl.slice(1, -1);
|
|
40311
|
+
let file;
|
|
40312
|
+
if (url.startsWith('.')) {
|
|
40313
|
+
file = path$n.resolve(path$n.dirname(id), url);
|
|
40314
|
+
}
|
|
40315
|
+
else {
|
|
40316
|
+
workerResolver ?? (workerResolver = config.createResolver({
|
|
40317
|
+
extensions: [],
|
|
40318
|
+
tryIndex: false,
|
|
40319
|
+
preferRelative: true
|
|
40320
|
+
}));
|
|
40321
|
+
file = await workerResolver(url, id);
|
|
40322
|
+
file ?? (file = url.startsWith('/')
|
|
40323
|
+
? slash$1(path$n.join(config.publicDir, url))
|
|
40324
|
+
: slash$1(path$n.resolve(path$n.dirname(id), url)));
|
|
40325
|
+
}
|
|
40326
|
+
let builtUrl;
|
|
40165
40327
|
if (isBuild) {
|
|
40166
40328
|
getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
|
|
40167
|
-
|
|
40329
|
+
builtUrl = await workerFileToUrl(config, file, query);
|
|
40168
40330
|
}
|
|
40169
40331
|
else {
|
|
40170
|
-
|
|
40171
|
-
|
|
40172
|
-
|
|
40332
|
+
builtUrl = await fileToUrl(cleanUrl(file), config, this);
|
|
40333
|
+
builtUrl = injectQuery(builtUrl, WORKER_FILE_ID);
|
|
40334
|
+
builtUrl = injectQuery(builtUrl, `type=${workerType}`);
|
|
40173
40335
|
}
|
|
40174
|
-
s.overwrite(urlIndex, urlIndex + exp.length, JSON.stringify(
|
|
40175
|
-
contentOnly: true
|
|
40176
|
-
});
|
|
40336
|
+
s.overwrite(urlIndex, urlIndex + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
|
|
40177
40337
|
}
|
|
40178
40338
|
if (s) {
|
|
40179
40339
|
return transformStableResult(s, id, config);
|
|
@@ -40184,6 +40344,119 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
40184
40344
|
};
|
|
40185
40345
|
}
|
|
40186
40346
|
|
|
40347
|
+
/**
|
|
40348
|
+
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
|
|
40349
|
+
*
|
|
40350
|
+
* Supports template string with dynamic segments:
|
|
40351
|
+
* ```
|
|
40352
|
+
* new URL(`./dir/${name}.png`, import.meta.url)
|
|
40353
|
+
* // transformed to
|
|
40354
|
+
* import.meta.glob('./dir/**.png', { eager: true, import: 'default' })[`./dir/${name}.png`]
|
|
40355
|
+
* ```
|
|
40356
|
+
*/
|
|
40357
|
+
function assetImportMetaUrlPlugin(config) {
|
|
40358
|
+
const normalizedPublicDir = normalizePath$3(config.publicDir);
|
|
40359
|
+
let assetResolver;
|
|
40360
|
+
return {
|
|
40361
|
+
name: 'vite:asset-import-meta-url',
|
|
40362
|
+
async transform(code, id, options) {
|
|
40363
|
+
if (!options?.ssr &&
|
|
40364
|
+
id !== preloadHelperId &&
|
|
40365
|
+
code.includes('new URL') &&
|
|
40366
|
+
code.includes(`import.meta.url`)) {
|
|
40367
|
+
let s;
|
|
40368
|
+
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g;
|
|
40369
|
+
const cleanString = stripLiteral(code);
|
|
40370
|
+
let match;
|
|
40371
|
+
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
|
40372
|
+
const { 0: exp, 1: emptyUrl, index } = match;
|
|
40373
|
+
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
40374
|
+
const urlEnd = urlStart + emptyUrl.length;
|
|
40375
|
+
const rawUrl = code.slice(urlStart, urlEnd);
|
|
40376
|
+
if (!s)
|
|
40377
|
+
s = new MagicString(code);
|
|
40378
|
+
// potential dynamic template string
|
|
40379
|
+
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
|
|
40380
|
+
const ast = this.parse(rawUrl);
|
|
40381
|
+
const templateLiteral = ast.body[0].expression;
|
|
40382
|
+
if (templateLiteral.expressions.length) {
|
|
40383
|
+
const pattern = JSON.stringify(buildGlobPattern(templateLiteral));
|
|
40384
|
+
// Note: native import.meta.url is not supported in the baseline
|
|
40385
|
+
// target so we use the global location here. It can be
|
|
40386
|
+
// window.location or self.location in case it is used in a Web Worker.
|
|
40387
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Window/self
|
|
40388
|
+
s.overwrite(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, { contentOnly: true });
|
|
40389
|
+
continue;
|
|
40390
|
+
}
|
|
40391
|
+
}
|
|
40392
|
+
const url = rawUrl.slice(1, -1);
|
|
40393
|
+
let file;
|
|
40394
|
+
if (url.startsWith('.')) {
|
|
40395
|
+
file = slash$1(path$n.resolve(path$n.dirname(id), url));
|
|
40396
|
+
}
|
|
40397
|
+
else {
|
|
40398
|
+
assetResolver ?? (assetResolver = config.createResolver({
|
|
40399
|
+
extensions: [],
|
|
40400
|
+
mainFields: [],
|
|
40401
|
+
tryIndex: false,
|
|
40402
|
+
preferRelative: true
|
|
40403
|
+
}));
|
|
40404
|
+
file = await assetResolver(url, id);
|
|
40405
|
+
file ?? (file = url.startsWith('/')
|
|
40406
|
+
? slash$1(path$n.join(config.publicDir, url))
|
|
40407
|
+
: slash$1(path$n.resolve(path$n.dirname(id), url)));
|
|
40408
|
+
}
|
|
40409
|
+
// Get final asset URL. If the file does not exist,
|
|
40410
|
+
// we fall back to the initial URL and let it resolve in runtime
|
|
40411
|
+
let builtUrl;
|
|
40412
|
+
if (file) {
|
|
40413
|
+
try {
|
|
40414
|
+
if (isParentDirectory(normalizedPublicDir, file)) {
|
|
40415
|
+
const publicPath = '/' + path$n.posix.relative(normalizedPublicDir, file);
|
|
40416
|
+
builtUrl = await fileToUrl(publicPath, config, this);
|
|
40417
|
+
}
|
|
40418
|
+
else {
|
|
40419
|
+
builtUrl = await fileToUrl(file, config, this);
|
|
40420
|
+
}
|
|
40421
|
+
}
|
|
40422
|
+
catch {
|
|
40423
|
+
// do nothing, we'll log a warning after this
|
|
40424
|
+
}
|
|
40425
|
+
}
|
|
40426
|
+
if (!builtUrl) {
|
|
40427
|
+
const rawExp = code.slice(index, index + exp.length);
|
|
40428
|
+
config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
|
|
40429
|
+
builtUrl = url;
|
|
40430
|
+
}
|
|
40431
|
+
s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
|
|
40432
|
+
}
|
|
40433
|
+
if (s) {
|
|
40434
|
+
return transformStableResult(s, id, config);
|
|
40435
|
+
}
|
|
40436
|
+
}
|
|
40437
|
+
return null;
|
|
40438
|
+
}
|
|
40439
|
+
};
|
|
40440
|
+
}
|
|
40441
|
+
function buildGlobPattern(ast) {
|
|
40442
|
+
let pattern = '';
|
|
40443
|
+
let lastElementIndex = -1;
|
|
40444
|
+
for (const exp of ast.expressions) {
|
|
40445
|
+
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
40446
|
+
const el = ast.quasis[i];
|
|
40447
|
+
if (el.end < exp.start) {
|
|
40448
|
+
pattern += el.value.raw;
|
|
40449
|
+
lastElementIndex = i;
|
|
40450
|
+
}
|
|
40451
|
+
}
|
|
40452
|
+
pattern += '**';
|
|
40453
|
+
}
|
|
40454
|
+
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
40455
|
+
pattern += ast.quasis[i].value.raw;
|
|
40456
|
+
}
|
|
40457
|
+
return pattern;
|
|
40458
|
+
}
|
|
40459
|
+
|
|
40187
40460
|
/**
|
|
40188
40461
|
* plugin to ensure rollup can watch correctly.
|
|
40189
40462
|
*/
|
|
@@ -40365,6 +40638,12 @@ function parseDynamicImportPattern(strings) {
|
|
|
40365
40638
|
if (rawQuery?.raw !== undefined) {
|
|
40366
40639
|
globParams = { as: 'raw' };
|
|
40367
40640
|
}
|
|
40641
|
+
if (rawQuery?.url !== undefined) {
|
|
40642
|
+
globParams = { as: 'url' };
|
|
40643
|
+
}
|
|
40644
|
+
if (rawQuery?.worker !== undefined) {
|
|
40645
|
+
globParams = { as: 'worker' };
|
|
40646
|
+
}
|
|
40368
40647
|
return {
|
|
40369
40648
|
globParams,
|
|
40370
40649
|
userPattern,
|
|
@@ -40484,13 +40763,15 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
40484
40763
|
const buildPlugins = isBuild
|
|
40485
40764
|
? (await Promise.resolve().then(function () { return build$1; })).resolveBuildPlugins(config)
|
|
40486
40765
|
: { pre: [], post: [] };
|
|
40766
|
+
const { modulePreload } = config.build;
|
|
40487
40767
|
return [
|
|
40488
40768
|
isWatch ? ensureWatchPlugin() : null,
|
|
40489
40769
|
isBuild ? metadataPlugin() : null,
|
|
40490
40770
|
preAliasPlugin(config),
|
|
40491
40771
|
alias$1({ entries: config.resolve.alias }),
|
|
40492
40772
|
...prePlugins,
|
|
40493
|
-
|
|
40773
|
+
modulePreload === true ||
|
|
40774
|
+
(typeof modulePreload === 'object' && modulePreload.polyfill)
|
|
40494
40775
|
? modulePreloadPolyfillPlugin(config)
|
|
40495
40776
|
: null,
|
|
40496
40777
|
...(isDepsOptimizerEnabled(config, false) ||
|
|
@@ -40531,6 +40812,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
40531
40812
|
isBuild && config.build.ssr ? ssrRequireHookPlugin(config) : null,
|
|
40532
40813
|
isBuild && buildHtmlPlugin(config),
|
|
40533
40814
|
workerImportMetaUrlPlugin(config),
|
|
40815
|
+
assetImportMetaUrlPlugin(config),
|
|
40534
40816
|
...buildPlugins.pre,
|
|
40535
40817
|
dynamicImportVarsPlugin(config),
|
|
40536
40818
|
importGlobPlugin(config),
|
|
@@ -41461,7 +41743,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
41461
41743
|
// may end with these extensions
|
|
41462
41744
|
// css & json & wasm
|
|
41463
41745
|
build.onResolve({
|
|
41464
|
-
filter: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|json|wasm)$/
|
|
41746
|
+
filter: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss|json|wasm)$/
|
|
41465
41747
|
}, externalUnlessEntry);
|
|
41466
41748
|
// known asset types
|
|
41467
41749
|
build.onResolve({
|
|
@@ -41606,6 +41888,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
41606
41888
|
const sessionTimestamp = Date.now().toString();
|
|
41607
41889
|
const cachedMetadata = loadCachedDepOptimizationMetadata(config, ssr);
|
|
41608
41890
|
let handle;
|
|
41891
|
+
let closed = false;
|
|
41609
41892
|
let metadata = cachedMetadata || initDepsOptimizerMetadata(config, ssr, sessionTimestamp);
|
|
41610
41893
|
const depsOptimizer = {
|
|
41611
41894
|
metadata,
|
|
@@ -41618,6 +41901,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
41618
41901
|
delayDepsOptimizerUntil,
|
|
41619
41902
|
resetRegisteredIds,
|
|
41620
41903
|
ensureFirstRun,
|
|
41904
|
+
close,
|
|
41621
41905
|
options: getDepOptimizationConfig(config, ssr)
|
|
41622
41906
|
};
|
|
41623
41907
|
depsOptimizerMap.set(config, depsOptimizer);
|
|
@@ -41646,6 +41930,12 @@ async function createDepsOptimizer(config, server) {
|
|
|
41646
41930
|
// If there wasn't a cache or it is outdated, we need to prepare a first run
|
|
41647
41931
|
let firstRunCalled = !!cachedMetadata;
|
|
41648
41932
|
let postScanOptimizationResult;
|
|
41933
|
+
let optimizingNewDeps;
|
|
41934
|
+
async function close() {
|
|
41935
|
+
closed = true;
|
|
41936
|
+
await postScanOptimizationResult;
|
|
41937
|
+
await optimizingNewDeps;
|
|
41938
|
+
}
|
|
41649
41939
|
if (!cachedMetadata) {
|
|
41650
41940
|
// Enter processing state until crawl of static imports ends
|
|
41651
41941
|
currentlyProcessing = true;
|
|
@@ -41743,13 +42033,20 @@ async function createDepsOptimizer(config, server) {
|
|
|
41743
42033
|
// Ensure that a rerun will not be issued for current discovered deps
|
|
41744
42034
|
if (handle)
|
|
41745
42035
|
clearTimeout(handle);
|
|
41746
|
-
if (Object.keys(metadata.discovered).length === 0) {
|
|
42036
|
+
if (closed || Object.keys(metadata.discovered).length === 0) {
|
|
41747
42037
|
currentlyProcessing = false;
|
|
41748
42038
|
return;
|
|
41749
42039
|
}
|
|
41750
42040
|
currentlyProcessing = true;
|
|
41751
42041
|
try {
|
|
41752
|
-
const processingResult = preRunResult ?? (await optimizeNewDeps());
|
|
42042
|
+
const processingResult = preRunResult ?? (await (optimizingNewDeps = optimizeNewDeps()));
|
|
42043
|
+
optimizingNewDeps = undefined;
|
|
42044
|
+
if (closed) {
|
|
42045
|
+
currentlyProcessing = false;
|
|
42046
|
+
processingResult.cancel();
|
|
42047
|
+
resolveEnqueuedProcessingPromises();
|
|
42048
|
+
return;
|
|
42049
|
+
}
|
|
41753
42050
|
const newData = processingResult.metadata;
|
|
41754
42051
|
const needsInteropMismatch = findInteropMismatches(metadata.discovered, newData.optimized);
|
|
41755
42052
|
// After a re-optimization, if the internal bundled chunks change a full page reload
|
|
@@ -42018,7 +42315,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
42018
42315
|
function ensureFirstRun() {
|
|
42019
42316
|
if (!firstRunEnsured && !firstRunCalled && registeredIds.length === 0) {
|
|
42020
42317
|
setTimeout(() => {
|
|
42021
|
-
if (registeredIds.length === 0) {
|
|
42318
|
+
if (!closed && registeredIds.length === 0) {
|
|
42022
42319
|
onCrawlEnd();
|
|
42023
42320
|
}
|
|
42024
42321
|
}, runOptimizerIfIdleAfterMs);
|
|
@@ -42049,7 +42346,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
42049
42346
|
waitingOn = next.id;
|
|
42050
42347
|
const afterLoad = () => {
|
|
42051
42348
|
waitingOn = undefined;
|
|
42052
|
-
if (!workersSources.has(next.id)) {
|
|
42349
|
+
if (!closed && !workersSources.has(next.id)) {
|
|
42053
42350
|
if (registeredIds.length > 0) {
|
|
42054
42351
|
runOptimizerWhenIdle();
|
|
42055
42352
|
}
|
|
@@ -42085,6 +42382,7 @@ async function createDevSsrDepsOptimizer(config) {
|
|
|
42085
42382
|
delayDepsOptimizerUntil: (id, done) => { },
|
|
42086
42383
|
resetRegisteredIds: () => { },
|
|
42087
42384
|
ensureFirstRun: () => { },
|
|
42385
|
+
close: async () => { },
|
|
42088
42386
|
options: config.ssr.optimizeDeps
|
|
42089
42387
|
};
|
|
42090
42388
|
devSsrDepsOptimizerMap.set(config, depsOptimizer);
|
|
@@ -42694,7 +42992,12 @@ function needsInterop(config, ssr, id, exportsData, output) {
|
|
|
42694
42992
|
function isSingleDefaultExport(exports) {
|
|
42695
42993
|
return exports.length === 1 && exports[0] === 'default';
|
|
42696
42994
|
}
|
|
42697
|
-
const lockfileFormats = [
|
|
42995
|
+
const lockfileFormats = [
|
|
42996
|
+
'package-lock.json',
|
|
42997
|
+
'yarn.lock',
|
|
42998
|
+
'pnpm-lock.yaml',
|
|
42999
|
+
'bun.lockb'
|
|
43000
|
+
];
|
|
42698
43001
|
function getDepHash(config, ssr) {
|
|
42699
43002
|
let content = lookupFile(config.root, lockfileFormats) || '';
|
|
42700
43003
|
// also take config into account
|
|
@@ -42794,6 +43097,10 @@ const dynamicImportPrefixRE = /import\s*\(/;
|
|
|
42794
43097
|
// TODO: abstract
|
|
42795
43098
|
const optimizedDepChunkRE = /\/chunk-[A-Z0-9]{8}\.js/;
|
|
42796
43099
|
const optimizedDepDynamicRE = /-[A-Z0-9]{8}\.js/;
|
|
43100
|
+
function toRelativePath(filename, importer) {
|
|
43101
|
+
const relPath = path$n.relative(path$n.dirname(importer), filename);
|
|
43102
|
+
return relPath.startsWith('.') ? relPath : `./${relPath}`;
|
|
43103
|
+
}
|
|
42797
43104
|
/**
|
|
42798
43105
|
* Helper for preloading CSS and direct imports of async chunks in parallel to
|
|
42799
43106
|
* the async chunk itself.
|
|
@@ -42811,6 +43118,7 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42811
43118
|
if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {
|
|
42812
43119
|
return baseModule();
|
|
42813
43120
|
}
|
|
43121
|
+
const links = document.getElementsByTagName('link');
|
|
42814
43122
|
return Promise.all(deps.map((dep) => {
|
|
42815
43123
|
// @ts-ignore
|
|
42816
43124
|
dep = assetsURL(dep, importerUrl);
|
|
@@ -42821,8 +43129,21 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42821
43129
|
seen[dep] = true;
|
|
42822
43130
|
const isCss = dep.endsWith('.css');
|
|
42823
43131
|
const cssSelector = isCss ? '[rel="stylesheet"]' : '';
|
|
42824
|
-
|
|
42825
|
-
if
|
|
43132
|
+
const isBaseRelative = !!importerUrl;
|
|
43133
|
+
// check if the file is already preloaded by SSR markup
|
|
43134
|
+
if (isBaseRelative) {
|
|
43135
|
+
// When isBaseRelative is true then we have `importerUrl` and `dep` is
|
|
43136
|
+
// already converted to an absolute URL by the `assetsURL` function
|
|
43137
|
+
for (let i = links.length - 1; i >= 0; i--) {
|
|
43138
|
+
const link = links[i];
|
|
43139
|
+
// The `links[i].href` is an absolute URL thanks to browser doing the work
|
|
43140
|
+
// for us. See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-domstring-5
|
|
43141
|
+
if (link.href === dep && (!isCss || link.rel === 'stylesheet')) {
|
|
43142
|
+
return;
|
|
43143
|
+
}
|
|
43144
|
+
}
|
|
43145
|
+
}
|
|
43146
|
+
else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
|
|
42826
43147
|
return;
|
|
42827
43148
|
}
|
|
42828
43149
|
// @ts-ignore
|
|
@@ -42850,14 +43171,39 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
42850
43171
|
function buildImportAnalysisPlugin(config) {
|
|
42851
43172
|
const ssr = !!config.build.ssr;
|
|
42852
43173
|
const isWorker = config.isWorker;
|
|
42853
|
-
const insertPreload = !(ssr ||
|
|
42854
|
-
|
|
42855
|
-
|
|
43174
|
+
const insertPreload = !(ssr ||
|
|
43175
|
+
!!config.build.lib ||
|
|
43176
|
+
isWorker ||
|
|
43177
|
+
config.build.modulePreload === false);
|
|
43178
|
+
const resolveModulePreloadDependencies = config.build.modulePreload && config.build.modulePreload.resolveDependencies;
|
|
43179
|
+
const renderBuiltUrl = config.experimental.renderBuiltUrl;
|
|
43180
|
+
const customModulePreloadPaths = !!(resolveModulePreloadDependencies || renderBuiltUrl);
|
|
43181
|
+
const isRelativeBase = config.base === './' || config.base === '';
|
|
43182
|
+
const optimizeModulePreloadRelativePaths = isRelativeBase && !customModulePreloadPaths;
|
|
43183
|
+
const { modulePreload } = config.build;
|
|
43184
|
+
const scriptRel = modulePreload && modulePreload.polyfill
|
|
42856
43185
|
? `'modulepreload'`
|
|
42857
43186
|
: `(${detectScriptRel.toString()})()`;
|
|
42858
|
-
|
|
42859
|
-
|
|
42860
|
-
|
|
43187
|
+
// There are three different cases for the preload list format in __vitePreload
|
|
43188
|
+
//
|
|
43189
|
+
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
|
|
43190
|
+
//
|
|
43191
|
+
// This is maintained to keep backwards compatibility as some users developed plugins
|
|
43192
|
+
// using regex over this list to workaround the fact that module preload wasn't
|
|
43193
|
+
// configurable.
|
|
43194
|
+
const assetsURL = customModulePreloadPaths
|
|
43195
|
+
? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used
|
|
43196
|
+
// the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
|
|
43197
|
+
// a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
|
|
43198
|
+
`function(dep, importerUrl) { return dep.startsWith('.') ? new URL(dep, importerUrl).href : dep }`
|
|
43199
|
+
: optimizeModulePreloadRelativePaths
|
|
43200
|
+
? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
|
|
43201
|
+
// to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
|
|
43202
|
+
// The importerUrl is passed as third parameter to __vitePreload in this case
|
|
43203
|
+
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
|
|
43204
|
+
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
|
|
43205
|
+
// is appendended inside __vitePreload too.
|
|
43206
|
+
`function(dep) { return ${JSON.stringify(config.base)}+dep }`;
|
|
42861
43207
|
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
|
|
42862
43208
|
return {
|
|
42863
43209
|
name: 'vite:build-import-analysis',
|
|
@@ -42943,7 +43289,9 @@ function buildImportAnalysisPlugin(config) {
|
|
|
42943
43289
|
if (isDynamicImport && insertPreload) {
|
|
42944
43290
|
needPreloadHelper = true;
|
|
42945
43291
|
str().prependLeft(expStart, `${preloadMethod}(() => `);
|
|
42946
|
-
str().appendRight(expEnd, `,${isModernFlag}?"${preloadMarker}":void 0${
|
|
43292
|
+
str().appendRight(expEnd, `,${isModernFlag}?"${preloadMarker}":void 0${optimizeModulePreloadRelativePaths || customModulePreloadPaths
|
|
43293
|
+
? ',import.meta.url'
|
|
43294
|
+
: ''})`);
|
|
42947
43295
|
}
|
|
42948
43296
|
// static import or valid string in dynamic import
|
|
42949
43297
|
// If resolvable, let's resolve it
|
|
@@ -43038,7 +43386,10 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43038
43386
|
return null;
|
|
43039
43387
|
},
|
|
43040
43388
|
generateBundle({ format }, bundle) {
|
|
43041
|
-
if (format !== 'es' ||
|
|
43389
|
+
if (format !== 'es' ||
|
|
43390
|
+
ssr ||
|
|
43391
|
+
isWorker ||
|
|
43392
|
+
config.build.modulePreload === false) {
|
|
43042
43393
|
return;
|
|
43043
43394
|
}
|
|
43044
43395
|
for (const file in bundle) {
|
|
@@ -43047,7 +43398,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43047
43398
|
// dynamic import to constant json may get inlined.
|
|
43048
43399
|
if (chunk.type === 'chunk' && chunk.code.indexOf(preloadMarker) > -1) {
|
|
43049
43400
|
const code = chunk.code;
|
|
43050
|
-
let imports
|
|
43401
|
+
let imports;
|
|
43051
43402
|
try {
|
|
43052
43403
|
imports = parse$b(code)[0].filter((i) => i.d > -1);
|
|
43053
43404
|
}
|
|
@@ -43069,7 +43420,9 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43069
43420
|
}
|
|
43070
43421
|
const deps = new Set();
|
|
43071
43422
|
let hasRemovedPureCssChunk = false;
|
|
43423
|
+
let normalizedFile = undefined;
|
|
43072
43424
|
if (url) {
|
|
43425
|
+
normalizedFile = path$n.posix.join(path$n.posix.dirname(chunk.fileName), url);
|
|
43073
43426
|
const ownerFilename = chunk.fileName;
|
|
43074
43427
|
// literal import - trace direct imports and add to deps
|
|
43075
43428
|
const analyzed = new Set();
|
|
@@ -43082,10 +43435,12 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43082
43435
|
const chunk = bundle[filename];
|
|
43083
43436
|
if (chunk) {
|
|
43084
43437
|
deps.add(chunk.fileName);
|
|
43438
|
+
chunk.imports.forEach(addDeps);
|
|
43439
|
+
// Ensure that the css imported by current chunk is loaded after the dependencies.
|
|
43440
|
+
// So the style of current chunk won't be overwritten unexpectedly.
|
|
43085
43441
|
chunk.viteMetadata.importedCss.forEach((file) => {
|
|
43086
43442
|
deps.add(file);
|
|
43087
43443
|
});
|
|
43088
|
-
chunk.imports.forEach(addDeps);
|
|
43089
43444
|
}
|
|
43090
43445
|
else {
|
|
43091
43446
|
const removedPureCssFiles = removedPureCssFilesCache.get(config);
|
|
@@ -43103,7 +43458,6 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43103
43458
|
}
|
|
43104
43459
|
}
|
|
43105
43460
|
};
|
|
43106
|
-
const normalizedFile = path$n.posix.join(path$n.posix.dirname(chunk.fileName), url);
|
|
43107
43461
|
addDeps(normalizedFile);
|
|
43108
43462
|
}
|
|
43109
43463
|
let markerStartPos = code.indexOf(preloadMarkerWithQuote, end);
|
|
@@ -43112,19 +43466,53 @@ function buildImportAnalysisPlugin(config) {
|
|
|
43112
43466
|
markerStartPos = code.indexOf(preloadMarkerWithQuote);
|
|
43113
43467
|
}
|
|
43114
43468
|
if (markerStartPos > 0) {
|
|
43115
|
-
|
|
43116
|
-
|
|
43117
|
-
// actual other deps. Don't include the assets dir if the default asset file names
|
|
43118
|
-
// are used, the path will be reconstructed by the import preload helper
|
|
43119
|
-
deps.size > 1 ||
|
|
43469
|
+
// the dep list includes the main chunk, so only need to reload when there are actual other deps.
|
|
43470
|
+
const depsArray = deps.size > 1 ||
|
|
43120
43471
|
// main chunk is removed
|
|
43121
43472
|
(hasRemovedPureCssChunk && deps.size > 0)
|
|
43122
|
-
?
|
|
43123
|
-
|
|
43124
|
-
|
|
43125
|
-
|
|
43126
|
-
|
|
43127
|
-
|
|
43473
|
+
? [...deps]
|
|
43474
|
+
: [];
|
|
43475
|
+
let renderedDeps;
|
|
43476
|
+
if (normalizedFile && customModulePreloadPaths) {
|
|
43477
|
+
const { modulePreload } = config.build;
|
|
43478
|
+
const resolveDependencies = modulePreload && modulePreload.resolveDependencies;
|
|
43479
|
+
let resolvedDeps;
|
|
43480
|
+
if (resolveDependencies) {
|
|
43481
|
+
// We can't let the user remove css deps as these aren't really preloads, they are just using
|
|
43482
|
+
// the same mechanism as module preloads for this chunk
|
|
43483
|
+
const cssDeps = [];
|
|
43484
|
+
const otherDeps = [];
|
|
43485
|
+
for (const dep of depsArray) {
|
|
43486
|
+
(dep.endsWith('.css') ? cssDeps : otherDeps).push(dep);
|
|
43487
|
+
}
|
|
43488
|
+
resolvedDeps = [
|
|
43489
|
+
...resolveDependencies(normalizedFile, otherDeps, {
|
|
43490
|
+
hostId: file,
|
|
43491
|
+
hostType: 'js'
|
|
43492
|
+
}),
|
|
43493
|
+
...cssDeps
|
|
43494
|
+
];
|
|
43495
|
+
}
|
|
43496
|
+
else {
|
|
43497
|
+
resolvedDeps = depsArray;
|
|
43498
|
+
}
|
|
43499
|
+
renderedDeps = resolvedDeps.map((dep) => {
|
|
43500
|
+
const replacement = toOutputFilePathInJS(dep, 'asset', chunk.fileName, 'js', config, toRelativePath);
|
|
43501
|
+
const replacementString = typeof replacement === 'string'
|
|
43502
|
+
? JSON.stringify(replacement)
|
|
43503
|
+
: replacement.runtime;
|
|
43504
|
+
return replacementString;
|
|
43505
|
+
});
|
|
43506
|
+
}
|
|
43507
|
+
else {
|
|
43508
|
+
renderedDeps = depsArray.map((d) =>
|
|
43509
|
+
// Don't include the assets dir if the default asset file names
|
|
43510
|
+
// are used, the path will be reconstructed by the import preload helper
|
|
43511
|
+
JSON.stringify(optimizeModulePreloadRelativePaths
|
|
43512
|
+
? toRelativePath(d, file)
|
|
43513
|
+
: d));
|
|
43514
|
+
}
|
|
43515
|
+
s.overwrite(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, `[${renderedDeps.join(',')}]`, { contentOnly: true });
|
|
43128
43516
|
rewroteMarkerStartPos.add(markerStartPos);
|
|
43129
43517
|
}
|
|
43130
43518
|
}
|
|
@@ -43609,7 +43997,9 @@ function buildHtmlPlugin(config) {
|
|
|
43609
43997
|
}
|
|
43610
43998
|
processedHtml.set(id, s.toString());
|
|
43611
43999
|
// inject module preload polyfill only when configured and needed
|
|
43612
|
-
|
|
44000
|
+
const { modulePreload } = config.build;
|
|
44001
|
+
if ((modulePreload === true ||
|
|
44002
|
+
(typeof modulePreload === 'object' && modulePreload.polyfill)) &&
|
|
43613
44003
|
(someScriptsAreAsync || someScriptsAreDefer)) {
|
|
43614
44004
|
js = `import "${modulePreloadPolyfillId}";\n${js}`;
|
|
43615
44005
|
}
|
|
@@ -43640,12 +44030,12 @@ function buildHtmlPlugin(config) {
|
|
|
43640
44030
|
src: toOutputPath(chunk.fileName)
|
|
43641
44031
|
}
|
|
43642
44032
|
});
|
|
43643
|
-
const toPreloadTag = (
|
|
44033
|
+
const toPreloadTag = (filename, toOutputPath) => ({
|
|
43644
44034
|
tag: 'link',
|
|
43645
44035
|
attrs: {
|
|
43646
44036
|
rel: 'modulepreload',
|
|
43647
44037
|
crossorigin: true,
|
|
43648
|
-
href: toOutputPath(
|
|
44038
|
+
href: toOutputPath(filename)
|
|
43649
44039
|
}
|
|
43650
44040
|
});
|
|
43651
44041
|
const getCssTagsForChunk = (chunk, toOutputPath, seen = new Set()) => {
|
|
@@ -43704,12 +44094,26 @@ function buildHtmlPlugin(config) {
|
|
|
43704
44094
|
// when not inlined, inject <script> for entry and modulepreload its dependencies
|
|
43705
44095
|
// when inlined, discard entry chunk and inject <script> for everything in post-order
|
|
43706
44096
|
const imports = getImportedChunks(chunk);
|
|
43707
|
-
|
|
43708
|
-
|
|
43709
|
-
|
|
44097
|
+
let assetTags;
|
|
44098
|
+
if (canInlineEntry) {
|
|
44099
|
+
assetTags = imports.map((chunk) => toScriptTag(chunk, toOutputAssetFilePath, isAsync));
|
|
44100
|
+
}
|
|
44101
|
+
else {
|
|
44102
|
+
const { modulePreload } = config.build;
|
|
44103
|
+
const resolveDependencies = typeof modulePreload === 'object' &&
|
|
44104
|
+
modulePreload.resolveDependencies;
|
|
44105
|
+
const importsFileNames = imports.map((chunk) => chunk.fileName);
|
|
44106
|
+
const resolvedDeps = resolveDependencies
|
|
44107
|
+
? resolveDependencies(chunk.fileName, importsFileNames, {
|
|
44108
|
+
hostId: relativeUrlPath,
|
|
44109
|
+
hostType: 'html'
|
|
44110
|
+
})
|
|
44111
|
+
: importsFileNames;
|
|
44112
|
+
assetTags = [
|
|
43710
44113
|
toScriptTag(chunk, toOutputAssetFilePath, isAsync),
|
|
43711
|
-
...
|
|
44114
|
+
...resolvedDeps.map((i) => toPreloadTag(i, toOutputAssetFilePath))
|
|
43712
44115
|
];
|
|
44116
|
+
}
|
|
43713
44117
|
assetTags.push(...getCssTagsForChunk(chunk, toOutputAssetFilePath));
|
|
43714
44118
|
result = injectToHead(result, assetTags);
|
|
43715
44119
|
}
|
|
@@ -43976,7 +44380,7 @@ function incrementIndent(indent = '') {
|
|
|
43976
44380
|
return `${indent}${indent[0] === '\t' ? '\t' : ' '}`;
|
|
43977
44381
|
}
|
|
43978
44382
|
|
|
43979
|
-
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
|
|
44383
|
+
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`;
|
|
43980
44384
|
const cssLangRE = new RegExp(cssLangs);
|
|
43981
44385
|
const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
|
|
43982
44386
|
const directRequestRE = /(\?|&)direct\b/;
|
|
@@ -43993,7 +44397,7 @@ const isDirectRequest = (request) => directRequestRE.test(request);
|
|
|
43993
44397
|
const cssModulesCache = new WeakMap();
|
|
43994
44398
|
const removedPureCssFilesCache = new WeakMap();
|
|
43995
44399
|
const cssEntryFilesCache = new WeakMap();
|
|
43996
|
-
const postcssConfigCache =
|
|
44400
|
+
const postcssConfigCache = {};
|
|
43997
44401
|
function encodePublicUrlsInCSS(config) {
|
|
43998
44402
|
return config.command === 'build';
|
|
43999
44403
|
}
|
|
@@ -44299,7 +44703,7 @@ function cssPostPlugin(config) {
|
|
|
44299
44703
|
// the legacy build should avoid inserting entry CSS modules here, they
|
|
44300
44704
|
// will be collected into `chunk.viteMetadata.importedCss` and injected
|
|
44301
44705
|
// later by the `'vite:build-html'` plugin into the `index.html`
|
|
44302
|
-
if (chunk.isEntry) {
|
|
44706
|
+
if (chunk.isEntry && !config.build.lib) {
|
|
44303
44707
|
return null;
|
|
44304
44708
|
}
|
|
44305
44709
|
chunkCSS = await finalizeCss(chunkCSS, true, config);
|
|
@@ -44431,8 +44835,8 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44431
44835
|
// crawl them in order to register watch dependencies.
|
|
44432
44836
|
const needInlineImport = code.includes('@import');
|
|
44433
44837
|
const hasUrl = cssUrlRE.test(code) || cssImageSetRE.test(code);
|
|
44434
|
-
const postcssConfig = await resolvePostcssConfig(config);
|
|
44435
44838
|
const lang = id.match(cssLangRE)?.[1];
|
|
44839
|
+
const postcssConfig = await resolvePostcssConfig(config, getCssDialect(lang));
|
|
44436
44840
|
// 1. plain css that needs no processing
|
|
44437
44841
|
if (lang === 'css' &&
|
|
44438
44842
|
!postcssConfig &&
|
|
@@ -44487,9 +44891,13 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44487
44891
|
}
|
|
44488
44892
|
// 3. postcss
|
|
44489
44893
|
const postcssOptions = (postcssConfig && postcssConfig.options) || {};
|
|
44894
|
+
// for sugarss change parser
|
|
44895
|
+
if (lang === 'sss') {
|
|
44896
|
+
postcssOptions.parser = loadPreprocessor("sugarss" /* sss */, config.root);
|
|
44897
|
+
}
|
|
44490
44898
|
const postcssPlugins = postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [];
|
|
44491
44899
|
if (needInlineImport) {
|
|
44492
|
-
postcssPlugins.unshift((await import('./dep-
|
|
44900
|
+
postcssPlugins.unshift((await import('./dep-39e6741e.js').then(function (n) { return n.i; })).default({
|
|
44493
44901
|
async resolve(id, basedir) {
|
|
44494
44902
|
const publicFile = checkPublicFile(id, config);
|
|
44495
44903
|
if (publicFile) {
|
|
@@ -44511,7 +44919,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
44511
44919
|
logger: config.logger
|
|
44512
44920
|
}));
|
|
44513
44921
|
if (isModule) {
|
|
44514
|
-
postcssPlugins.unshift((await import('./dep-
|
|
44922
|
+
postcssPlugins.unshift((await import('./dep-553f6a62.js').then(function (n) { return n.i; })).default({
|
|
44515
44923
|
...modulesOptions,
|
|
44516
44924
|
getJSON(cssFileName, _modules, outputFileName) {
|
|
44517
44925
|
modules = _modules;
|
|
@@ -44659,8 +45067,9 @@ async function finalizeCss(css, minify, config) {
|
|
|
44659
45067
|
}
|
|
44660
45068
|
return css;
|
|
44661
45069
|
}
|
|
44662
|
-
async function resolvePostcssConfig(config) {
|
|
44663
|
-
|
|
45070
|
+
async function resolvePostcssConfig(config, dialect = 'css') {
|
|
45071
|
+
postcssConfigCache[dialect] ?? (postcssConfigCache[dialect] = new WeakMap());
|
|
45072
|
+
let result = postcssConfigCache[dialect].get(config);
|
|
44664
45073
|
if (result !== undefined) {
|
|
44665
45074
|
return result;
|
|
44666
45075
|
}
|
|
@@ -44696,7 +45105,7 @@ async function resolvePostcssConfig(config) {
|
|
|
44696
45105
|
result = null;
|
|
44697
45106
|
}
|
|
44698
45107
|
}
|
|
44699
|
-
postcssConfigCache.set(config, result);
|
|
45108
|
+
postcssConfigCache[dialect].set(config, result);
|
|
44700
45109
|
return result;
|
|
44701
45110
|
}
|
|
44702
45111
|
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
|
|
@@ -44921,8 +45330,8 @@ const scss = async (source, root, options, resolvers) => {
|
|
|
44921
45330
|
const importer = [internalImporter];
|
|
44922
45331
|
if (options.importer) {
|
|
44923
45332
|
Array.isArray(options.importer)
|
|
44924
|
-
? importer.
|
|
44925
|
-
: importer.
|
|
45333
|
+
? importer.unshift(...options.importer)
|
|
45334
|
+
: importer.unshift(options.importer);
|
|
44926
45335
|
}
|
|
44927
45336
|
const { content: data, map: additionalMap } = await getSource(source, options.filename, options.additionalData, options.enableSourcemap);
|
|
44928
45337
|
const finalOptions = {
|
|
@@ -45195,6 +45604,9 @@ const preProcessors = Object.freeze({
|
|
|
45195
45604
|
function isPreProcessor(lang) {
|
|
45196
45605
|
return lang && lang in preProcessors;
|
|
45197
45606
|
}
|
|
45607
|
+
function getCssDialect(lang) {
|
|
45608
|
+
return lang === 'sss' ? 'sss' : 'css';
|
|
45609
|
+
}
|
|
45198
45610
|
|
|
45199
45611
|
function manifestPlugin(config) {
|
|
45200
45612
|
const manifest = {};
|
|
@@ -45281,6 +45693,10 @@ function manifestPlugin(config) {
|
|
|
45281
45693
|
manifest[chunk.name] = createAsset(chunk);
|
|
45282
45694
|
}
|
|
45283
45695
|
}
|
|
45696
|
+
duplicateAssets.get(config).forEach((asset) => {
|
|
45697
|
+
const chunk = createAsset(asset);
|
|
45698
|
+
manifest[asset.name] = chunk;
|
|
45699
|
+
});
|
|
45284
45700
|
outputCount++;
|
|
45285
45701
|
const output = config.build.rollupOptions?.output;
|
|
45286
45702
|
const outputLength = Array.isArray(output) ? output.length : 1;
|
|
@@ -45420,87 +45836,6 @@ function ssrManifestPlugin(config) {
|
|
|
45420
45836
|
};
|
|
45421
45837
|
}
|
|
45422
45838
|
|
|
45423
|
-
/**
|
|
45424
|
-
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
|
|
45425
|
-
*
|
|
45426
|
-
* Supports template string with dynamic segments:
|
|
45427
|
-
* ```
|
|
45428
|
-
* new URL(`./dir/${name}.png`, import.meta.url)
|
|
45429
|
-
* // transformed to
|
|
45430
|
-
* import.meta.glob('./dir/**.png', { eager: true, import: 'default' })[`./dir/${name}.png`]
|
|
45431
|
-
* ```
|
|
45432
|
-
*/
|
|
45433
|
-
function assetImportMetaUrlPlugin(config) {
|
|
45434
|
-
return {
|
|
45435
|
-
name: 'vite:asset-import-meta-url',
|
|
45436
|
-
async transform(code, id, options) {
|
|
45437
|
-
if (!options?.ssr &&
|
|
45438
|
-
id !== preloadHelperId &&
|
|
45439
|
-
code.includes('new URL') &&
|
|
45440
|
-
code.includes(`import.meta.url`)) {
|
|
45441
|
-
let s;
|
|
45442
|
-
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g;
|
|
45443
|
-
const cleanString = stripLiteral(code);
|
|
45444
|
-
let match;
|
|
45445
|
-
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
|
45446
|
-
const { 0: exp, 1: emptyUrl, index } = match;
|
|
45447
|
-
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
45448
|
-
const urlEnd = urlStart + emptyUrl.length;
|
|
45449
|
-
const rawUrl = code.slice(urlStart, urlEnd);
|
|
45450
|
-
if (!s)
|
|
45451
|
-
s = new MagicString(code);
|
|
45452
|
-
// potential dynamic template string
|
|
45453
|
-
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
|
|
45454
|
-
const ast = this.parse(rawUrl);
|
|
45455
|
-
const templateLiteral = ast.body[0].expression;
|
|
45456
|
-
if (templateLiteral.expressions.length) {
|
|
45457
|
-
const pattern = JSON.stringify(buildGlobPattern(templateLiteral));
|
|
45458
|
-
// Note: native import.meta.url is not supported in the baseline
|
|
45459
|
-
// target so we use the global location here. It can be
|
|
45460
|
-
// window.location or self.location in case it is used in a Web Worker.
|
|
45461
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Window/self
|
|
45462
|
-
s.overwrite(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, { contentOnly: true });
|
|
45463
|
-
continue;
|
|
45464
|
-
}
|
|
45465
|
-
}
|
|
45466
|
-
const url = rawUrl.slice(1, -1);
|
|
45467
|
-
const file = path$n.resolve(path$n.dirname(id), url);
|
|
45468
|
-
// Get final asset URL. Catch error if the file does not exist,
|
|
45469
|
-
// in which we can resort to the initial URL and let it resolve in runtime
|
|
45470
|
-
const builtUrl = await fileToUrl(file, config, this).catch(() => {
|
|
45471
|
-
const rawExp = code.slice(index, index + exp.length);
|
|
45472
|
-
config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
|
|
45473
|
-
return url;
|
|
45474
|
-
});
|
|
45475
|
-
s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
|
|
45476
|
-
}
|
|
45477
|
-
if (s) {
|
|
45478
|
-
return transformStableResult(s, id, config);
|
|
45479
|
-
}
|
|
45480
|
-
}
|
|
45481
|
-
return null;
|
|
45482
|
-
}
|
|
45483
|
-
};
|
|
45484
|
-
}
|
|
45485
|
-
function buildGlobPattern(ast) {
|
|
45486
|
-
let pattern = '';
|
|
45487
|
-
let lastElementIndex = -1;
|
|
45488
|
-
for (const exp of ast.expressions) {
|
|
45489
|
-
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
45490
|
-
const el = ast.quasis[i];
|
|
45491
|
-
if (el.end < exp.start) {
|
|
45492
|
-
pattern += el.value.raw;
|
|
45493
|
-
lastElementIndex = i;
|
|
45494
|
-
}
|
|
45495
|
-
}
|
|
45496
|
-
pattern += '**';
|
|
45497
|
-
}
|
|
45498
|
-
for (let i = lastElementIndex + 1; i < ast.quasis.length; i++) {
|
|
45499
|
-
pattern += ast.quasis[i].value.raw;
|
|
45500
|
-
}
|
|
45501
|
-
return pattern;
|
|
45502
|
-
}
|
|
45503
|
-
|
|
45504
45839
|
/**
|
|
45505
45840
|
* A plugin to provide build load fallback for arbitrary request with queries.
|
|
45506
45841
|
*/
|
|
@@ -45554,9 +45889,24 @@ function completeSystemWrapPlugin() {
|
|
|
45554
45889
|
}
|
|
45555
45890
|
|
|
45556
45891
|
function resolveBuildOptions(raw, isBuild, logger) {
|
|
45892
|
+
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload;
|
|
45893
|
+
if (raw) {
|
|
45894
|
+
const { polyfillModulePreload, ...rest } = raw;
|
|
45895
|
+
raw = rest;
|
|
45896
|
+
if (deprecatedPolyfillModulePreload !== undefined) {
|
|
45897
|
+
logger.warn('polyfillModulePreload is deprecated. Use modulePreload.polyfill instead.');
|
|
45898
|
+
}
|
|
45899
|
+
if (deprecatedPolyfillModulePreload === false &&
|
|
45900
|
+
raw.modulePreload === undefined) {
|
|
45901
|
+
raw.modulePreload = { polyfill: false };
|
|
45902
|
+
}
|
|
45903
|
+
}
|
|
45904
|
+
const modulePreload = raw?.modulePreload;
|
|
45905
|
+
const defaultModulePreload = {
|
|
45906
|
+
polyfill: true
|
|
45907
|
+
};
|
|
45557
45908
|
const resolved = {
|
|
45558
45909
|
target: 'modules',
|
|
45559
|
-
polyfillModulePreload: true,
|
|
45560
45910
|
outDir: 'dist',
|
|
45561
45911
|
assetsDir: 'assets',
|
|
45562
45912
|
assetsInlineLimit: 4096,
|
|
@@ -45585,7 +45935,16 @@ function resolveBuildOptions(raw, isBuild, logger) {
|
|
|
45585
45935
|
warnOnError: true,
|
|
45586
45936
|
exclude: [/node_modules/],
|
|
45587
45937
|
...raw?.dynamicImportVarsOptions
|
|
45588
|
-
}
|
|
45938
|
+
},
|
|
45939
|
+
// Resolve to false | object
|
|
45940
|
+
modulePreload: modulePreload === false
|
|
45941
|
+
? false
|
|
45942
|
+
: typeof modulePreload === 'object'
|
|
45943
|
+
? {
|
|
45944
|
+
...defaultModulePreload,
|
|
45945
|
+
...modulePreload
|
|
45946
|
+
}
|
|
45947
|
+
: defaultModulePreload
|
|
45589
45948
|
};
|
|
45590
45949
|
// handle special build targets
|
|
45591
45950
|
if (resolved.target === 'modules') {
|
|
@@ -45619,7 +45978,6 @@ function resolveBuildPlugins(config) {
|
|
|
45619
45978
|
watchPackageDataPlugin(config),
|
|
45620
45979
|
...(usePluginCommonjs ? [commonjs(options.commonjsOptions)] : []),
|
|
45621
45980
|
dataURIPlugin(),
|
|
45622
|
-
assetImportMetaUrlPlugin(config),
|
|
45623
45981
|
...(options.rollupOptions.plugins
|
|
45624
45982
|
? options.rollupOptions.plugins.filter(Boolean)
|
|
45625
45983
|
: [])
|
|
@@ -45668,7 +46026,15 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45668
46026
|
config.logger.info(picocolors.exports.cyan(`vite v${VERSION} ${picocolors.exports.green(`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`)}`));
|
|
45669
46027
|
const resolve = (p) => path$n.resolve(config.root, p);
|
|
45670
46028
|
const input = libOptions
|
|
45671
|
-
? options.rollupOptions?.input ||
|
|
46029
|
+
? options.rollupOptions?.input ||
|
|
46030
|
+
(typeof libOptions.entry === 'string'
|
|
46031
|
+
? resolve(libOptions.entry)
|
|
46032
|
+
: Array.isArray(libOptions.entry)
|
|
46033
|
+
? libOptions.entry.map(resolve)
|
|
46034
|
+
: Object.fromEntries(Object.entries(libOptions.entry).map(([alias, file]) => [
|
|
46035
|
+
alias,
|
|
46036
|
+
resolve(file)
|
|
46037
|
+
])))
|
|
45672
46038
|
: typeof options.ssr === 'string'
|
|
45673
46039
|
? resolve(options.ssr)
|
|
45674
46040
|
: options.rollupOptions?.input || resolve('index.html');
|
|
@@ -45745,7 +46111,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45745
46111
|
entryFileNames: ssr
|
|
45746
46112
|
? `[name].${jsExt}`
|
|
45747
46113
|
: libOptions
|
|
45748
|
-
? resolveLibFilename(libOptions, format, config.root, jsExt)
|
|
46114
|
+
? ({ name }) => resolveLibFilename(libOptions, format, name, config.root, jsExt)
|
|
45749
46115
|
: path$n.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
|
|
45750
46116
|
chunkFileNames: libOptions
|
|
45751
46117
|
? `[name].[hash].${jsExt}`
|
|
@@ -45762,23 +46128,24 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45762
46128
|
};
|
|
45763
46129
|
// resolve lib mode outputs
|
|
45764
46130
|
const outputs = resolveBuildOutputs(options.rollupOptions?.output, libOptions, config.logger);
|
|
46131
|
+
const normalizedOutputs = [];
|
|
46132
|
+
if (Array.isArray(outputs)) {
|
|
46133
|
+
for (const resolvedOutput of outputs) {
|
|
46134
|
+
normalizedOutputs.push(buildOutputOptions(resolvedOutput));
|
|
46135
|
+
}
|
|
46136
|
+
}
|
|
46137
|
+
else {
|
|
46138
|
+
normalizedOutputs.push(buildOutputOptions(outputs));
|
|
46139
|
+
}
|
|
46140
|
+
const outDirs = normalizedOutputs.map(({ dir }) => resolve(dir));
|
|
45765
46141
|
// watch file changes with rollup
|
|
45766
46142
|
if (config.build.watch) {
|
|
45767
46143
|
config.logger.info(picocolors.exports.cyan(`\nwatching for file changes...`));
|
|
45768
|
-
const output = [];
|
|
45769
|
-
if (Array.isArray(outputs)) {
|
|
45770
|
-
for (const resolvedOutput of outputs) {
|
|
45771
|
-
output.push(buildOutputOptions(resolvedOutput));
|
|
45772
|
-
}
|
|
45773
|
-
}
|
|
45774
|
-
else {
|
|
45775
|
-
output.push(buildOutputOptions(outputs));
|
|
45776
|
-
}
|
|
45777
46144
|
const resolvedChokidarOptions = resolveChokidarOptions(config.build.watch.chokidar);
|
|
45778
46145
|
const { watch } = await import('rollup');
|
|
45779
46146
|
const watcher = watch({
|
|
45780
46147
|
...rollupOptions,
|
|
45781
|
-
output,
|
|
46148
|
+
output: normalizedOutputs,
|
|
45782
46149
|
watch: {
|
|
45783
46150
|
...config.build.watch,
|
|
45784
46151
|
chokidar: resolvedChokidarOptions
|
|
@@ -45788,7 +46155,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45788
46155
|
if (event.code === 'BUNDLE_START') {
|
|
45789
46156
|
config.logger.info(picocolors.exports.cyan(`\nbuild started...`));
|
|
45790
46157
|
if (options.write) {
|
|
45791
|
-
prepareOutDir(
|
|
46158
|
+
prepareOutDir(outDirs, options.emptyOutDir, config);
|
|
45792
46159
|
}
|
|
45793
46160
|
}
|
|
45794
46161
|
else if (event.code === 'BUNDLE_END') {
|
|
@@ -45806,41 +46173,56 @@ async function doBuild(inlineConfig = {}) {
|
|
|
45806
46173
|
const bundle = await rollup(rollupOptions);
|
|
45807
46174
|
parallelBuilds.push(bundle);
|
|
45808
46175
|
const generate = (output = {}) => {
|
|
45809
|
-
return bundle[options.write ? 'write' : 'generate'](
|
|
46176
|
+
return bundle[options.write ? 'write' : 'generate'](output);
|
|
45810
46177
|
};
|
|
45811
46178
|
if (options.write) {
|
|
45812
|
-
prepareOutDir(
|
|
46179
|
+
prepareOutDir(outDirs, options.emptyOutDir, config);
|
|
45813
46180
|
}
|
|
45814
|
-
|
|
45815
|
-
|
|
45816
|
-
|
|
45817
|
-
res.push(await generate(output));
|
|
45818
|
-
}
|
|
45819
|
-
return res;
|
|
45820
|
-
}
|
|
45821
|
-
else {
|
|
45822
|
-
return await generate(outputs);
|
|
46181
|
+
const res = [];
|
|
46182
|
+
for (const output of normalizedOutputs) {
|
|
46183
|
+
res.push(await generate(output));
|
|
45823
46184
|
}
|
|
46185
|
+
return Array.isArray(outputs) ? res : res[0];
|
|
45824
46186
|
}
|
|
45825
46187
|
catch (e) {
|
|
45826
46188
|
outputBuildError(e);
|
|
45827
46189
|
throw e;
|
|
45828
46190
|
}
|
|
45829
46191
|
}
|
|
45830
|
-
function prepareOutDir(
|
|
45831
|
-
|
|
45832
|
-
|
|
45833
|
-
|
|
45834
|
-
|
|
45835
|
-
|
|
45836
|
-
|
|
45837
|
-
|
|
45838
|
-
|
|
45839
|
-
|
|
46192
|
+
function prepareOutDir(outDirs, emptyOutDir, config) {
|
|
46193
|
+
const nonDuplicateDirs = new Set(outDirs);
|
|
46194
|
+
let outside = false;
|
|
46195
|
+
if (emptyOutDir == null) {
|
|
46196
|
+
for (const outDir of nonDuplicateDirs) {
|
|
46197
|
+
if (fs$l.existsSync(outDir) &&
|
|
46198
|
+
!normalizePath$3(outDir).startsWith(config.root + '/')) {
|
|
46199
|
+
// warn if outDir is outside of root
|
|
46200
|
+
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` +
|
|
46201
|
+
`Use --emptyOutDir to override.\n`));
|
|
46202
|
+
outside = true;
|
|
46203
|
+
break;
|
|
46204
|
+
}
|
|
45840
46205
|
}
|
|
45841
46206
|
}
|
|
45842
|
-
|
|
45843
|
-
|
|
46207
|
+
for (const outDir of nonDuplicateDirs) {
|
|
46208
|
+
if (!outside && emptyOutDir !== false && fs$l.existsSync(outDir)) {
|
|
46209
|
+
// skip those other outDirs which are nested in current outDir
|
|
46210
|
+
const skipDirs = outDirs
|
|
46211
|
+
.map((dir) => {
|
|
46212
|
+
const relative = path$n.relative(outDir, dir);
|
|
46213
|
+
if (relative &&
|
|
46214
|
+
!relative.startsWith('..') &&
|
|
46215
|
+
!path$n.isAbsolute(relative)) {
|
|
46216
|
+
return relative;
|
|
46217
|
+
}
|
|
46218
|
+
return '';
|
|
46219
|
+
})
|
|
46220
|
+
.filter(Boolean);
|
|
46221
|
+
emptyDir(outDir, [...skipDirs, '.git']);
|
|
46222
|
+
}
|
|
46223
|
+
if (config.publicDir && fs$l.existsSync(config.publicDir)) {
|
|
46224
|
+
copyDir(config.publicDir, outDir);
|
|
46225
|
+
}
|
|
45844
46226
|
}
|
|
45845
46227
|
}
|
|
45846
46228
|
function getPkgJson(root) {
|
|
@@ -45857,12 +46239,15 @@ function resolveOutputJsExtension(format, type = 'commonjs') {
|
|
|
45857
46239
|
return format === 'es' ? 'mjs' : 'js';
|
|
45858
46240
|
}
|
|
45859
46241
|
}
|
|
45860
|
-
function resolveLibFilename(libOptions, format, root, extension) {
|
|
46242
|
+
function resolveLibFilename(libOptions, format, entryName, root, extension) {
|
|
45861
46243
|
if (typeof libOptions.fileName === 'function') {
|
|
45862
|
-
return libOptions.fileName(format);
|
|
46244
|
+
return libOptions.fileName(format, entryName);
|
|
45863
46245
|
}
|
|
45864
46246
|
const packageJson = getPkgJson(root);
|
|
45865
|
-
const name = libOptions.fileName ||
|
|
46247
|
+
const name = libOptions.fileName ||
|
|
46248
|
+
(typeof libOptions.entry === 'string'
|
|
46249
|
+
? getPkgName(packageJson.name)
|
|
46250
|
+
: entryName);
|
|
45866
46251
|
if (!name)
|
|
45867
46252
|
throw new Error('Name in package.json is required if option "build.lib.fileName" is not provided.');
|
|
45868
46253
|
extension ?? (extension = resolveOutputJsExtension(format, packageJson.type));
|
|
@@ -45874,10 +46259,15 @@ function resolveLibFilename(libOptions, format, root, extension) {
|
|
|
45874
46259
|
function resolveBuildOutputs(outputs, libOptions, logger) {
|
|
45875
46260
|
if (libOptions) {
|
|
45876
46261
|
const formats = libOptions.formats || ['es', 'umd'];
|
|
45877
|
-
if (
|
|
45878
|
-
|
|
45879
|
-
|
|
45880
|
-
`include "umd" or "iife".`);
|
|
46262
|
+
if (formats.includes('umd') || formats.includes('iife')) {
|
|
46263
|
+
if (typeof libOptions.entry !== 'string' &&
|
|
46264
|
+
Object.values(libOptions.entry).length > 1) {
|
|
46265
|
+
throw new Error(`Multiple entry points are not supported when output formats include "umd" or "iife".`);
|
|
46266
|
+
}
|
|
46267
|
+
if (!libOptions.name) {
|
|
46268
|
+
throw new Error(`Option "build.lib.name" is required when output formats ` +
|
|
46269
|
+
`include "umd" or "iife".`);
|
|
46270
|
+
}
|
|
45881
46271
|
}
|
|
45882
46272
|
if (!outputs) {
|
|
45883
46273
|
return formats.map((format) => ({ format }));
|
|
@@ -46061,7 +46451,7 @@ const relativeUrlMechanisms = {
|
|
|
46061
46451
|
system: (relativePath) => getResolveUrl(`'${relativePath}', module.meta.url`),
|
|
46062
46452
|
umd: (relativePath) => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getResolveUrl(`'file:' + __dirname + '/${relativePath}'`, `(require('u' + 'rl').URL)`)} : ${getRelativeUrlFromDocument(relativePath, true)})`
|
|
46063
46453
|
};
|
|
46064
|
-
function
|
|
46454
|
+
function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
|
|
46065
46455
|
const { renderBuiltUrl } = config.experimental;
|
|
46066
46456
|
let relative = config.base === '' || config.base === './';
|
|
46067
46457
|
if (renderBuiltUrl) {
|
|
@@ -46088,7 +46478,7 @@ function toOutputFilePathInString(filename, type, hostId, hostType, config, form
|
|
|
46088
46478
|
}
|
|
46089
46479
|
return config.base + filename;
|
|
46090
46480
|
}
|
|
46091
|
-
function
|
|
46481
|
+
function createToImportMetaURLBasedRelativeRuntime(format) {
|
|
46092
46482
|
const toRelativePath = relativeUrlMechanisms[format];
|
|
46093
46483
|
return (filename, importer) => ({
|
|
46094
46484
|
runtime: toRelativePath(path$n.posix.relative(path$n.dirname(importer), filename))
|
|
@@ -46133,7 +46523,8 @@ var build$1 = {
|
|
|
46133
46523
|
build: build,
|
|
46134
46524
|
resolveLibFilename: resolveLibFilename,
|
|
46135
46525
|
onRollupWarning: onRollupWarning,
|
|
46136
|
-
|
|
46526
|
+
toOutputFilePathInJS: toOutputFilePathInJS,
|
|
46527
|
+
createToImportMetaURLBasedRelativeRuntime: createToImportMetaURLBasedRelativeRuntime,
|
|
46137
46528
|
toOutputFilePathWithoutRuntime: toOutputFilePathWithoutRuntime,
|
|
46138
46529
|
toOutputFilePathInCss: toOutputFilePathInCss,
|
|
46139
46530
|
toOutputFilePathInHtml: toOutputFilePathInHtml
|
|
@@ -48936,7 +49327,7 @@ const fs$9 = require$$0__default;
|
|
|
48936
49327
|
const { Readable } = require$$0$7;
|
|
48937
49328
|
const sysPath$3 = require$$0$4;
|
|
48938
49329
|
const { promisify: promisify$3 } = require$$0$6;
|
|
48939
|
-
const picomatch$1 = picomatch$
|
|
49330
|
+
const picomatch$1 = picomatch$5.exports;
|
|
48940
49331
|
|
|
48941
49332
|
const readdir$1 = promisify$3(fs$9.readdir);
|
|
48942
49333
|
const stat$3 = promisify$3(fs$9.stat);
|
|
@@ -49258,7 +49649,7 @@ var normalizePath$2 = function(path, stripTrailing) {
|
|
|
49258
49649
|
|
|
49259
49650
|
Object.defineProperty(anymatch$2.exports, "__esModule", { value: true });
|
|
49260
49651
|
|
|
49261
|
-
const picomatch = picomatch$
|
|
49652
|
+
const picomatch = picomatch$5.exports;
|
|
49262
49653
|
const normalizePath$1 = normalizePath$2;
|
|
49263
49654
|
|
|
49264
49655
|
/**
|
|
@@ -52500,7 +52891,7 @@ async function resolveHttpServer({ proxy }, app, httpsOptions) {
|
|
|
52500
52891
|
app);
|
|
52501
52892
|
}
|
|
52502
52893
|
}
|
|
52503
|
-
async function resolveHttpsConfig(https
|
|
52894
|
+
async function resolveHttpsConfig(https) {
|
|
52504
52895
|
if (!https)
|
|
52505
52896
|
return undefined;
|
|
52506
52897
|
const httpsOption = isObject$2(https) ? { ...https } : {};
|
|
@@ -53062,35 +53453,35 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
|
|
|
53062
53453
|
function isInScope(name, parents) {
|
|
53063
53454
|
return parents.some((node) => node && scopeMap.get(node)?.has(name));
|
|
53064
53455
|
}
|
|
53065
|
-
function handlePattern(p,
|
|
53456
|
+
function handlePattern(p, parentScope) {
|
|
53066
53457
|
if (p.type === 'Identifier') {
|
|
53067
|
-
setScope(
|
|
53458
|
+
setScope(parentScope, p.name);
|
|
53068
53459
|
}
|
|
53069
53460
|
else if (p.type === 'RestElement') {
|
|
53070
|
-
handlePattern(p.argument,
|
|
53461
|
+
handlePattern(p.argument, parentScope);
|
|
53071
53462
|
}
|
|
53072
53463
|
else if (p.type === 'ObjectPattern') {
|
|
53073
53464
|
p.properties.forEach((property) => {
|
|
53074
53465
|
if (property.type === 'RestElement') {
|
|
53075
|
-
setScope(
|
|
53466
|
+
setScope(parentScope, property.argument.name);
|
|
53076
53467
|
}
|
|
53077
53468
|
else {
|
|
53078
|
-
handlePattern(property.value,
|
|
53469
|
+
handlePattern(property.value, parentScope);
|
|
53079
53470
|
}
|
|
53080
53471
|
});
|
|
53081
53472
|
}
|
|
53082
53473
|
else if (p.type === 'ArrayPattern') {
|
|
53083
53474
|
p.elements.forEach((element) => {
|
|
53084
53475
|
if (element) {
|
|
53085
|
-
handlePattern(element,
|
|
53476
|
+
handlePattern(element, parentScope);
|
|
53086
53477
|
}
|
|
53087
53478
|
});
|
|
53088
53479
|
}
|
|
53089
53480
|
else if (p.type === 'AssignmentPattern') {
|
|
53090
|
-
handlePattern(p.left,
|
|
53481
|
+
handlePattern(p.left, parentScope);
|
|
53091
53482
|
}
|
|
53092
53483
|
else {
|
|
53093
|
-
setScope(
|
|
53484
|
+
setScope(parentScope, p.name);
|
|
53094
53485
|
}
|
|
53095
53486
|
}
|
|
53096
53487
|
walk$1(root, {
|
|
@@ -53098,7 +53489,12 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
|
|
|
53098
53489
|
if (node.type === 'ImportDeclaration') {
|
|
53099
53490
|
return this.skip();
|
|
53100
53491
|
}
|
|
53101
|
-
parent
|
|
53492
|
+
// track parent stack, skip for "else-if"/"else" branches as acorn nests
|
|
53493
|
+
// the ast within "if" nodes instead of flattening them
|
|
53494
|
+
if (parent &&
|
|
53495
|
+
!(parent.type === 'IfStatement' && node === parent.alternate)) {
|
|
53496
|
+
parentStack.unshift(parent);
|
|
53497
|
+
}
|
|
53102
53498
|
if (node.type === 'MetaProperty' && node.meta.name === 'import') {
|
|
53103
53499
|
onImportMeta(node);
|
|
53104
53500
|
}
|
|
@@ -53116,9 +53512,9 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
|
|
|
53116
53512
|
// If it is a function declaration, it could be shadowing an import
|
|
53117
53513
|
// Add its name to the scope so it won't get replaced
|
|
53118
53514
|
if (node.type === 'FunctionDeclaration') {
|
|
53119
|
-
const
|
|
53120
|
-
if (
|
|
53121
|
-
setScope(
|
|
53515
|
+
const parentScope = findParentScope(parentStack);
|
|
53516
|
+
if (parentScope) {
|
|
53517
|
+
setScope(parentScope, node.id.name);
|
|
53122
53518
|
}
|
|
53123
53519
|
}
|
|
53124
53520
|
// walk function expressions and add its arguments to known identifiers
|
|
@@ -53157,14 +53553,18 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
|
|
|
53157
53553
|
setIsNodeInPattern(node);
|
|
53158
53554
|
}
|
|
53159
53555
|
else if (node.type === 'VariableDeclarator') {
|
|
53160
|
-
const parentFunction =
|
|
53556
|
+
const parentFunction = findParentScope(parentStack);
|
|
53161
53557
|
if (parentFunction) {
|
|
53162
53558
|
handlePattern(node.id, parentFunction);
|
|
53163
53559
|
}
|
|
53164
53560
|
}
|
|
53165
53561
|
},
|
|
53166
53562
|
leave(node, parent) {
|
|
53167
|
-
parent
|
|
53563
|
+
// untrack parent stack from above
|
|
53564
|
+
if (parent &&
|
|
53565
|
+
!(parent.type === 'IfStatement' && node === parent.alternate)) {
|
|
53566
|
+
parentStack.shift();
|
|
53567
|
+
}
|
|
53168
53568
|
}
|
|
53169
53569
|
});
|
|
53170
53570
|
// emit the identifier events in BFS so the hoisted declarations
|
|
@@ -53226,11 +53626,13 @@ function isRefIdentifier(id, parent, parentStack) {
|
|
|
53226
53626
|
}
|
|
53227
53627
|
const isStaticProperty = (node) => node && node.type === 'Property' && !node.computed;
|
|
53228
53628
|
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
53629
|
+
const functionNodeTypeRE = /Function(?:Expression|Declaration)$|Method$/;
|
|
53229
53630
|
function isFunction(node) {
|
|
53230
|
-
return
|
|
53631
|
+
return functionNodeTypeRE.test(node.type);
|
|
53231
53632
|
}
|
|
53232
|
-
|
|
53233
|
-
|
|
53633
|
+
const scopeNodeTypeRE = /(?:Function|Class)(?:Expression|Declaration)$|Method$|^IfStatement$/;
|
|
53634
|
+
function findParentScope(parentStack) {
|
|
53635
|
+
return parentStack.find((i) => scopeNodeTypeRE.test(i.type));
|
|
53234
53636
|
}
|
|
53235
53637
|
function isInDestructuringAssignment(parent, parentStack) {
|
|
53236
53638
|
if (parent &&
|
|
@@ -53353,13 +53755,15 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
|
|
|
53353
53755
|
// CommonJS modules are preferred. We want to avoid ESM->ESM imports
|
|
53354
53756
|
// whenever possible, because `hookNodeResolve` can't intercept them.
|
|
53355
53757
|
const resolveOptions = {
|
|
53356
|
-
|
|
53758
|
+
mainFields: ['main'],
|
|
53759
|
+
browserField: true,
|
|
53760
|
+
conditions: [],
|
|
53357
53761
|
extensions: ['.js', '.cjs', '.json'],
|
|
53762
|
+
dedupe,
|
|
53763
|
+
preserveSymlinks,
|
|
53358
53764
|
isBuild: true,
|
|
53359
53765
|
isProduction,
|
|
53360
53766
|
isRequire: true,
|
|
53361
|
-
mainFields: ['main'],
|
|
53362
|
-
preserveSymlinks,
|
|
53363
53767
|
root
|
|
53364
53768
|
};
|
|
53365
53769
|
// Since dynamic imports can happen in parallel, we need to
|
|
@@ -56578,20 +56982,20 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56578
56982
|
}
|
|
56579
56983
|
|
|
56580
56984
|
const isSecure = parsedUrl.protocol === 'wss:';
|
|
56581
|
-
const
|
|
56582
|
-
let
|
|
56985
|
+
const isIpcUrl = parsedUrl.protocol === 'ws+unix:';
|
|
56986
|
+
let invalidUrlMessage;
|
|
56583
56987
|
|
|
56584
|
-
if (parsedUrl.protocol !== 'ws:' && !isSecure && !
|
|
56585
|
-
|
|
56988
|
+
if (parsedUrl.protocol !== 'ws:' && !isSecure && !isIpcUrl) {
|
|
56989
|
+
invalidUrlMessage =
|
|
56586
56990
|
'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"';
|
|
56587
|
-
} else if (
|
|
56588
|
-
|
|
56991
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
56992
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
56589
56993
|
} else if (parsedUrl.hash) {
|
|
56590
|
-
|
|
56994
|
+
invalidUrlMessage = 'The URL contains a fragment identifier';
|
|
56591
56995
|
}
|
|
56592
56996
|
|
|
56593
|
-
if (
|
|
56594
|
-
const err = new SyntaxError(
|
|
56997
|
+
if (invalidUrlMessage) {
|
|
56998
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
56595
56999
|
|
|
56596
57000
|
if (websocket._redirects === 0) {
|
|
56597
57001
|
throw err;
|
|
@@ -56661,7 +57065,7 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56661
57065
|
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
56662
57066
|
}
|
|
56663
57067
|
|
|
56664
|
-
if (
|
|
57068
|
+
if (isIpcUrl) {
|
|
56665
57069
|
const parts = opts.path.split(':');
|
|
56666
57070
|
|
|
56667
57071
|
opts.socketPath = parts[0];
|
|
@@ -56672,9 +57076,9 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56672
57076
|
|
|
56673
57077
|
if (opts.followRedirects) {
|
|
56674
57078
|
if (websocket._redirects === 0) {
|
|
56675
|
-
websocket.
|
|
57079
|
+
websocket._originalIpc = isIpcUrl;
|
|
56676
57080
|
websocket._originalSecure = isSecure;
|
|
56677
|
-
websocket._originalHostOrSocketPath =
|
|
57081
|
+
websocket._originalHostOrSocketPath = isIpcUrl
|
|
56678
57082
|
? opts.socketPath
|
|
56679
57083
|
: parsedUrl.host;
|
|
56680
57084
|
|
|
@@ -56692,11 +57096,11 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
56692
57096
|
}
|
|
56693
57097
|
}
|
|
56694
57098
|
} else if (websocket.listenerCount('redirect') === 0) {
|
|
56695
|
-
const isSameHost =
|
|
56696
|
-
? websocket.
|
|
57099
|
+
const isSameHost = isIpcUrl
|
|
57100
|
+
? websocket._originalIpc
|
|
56697
57101
|
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
56698
57102
|
: false
|
|
56699
|
-
: websocket.
|
|
57103
|
+
: websocket._originalIpc
|
|
56700
57104
|
? false
|
|
56701
57105
|
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
56702
57106
|
|
|
@@ -60286,9 +60690,9 @@ var lib = {exports: {}};
|
|
|
60286
60690
|
|
|
60287
60691
|
var history = lib.exports;
|
|
60288
60692
|
|
|
60289
|
-
function
|
|
60290
|
-
const
|
|
60291
|
-
logger: createDebugger('vite:
|
|
60693
|
+
function htmlFallbackMiddleware(root, spaFallback) {
|
|
60694
|
+
const historyHtmlFallbackMiddleware = history({
|
|
60695
|
+
logger: createDebugger('vite:html-fallback'),
|
|
60292
60696
|
// support /dir/ without explicit index.html
|
|
60293
60697
|
rewrites: [
|
|
60294
60698
|
{
|
|
@@ -60299,15 +60703,17 @@ function spaFallbackMiddleware(root) {
|
|
|
60299
60703
|
return rewritten;
|
|
60300
60704
|
}
|
|
60301
60705
|
else {
|
|
60302
|
-
|
|
60706
|
+
if (spaFallback) {
|
|
60707
|
+
return `/index.html`;
|
|
60708
|
+
}
|
|
60303
60709
|
}
|
|
60304
60710
|
}
|
|
60305
60711
|
}
|
|
60306
60712
|
]
|
|
60307
60713
|
});
|
|
60308
60714
|
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
60309
|
-
return function
|
|
60310
|
-
return
|
|
60715
|
+
return function viteHtmlFallbackMiddleware(req, res, next) {
|
|
60716
|
+
return historyHtmlFallbackMiddleware(req, res, next);
|
|
60311
60717
|
};
|
|
60312
60718
|
}
|
|
60313
60719
|
|
|
@@ -60672,7 +61078,7 @@ function indexHtmlMiddleware(server) {
|
|
|
60672
61078
|
return next();
|
|
60673
61079
|
}
|
|
60674
61080
|
const url = req.url && cleanUrl(req.url);
|
|
60675
|
-
//
|
|
61081
|
+
// htmlFallbackMiddleware appends '.html' to URLs
|
|
60676
61082
|
if (url?.endsWith('.html') && req.headers['sec-fetch-dest'] !== 'script') {
|
|
60677
61083
|
const filename = getHtmlFilename(url, server);
|
|
60678
61084
|
if (fs$l.existsSync(filename)) {
|
|
@@ -62131,6 +62537,8 @@ async function createServer(inlineConfig = {}) {
|
|
|
62131
62537
|
watcher.close(),
|
|
62132
62538
|
ws.close(),
|
|
62133
62539
|
container.close(),
|
|
62540
|
+
getDepsOptimizer(server.config)?.close(),
|
|
62541
|
+
getDepsOptimizer(server.config, true)?.close(),
|
|
62134
62542
|
closeHttpServer()
|
|
62135
62543
|
]);
|
|
62136
62544
|
server.resolvedUrls = null;
|
|
@@ -62160,7 +62568,8 @@ async function createServer(inlineConfig = {}) {
|
|
|
62160
62568
|
_restartPromise: null,
|
|
62161
62569
|
_importGlobMap: new Map(),
|
|
62162
62570
|
_forceOptimizeOnRestart: false,
|
|
62163
|
-
_pendingRequests: new Map()
|
|
62571
|
+
_pendingRequests: new Map(),
|
|
62572
|
+
_fsDenyGlob: picomatch$3(config.server.fs.deny, { matchBase: true })
|
|
62164
62573
|
};
|
|
62165
62574
|
server.transformIndexHtml = createDevHtmlTransformFn(server);
|
|
62166
62575
|
if (!middlewareMode) {
|
|
@@ -62210,6 +62619,13 @@ async function createServer(inlineConfig = {}) {
|
|
|
62210
62619
|
watcher.on('unlink', (file) => {
|
|
62211
62620
|
handleFileAddUnlink(normalizePath$3(file), server);
|
|
62212
62621
|
});
|
|
62622
|
+
ws.on('vite:invalidate', async ({ path }) => {
|
|
62623
|
+
const mod = moduleGraph.urlToModuleMap.get(path);
|
|
62624
|
+
if (mod && mod.isSelfAccepting && mod.lastHMRTimestamp > 0) {
|
|
62625
|
+
const file = getShortName(mod.file, config.root);
|
|
62626
|
+
updateModules(file, [...mod.importers], mod.lastHMRTimestamp, server);
|
|
62627
|
+
}
|
|
62628
|
+
});
|
|
62213
62629
|
if (!middlewareMode && httpServer) {
|
|
62214
62630
|
httpServer.once('listening', () => {
|
|
62215
62631
|
// update actual port since this may be different from initial value
|
|
@@ -62254,9 +62670,9 @@ async function createServer(inlineConfig = {}) {
|
|
|
62254
62670
|
// serve static files
|
|
62255
62671
|
middlewares.use(serveRawFsMiddleware(server));
|
|
62256
62672
|
middlewares.use(serveStaticMiddleware(root, server));
|
|
62257
|
-
//
|
|
62258
|
-
if (config.appType === 'spa') {
|
|
62259
|
-
middlewares.use(
|
|
62673
|
+
// html fallback
|
|
62674
|
+
if (config.appType === 'spa' || config.appType === 'mpa') {
|
|
62675
|
+
middlewares.use(htmlFallbackMiddleware(root, config.appType === 'spa'));
|
|
62260
62676
|
}
|
|
62261
62677
|
// run post config hooks
|
|
62262
62678
|
// This is applied before the html middleware so that user middleware can
|
|
@@ -62885,10 +63301,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
|
62885
63301
|
prefixes = arraify(prefixes);
|
|
62886
63302
|
const env = {};
|
|
62887
63303
|
const envFiles = [
|
|
62888
|
-
/**
|
|
62889
|
-
/** mode file */ `.env.${mode}`,
|
|
63304
|
+
/** default file */ `.env`,
|
|
62890
63305
|
/** local file */ `.env.local`,
|
|
62891
|
-
/**
|
|
63306
|
+
/** mode file */ `.env.${mode}`,
|
|
63307
|
+
/** mode local file */ `.env.${mode}.local`
|
|
62892
63308
|
];
|
|
62893
63309
|
// check if there are actual env variables starting with VITE_*
|
|
62894
63310
|
// these are typically provided inline and should be prioritized
|
|
@@ -62898,30 +63314,32 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
|
62898
63314
|
env[key] = process.env[key];
|
|
62899
63315
|
}
|
|
62900
63316
|
}
|
|
62901
|
-
|
|
62902
|
-
const path = lookupFile(envDir, [file], {
|
|
62903
|
-
|
|
62904
|
-
|
|
62905
|
-
|
|
62906
|
-
|
|
62907
|
-
|
|
62908
|
-
|
|
62909
|
-
|
|
62910
|
-
|
|
62911
|
-
|
|
62912
|
-
|
|
62913
|
-
|
|
62914
|
-
|
|
62915
|
-
|
|
62916
|
-
|
|
62917
|
-
|
|
62918
|
-
|
|
62919
|
-
|
|
62920
|
-
|
|
62921
|
-
|
|
62922
|
-
|
|
62923
|
-
|
|
62924
|
-
|
|
63317
|
+
const parsed = Object.fromEntries(envFiles.flatMap((file) => {
|
|
63318
|
+
const path = lookupFile(envDir, [file], {
|
|
63319
|
+
pathOnly: true,
|
|
63320
|
+
rootDir: envDir
|
|
63321
|
+
});
|
|
63322
|
+
if (!path)
|
|
63323
|
+
return [];
|
|
63324
|
+
return Object.entries(main$1.exports.parse(fs$l.readFileSync(path), {
|
|
63325
|
+
debug: process.env.DEBUG?.includes('vite:dotenv')
|
|
63326
|
+
}));
|
|
63327
|
+
}));
|
|
63328
|
+
// let environment variables use each other
|
|
63329
|
+
main({
|
|
63330
|
+
parsed,
|
|
63331
|
+
// prevent process.env mutation
|
|
63332
|
+
ignoreProcessEnv: true
|
|
63333
|
+
});
|
|
63334
|
+
// only keys that start with prefix are exposed to client
|
|
63335
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
63336
|
+
if (prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
63337
|
+
env[key] = value;
|
|
63338
|
+
}
|
|
63339
|
+
else if (key === 'NODE_ENV' &&
|
|
63340
|
+
process.env.VITE_USER_NODE_ENV === undefined) {
|
|
63341
|
+
// NODE_ENV override in .env file
|
|
63342
|
+
process.env.VITE_USER_NODE_ENV = value;
|
|
62925
63343
|
}
|
|
62926
63344
|
}
|
|
62927
63345
|
return env;
|
|
@@ -62934,7 +63352,7 @@ function resolveEnvPrefix({ envPrefix = 'VITE_' }) {
|
|
|
62934
63352
|
return envPrefix;
|
|
62935
63353
|
}
|
|
62936
63354
|
|
|
62937
|
-
function resolveSSROptions(ssr,
|
|
63355
|
+
function resolveSSROptions(ssr, preserveSymlinks, buildSsrCjsExternalHeuristics) {
|
|
62938
63356
|
ssr ?? (ssr = {});
|
|
62939
63357
|
const optimizeDeps = ssr.optimizeDeps ?? {};
|
|
62940
63358
|
let format = 'esm';
|
|
@@ -63065,7 +63483,12 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63065
63483
|
// replacement, but its implementation does work with function values.
|
|
63066
63484
|
clientAlias, config.resolve?.alias || []));
|
|
63067
63485
|
const resolveOptions = {
|
|
63068
|
-
|
|
63486
|
+
mainFields: config.resolve?.mainFields ?? DEFAULT_MAIN_FIELDS,
|
|
63487
|
+
browserField: config.resolve?.browserField ?? true,
|
|
63488
|
+
conditions: config.resolve?.conditions ?? [],
|
|
63489
|
+
extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS$1,
|
|
63490
|
+
dedupe: config.resolve?.dedupe ?? [],
|
|
63491
|
+
preserveSymlinks: config.resolve?.preserveSymlinks ?? false,
|
|
63069
63492
|
alias: resolvedAlias
|
|
63070
63493
|
};
|
|
63071
63494
|
// load .env files
|
|
@@ -63094,7 +63517,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63094
63517
|
? '/'
|
|
63095
63518
|
: './'
|
|
63096
63519
|
: resolveBaseUrl(config.base, isBuild, logger) ?? '/';
|
|
63097
|
-
const resolvedBuildOptions = resolveBuildOptions(config.build);
|
|
63520
|
+
const resolvedBuildOptions = resolveBuildOptions(config.build, isBuild, logger);
|
|
63098
63521
|
// resolve cache directory
|
|
63099
63522
|
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true });
|
|
63100
63523
|
const cacheDir = config.cacheDir
|
|
@@ -63149,7 +63572,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63149
63572
|
? path$n.resolve(resolvedRoot, typeof publicDir === 'string' ? publicDir : 'public')
|
|
63150
63573
|
: '';
|
|
63151
63574
|
const server = resolveServerOptions(resolvedRoot, config.server, logger);
|
|
63152
|
-
const ssr = resolveSSROptions(config.ssr,
|
|
63575
|
+
const ssr = resolveSSROptions(config.ssr, resolveOptions.preserveSymlinks, config.legacy?.buildSsrCjsExternalHeuristics);
|
|
63153
63576
|
const middlewareMode = config?.server?.middlewareMode;
|
|
63154
63577
|
const optimizeDeps = config.optimizeDeps || {};
|
|
63155
63578
|
const BASE_URL = resolvedBase;
|
|
@@ -63206,7 +63629,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
63206
63629
|
disabled: 'build',
|
|
63207
63630
|
...optimizeDeps,
|
|
63208
63631
|
esbuildOptions: {
|
|
63209
|
-
preserveSymlinks:
|
|
63632
|
+
preserveSymlinks: resolveOptions.preserveSymlinks,
|
|
63210
63633
|
...optimizeDeps.esbuildOptions
|
|
63211
63634
|
}
|
|
63212
63635
|
},
|
|
@@ -63420,40 +63843,32 @@ async function bundleConfigFile(fileName, isESM) {
|
|
|
63420
63843
|
{
|
|
63421
63844
|
name: 'externalize-deps',
|
|
63422
63845
|
setup(build) {
|
|
63423
|
-
|
|
63846
|
+
const options = {
|
|
63847
|
+
root: path$n.dirname(fileName),
|
|
63848
|
+
isBuild: true,
|
|
63849
|
+
isProduction: true,
|
|
63850
|
+
isRequire: !isESM,
|
|
63851
|
+
preferRelative: false,
|
|
63852
|
+
tryIndex: true,
|
|
63853
|
+
mainFields: DEFAULT_MAIN_FIELDS,
|
|
63854
|
+
browserField: false,
|
|
63855
|
+
conditions: [],
|
|
63856
|
+
dedupe: [],
|
|
63857
|
+
extensions: DEFAULT_EXTENSIONS$1,
|
|
63858
|
+
preserveSymlinks: false
|
|
63859
|
+
};
|
|
63860
|
+
build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
|
|
63424
63861
|
// externalize bare imports
|
|
63425
|
-
if (id[0] !== '.' && !
|
|
63862
|
+
if (id[0] !== '.' && !isAbsolute(id)) {
|
|
63863
|
+
let idFsPath = tryNodeResolve(id, importer, options, false)?.id;
|
|
63864
|
+
if (idFsPath && (isESM || kind === 'dynamic-import')) {
|
|
63865
|
+
idFsPath = pathToFileURL(idFsPath).href;
|
|
63866
|
+
}
|
|
63426
63867
|
return {
|
|
63868
|
+
path: idFsPath,
|
|
63427
63869
|
external: true
|
|
63428
63870
|
};
|
|
63429
63871
|
}
|
|
63430
|
-
// bundle the rest and make sure that the we can also access
|
|
63431
|
-
// it's third-party dependencies. externalize if not.
|
|
63432
|
-
// monorepo/
|
|
63433
|
-
// ├─ package.json
|
|
63434
|
-
// ├─ utils.js -----------> bundle (share same node_modules)
|
|
63435
|
-
// ├─ vite-project/
|
|
63436
|
-
// │ ├─ vite.config.js --> entry
|
|
63437
|
-
// │ ├─ package.json
|
|
63438
|
-
// ├─ foo-project/
|
|
63439
|
-
// │ ├─ utils.js --------> external (has own node_modules)
|
|
63440
|
-
// │ ├─ package.json
|
|
63441
|
-
const idFsPath = path$n.resolve(path$n.dirname(importer), id);
|
|
63442
|
-
const idPkgPath = lookupFile(idFsPath, [`package.json`], {
|
|
63443
|
-
pathOnly: true
|
|
63444
|
-
});
|
|
63445
|
-
if (idPkgPath) {
|
|
63446
|
-
const idPkgDir = path$n.dirname(idPkgPath);
|
|
63447
|
-
// if this file needs to go up one or more directory to reach the vite config,
|
|
63448
|
-
// that means it has it's own node_modules (e.g. foo-project)
|
|
63449
|
-
if (path$n.relative(idPkgDir, fileName).startsWith('..')) {
|
|
63450
|
-
return {
|
|
63451
|
-
// normalize actual import after bundled as a single vite config
|
|
63452
|
-
path: isESM ? pathToFileURL(idFsPath).href : idFsPath,
|
|
63453
|
-
external: true
|
|
63454
|
-
};
|
|
63455
|
-
}
|
|
63456
|
-
}
|
|
63457
63872
|
});
|
|
63458
63873
|
}
|
|
63459
63874
|
},
|
|
@@ -63547,5 +63962,8 @@ function isDepsOptimizerEnabled(config, ssr) {
|
|
|
63547
63962
|
(command === 'build' && disabled === 'build') ||
|
|
63548
63963
|
(command === 'serve' && disabled === 'dev'));
|
|
63549
63964
|
}
|
|
63965
|
+
function isAbsolute(id) {
|
|
63966
|
+
return path$n.isAbsolute(id) || path$n.posix.isAbsolute(id);
|
|
63967
|
+
}
|
|
63550
63968
|
|
|
63551
63969
|
export { index$1 as A, build$1 as B, index as C, preview$1 as D, resolvePackageData as a, build as b, createServer as c, defineConfig as d, resolveConfig as e, formatPostcssSourceMap as f, resolveBaseUrl as g, getDepOptimizationConfig as h, isDepsOptimizerEnabled as i, mergeAlias as j, createFilter as k, loadConfigFromFile as l, mergeConfig as m, normalizePath$3 as n, optimizeDeps as o, preview as p, send as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, createLogger as u, searchForWorkspaceRoot as v, loadEnv as w, resolveEnvPrefix as x, picocolors as y, commonjsGlobal as z };
|