[57e58a3] | 1 | import path, { resolve } from 'node:path';
|
---|
| 2 | import { fileURLToPath } from 'node:url';
|
---|
| 3 | import { readFileSync } from 'node:fs';
|
---|
| 4 |
|
---|
| 5 | const { version } = JSON.parse(
|
---|
| 6 | readFileSync(new URL("../../package.json", import.meta.url)).toString()
|
---|
| 7 | );
|
---|
| 8 | const ROLLUP_HOOKS = [
|
---|
| 9 | "options",
|
---|
| 10 | "buildStart",
|
---|
| 11 | "buildEnd",
|
---|
| 12 | "renderStart",
|
---|
| 13 | "renderError",
|
---|
| 14 | "renderChunk",
|
---|
| 15 | "writeBundle",
|
---|
| 16 | "generateBundle",
|
---|
| 17 | "banner",
|
---|
| 18 | "footer",
|
---|
| 19 | "augmentChunkHash",
|
---|
| 20 | "outputOptions",
|
---|
| 21 | "renderDynamicImport",
|
---|
| 22 | "resolveFileUrl",
|
---|
| 23 | "resolveImportMeta",
|
---|
| 24 | "intro",
|
---|
| 25 | "outro",
|
---|
| 26 | "closeBundle",
|
---|
| 27 | "closeWatcher",
|
---|
| 28 | "load",
|
---|
| 29 | "moduleParsed",
|
---|
| 30 | "watchChange",
|
---|
| 31 | "resolveDynamicImport",
|
---|
| 32 | "resolveId",
|
---|
| 33 | "shouldTransformCachedModule",
|
---|
| 34 | "transform",
|
---|
| 35 | "onLog"
|
---|
| 36 | ];
|
---|
| 37 | const VERSION = version;
|
---|
| 38 | const DEFAULT_MAIN_FIELDS = [
|
---|
| 39 | "browser",
|
---|
| 40 | "module",
|
---|
| 41 | "jsnext:main",
|
---|
| 42 | // moment still uses this...
|
---|
| 43 | "jsnext"
|
---|
| 44 | ];
|
---|
| 45 | const DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
|
---|
| 46 | const DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(
|
---|
| 47 | DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser")
|
---|
| 48 | );
|
---|
| 49 | const DEV_PROD_CONDITION = `development|production`;
|
---|
| 50 | const DEFAULT_CONDITIONS = ["module", "browser", "node", DEV_PROD_CONDITION];
|
---|
| 51 | const DEFAULT_CLIENT_CONDITIONS = Object.freeze(
|
---|
| 52 | DEFAULT_CONDITIONS.filter((c) => c !== "node")
|
---|
| 53 | );
|
---|
| 54 | const DEFAULT_SERVER_CONDITIONS = Object.freeze(
|
---|
| 55 | DEFAULT_CONDITIONS.filter((c) => c !== "browser")
|
---|
| 56 | );
|
---|
| 57 | const ESBUILD_MODULES_TARGET = [
|
---|
| 58 | "es2020",
|
---|
| 59 | "edge88",
|
---|
| 60 | "firefox78",
|
---|
| 61 | "chrome87",
|
---|
| 62 | "safari14"
|
---|
| 63 | ];
|
---|
| 64 | const DEFAULT_CONFIG_FILES = [
|
---|
| 65 | "vite.config.js",
|
---|
| 66 | "vite.config.mjs",
|
---|
| 67 | "vite.config.ts",
|
---|
| 68 | "vite.config.cjs",
|
---|
| 69 | "vite.config.mts",
|
---|
| 70 | "vite.config.cts"
|
---|
| 71 | ];
|
---|
| 72 | const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/;
|
---|
| 73 | const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
---|
| 74 | const OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
|
---|
| 75 | const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
|
---|
| 76 | const FS_PREFIX = `/@fs/`;
|
---|
| 77 | const CLIENT_PUBLIC_PATH = `/@vite/client`;
|
---|
| 78 | const ENV_PUBLIC_PATH = `/@vite/env`;
|
---|
| 79 | const VITE_PACKAGE_DIR = resolve(
|
---|
| 80 | // import.meta.url is `dist/node/constants.js` after bundle
|
---|
| 81 | fileURLToPath(import.meta.url),
|
---|
| 82 | "../../.."
|
---|
| 83 | );
|
---|
| 84 | const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
|
---|
| 85 | const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
|
---|
| 86 | const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
|
---|
| 87 | const KNOWN_ASSET_TYPES = [
|
---|
| 88 | // images
|
---|
| 89 | "apng",
|
---|
| 90 | "bmp",
|
---|
| 91 | "png",
|
---|
| 92 | "jpe?g",
|
---|
| 93 | "jfif",
|
---|
| 94 | "pjpeg",
|
---|
| 95 | "pjp",
|
---|
| 96 | "gif",
|
---|
| 97 | "svg",
|
---|
| 98 | "ico",
|
---|
| 99 | "webp",
|
---|
| 100 | "avif",
|
---|
| 101 | "cur",
|
---|
| 102 | "jxl",
|
---|
| 103 | // media
|
---|
| 104 | "mp4",
|
---|
| 105 | "webm",
|
---|
| 106 | "ogg",
|
---|
| 107 | "mp3",
|
---|
| 108 | "wav",
|
---|
| 109 | "flac",
|
---|
| 110 | "aac",
|
---|
| 111 | "opus",
|
---|
| 112 | "mov",
|
---|
| 113 | "m4a",
|
---|
| 114 | "vtt",
|
---|
| 115 | // fonts
|
---|
| 116 | "woff2?",
|
---|
| 117 | "eot",
|
---|
| 118 | "ttf",
|
---|
| 119 | "otf",
|
---|
| 120 | // other
|
---|
| 121 | "webmanifest",
|
---|
| 122 | "pdf",
|
---|
| 123 | "txt"
|
---|
| 124 | ];
|
---|
| 125 | const DEFAULT_ASSETS_RE = new RegExp(
|
---|
| 126 | `\\.(` + KNOWN_ASSET_TYPES.join("|") + `)(\\?.*)?$`
|
---|
| 127 | );
|
---|
| 128 | const DEP_VERSION_RE = /[?&](v=[\w.-]+)\b/;
|
---|
| 129 | const loopbackHosts = /* @__PURE__ */ new Set([
|
---|
| 130 | "localhost",
|
---|
| 131 | "127.0.0.1",
|
---|
| 132 | "::1",
|
---|
| 133 | "0000:0000:0000:0000:0000:0000:0000:0001"
|
---|
| 134 | ]);
|
---|
| 135 | const wildcardHosts = /* @__PURE__ */ new Set([
|
---|
| 136 | "0.0.0.0",
|
---|
| 137 | "::",
|
---|
| 138 | "0000:0000:0000:0000:0000:0000:0000:0000"
|
---|
| 139 | ]);
|
---|
| 140 | const DEFAULT_DEV_PORT = 5173;
|
---|
| 141 | const DEFAULT_PREVIEW_PORT = 4173;
|
---|
| 142 | const DEFAULT_ASSETS_INLINE_LIMIT = 4096;
|
---|
| 143 | const defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
|
---|
| 144 | const METADATA_FILENAME = "_metadata.json";
|
---|
| 145 | const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
|
---|
| 146 | const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR";
|
---|
| 147 |
|
---|
| 148 | export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CLIENT_CONDITIONS, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_PREVIEW_PORT, DEFAULT_SERVER_CONDITIONS, DEFAULT_SERVER_MAIN_FIELDS, DEP_VERSION_RE, DEV_PROD_CONDITION, ENV_ENTRY, ENV_PUBLIC_PATH, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, ROLLUP_HOOKS, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, defaultAllowedOrigins, loopbackHosts, wildcardHosts };
|
---|