UNPKG

3.79 kBJavaScriptView Raw
1import path, { resolve } from 'node:path';
2import { fileURLToPath } from 'node:url';
3
4var version = "3.2.6";
5
6const VERSION = version;
7const DEFAULT_MAIN_FIELDS = [
8 'module',
9 'jsnext:main',
10 'jsnext'
11];
12// Baseline support browserslist
13// "defaults and supports es6-module and supports es6-module-dynamic-import"
14// Higher browser versions may be needed for extra features.
15const ESBUILD_MODULES_TARGET = [
16 'es2020',
17 'edge88',
18 'firefox78',
19 'chrome87',
20 'safari13' // transpile nullish coalescing
21];
22const DEFAULT_EXTENSIONS = [
23 '.mjs',
24 '.js',
25 '.mts',
26 '.ts',
27 '.jsx',
28 '.tsx',
29 '.json'
30];
31const DEFAULT_CONFIG_FILES = [
32 'vite.config.js',
33 'vite.config.mjs',
34 'vite.config.ts',
35 'vite.config.cjs',
36 'vite.config.mts',
37 'vite.config.cts'
38];
39const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/;
40const OPTIMIZABLE_ENTRY_RE = /\.(?:[cm]?[jt]s)$/;
41const SPECIAL_QUERY_RE = /[\?&](?:worker|sharedworker|raw|url)\b/;
42/**
43 * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
44 */
45const FS_PREFIX = `/@fs/`;
46/**
47 * Prefix for resolved Ids that are not valid browser import specifiers
48 */
49const VALID_ID_PREFIX = `/@id/`;
50/**
51 * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
52 * module ID with `\0`, a convention from the rollup ecosystem.
53 * This prevents other plugins from trying to process the id (like node resolution),
54 * and core features like sourcemaps can use this info to differentiate between
55 * virtual modules and regular files.
56 * `\0` is not a permitted char in import URLs so we have to replace them during
57 * import analysis. The id will be decoded back before entering the plugins pipeline.
58 * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
59 * modules in the browser end up encoded as `/@id/__x00__{id}`
60 */
61const NULL_BYTE_PLACEHOLDER = `__x00__`;
62const CLIENT_PUBLIC_PATH = `/@vite/client`;
63const ENV_PUBLIC_PATH = `/@vite/env`;
64const VITE_PACKAGE_DIR = resolve(
65// import.meta.url is `dist/node/constants.js` after bundle
66fileURLToPath(import.meta.url), '../../..');
67const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
68const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
69const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
70// ** READ THIS ** before editing `KNOWN_ASSET_TYPES`.
71// If you add an asset to `KNOWN_ASSET_TYPES`, make sure to also add it
72// to the TypeScript declaration file `packages/vite/client.d.ts` and
73// add a mime type to the `registerCustomMime` in
74// `packages/vite/src/node/plugin/assets.ts` if mime type cannot be
75// looked up by mrmime.
76const KNOWN_ASSET_TYPES = [
77 // images
78 'png',
79 'jpe?g',
80 'jfif',
81 'pjpeg',
82 'pjp',
83 'gif',
84 'svg',
85 'ico',
86 'webp',
87 'avif',
88 // media
89 'mp4',
90 'webm',
91 'ogg',
92 'mp3',
93 'wav',
94 'flac',
95 'aac',
96 // fonts
97 'woff2?',
98 'eot',
99 'ttf',
100 'otf',
101 // other
102 'webmanifest',
103 'pdf',
104 'txt'
105];
106const DEFAULT_ASSETS_RE = new RegExp(`\\.(` + KNOWN_ASSET_TYPES.join('|') + `)(\\?.*)?$`);
107const DEP_VERSION_RE = /[\?&](v=[\w\.-]+)\b/;
108const loopbackHosts = new Set([
109 'localhost',
110 '127.0.0.1',
111 '::1',
112 '0000:0000:0000:0000:0000:0000:0000:0001'
113]);
114const wildcardHosts = new Set([
115 '0.0.0.0',
116 '::',
117 '0000:0000:0000:0000:0000:0000:0000:0000'
118]);
119
120export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, DEP_VERSION_RE, ENV_ENTRY, ENV_PUBLIC_PATH, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, OPTIMIZABLE_ENTRY_RE, SPECIAL_QUERY_RE, VALID_ID_PREFIX, VERSION, VITE_PACKAGE_DIR, loopbackHosts, wildcardHosts };