UNPKG

@lynx-js/rspeedy

Version:

A webpack/rspack-based frontend toolchain for Lynx

528 lines (527 loc) 22.7 kB
import * as __WEBPACK_EXTERNAL_MODULE__lynx_js_cache_events_webpack_plugin_4f60358d__ from "@lynx-js/cache-events-webpack-plugin"; import * as __WEBPACK_EXTERNAL_MODULE__lynx_js_chunk_loading_webpack_plugin_f5dc50b6__ from "@lynx-js/chunk-loading-webpack-plugin"; import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core"; import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises"; import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module"; import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path"; import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process"; import node_fs from "node:fs"; import { pathToFileURL } from "node:url"; import { register } from "@lynx-js/rspeedy/register"; var __webpack_modules__ = { "../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": function(module) { let p = process || {}, argv = p.argv || [], env = p.env || {}; let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || "win32" === p.platform || (p.stdout || {}).isTTY && "dumb" !== env.TERM || !!env.CI); let formatter = (open, close, replace = open)=>(input)=>{ let string = "" + input, index = string.indexOf(close, open.length); return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close; }; let replaceClose = (string, close, replace, index)=>{ let result = "", cursor = 0; do { result += string.substring(cursor, index) + replace; cursor = index + close.length; index = string.indexOf(close, cursor); }while (~index); return result + string.substring(cursor); }; let createColors = (enabled = isColorSupported)=>{ let f = enabled ? formatter : ()=>String; return { isColorSupported: enabled, reset: f("\x1b[0m", "\x1b[0m"), bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"), dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"), italic: f("\x1b[3m", "\x1b[23m"), underline: f("\x1b[4m", "\x1b[24m"), inverse: f("\x1b[7m", "\x1b[27m"), hidden: f("\x1b[8m", "\x1b[28m"), strikethrough: f("\x1b[9m", "\x1b[29m"), black: f("\x1b[30m", "\x1b[39m"), red: f("\x1b[31m", "\x1b[39m"), green: f("\x1b[32m", "\x1b[39m"), yellow: f("\x1b[33m", "\x1b[39m"), blue: f("\x1b[34m", "\x1b[39m"), magenta: f("\x1b[35m", "\x1b[39m"), cyan: f("\x1b[36m", "\x1b[39m"), white: f("\x1b[37m", "\x1b[39m"), gray: f("\x1b[90m", "\x1b[39m"), bgBlack: f("\x1b[40m", "\x1b[49m"), bgRed: f("\x1b[41m", "\x1b[49m"), bgGreen: f("\x1b[42m", "\x1b[49m"), bgYellow: f("\x1b[43m", "\x1b[49m"), bgBlue: f("\x1b[44m", "\x1b[49m"), bgMagenta: f("\x1b[45m", "\x1b[49m"), bgCyan: f("\x1b[46m", "\x1b[49m"), bgWhite: f("\x1b[47m", "\x1b[49m"), blackBright: f("\x1b[90m", "\x1b[39m"), redBright: f("\x1b[91m", "\x1b[39m"), greenBright: f("\x1b[92m", "\x1b[39m"), yellowBright: f("\x1b[93m", "\x1b[39m"), blueBright: f("\x1b[94m", "\x1b[39m"), magentaBright: f("\x1b[95m", "\x1b[39m"), cyanBright: f("\x1b[96m", "\x1b[39m"), whiteBright: f("\x1b[97m", "\x1b[39m"), bgBlackBright: f("\x1b[100m", "\x1b[49m"), bgRedBright: f("\x1b[101m", "\x1b[49m"), bgGreenBright: f("\x1b[102m", "\x1b[49m"), bgYellowBright: f("\x1b[103m", "\x1b[49m"), bgBlueBright: f("\x1b[104m", "\x1b[49m"), bgMagentaBright: f("\x1b[105m", "\x1b[49m"), bgCyanBright: f("\x1b[106m", "\x1b[49m"), bgWhiteBright: f("\x1b[107m", "\x1b[49m") }; }; module.exports = createColors(); module.exports.createColors = createColors; }, "./src/debug.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { L1: ()=>isDebug, NW: ()=>debugList, fF: ()=>debug }); var _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("@rsbuild/core"); var picocolors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"); var picocolors__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/ __webpack_require__.n(picocolors__WEBPACK_IMPORTED_MODULE_1__); const isDebug = ()=>{ if (!process.env['DEBUG']) return false; const values = process.env['DEBUG'].toLocaleLowerCase().split(','); return [ 'rsbuild', 'rspeedy', '*' ].some((key)=>values.includes(key)); }; const label = picocolors__WEBPACK_IMPORTED_MODULE_1___default().bgCyan('lynx'); const debug = (message)=>{ if (isDebug()) { const result = 'string' == typeof message ? message : message(); _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__.logger.level = 'verbose'; _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__.logger.debug(`${label} ${result}`); } }; const debugList = (prefix, messages)=>debug(()=>`${prefix} ${[ '' ].concat(messages).join('\n - ')}`); }, "./src/version.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { Q0: ()=>core_.version, _A: ()=>rspackVersion, i8: ()=>version }); var core_ = __webpack_require__("@rsbuild/core"); var package_namespaceObject = { i8: "0.10.8" }; const version = package_namespaceObject.i8; const rspackVersion = core_.rspack.rspackVersion; }, "@lynx-js/cache-events-webpack-plugin": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__lynx_js_cache_events_webpack_plugin_4f60358d__; }, "@lynx-js/chunk-loading-webpack-plugin": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__lynx_js_chunk_loading_webpack_plugin_f5dc50b6__; }, "@rsbuild/core": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__; }, "node:fs/promises": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__; }, "node:module": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__; }, "node:path": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__; }, "node:process": function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__; } }; var __webpack_module_cache__ = {}; function __webpack_require__(moduleId) { var cachedModule = __webpack_module_cache__[moduleId]; if (void 0 !== cachedModule) return cachedModule.exports; var module = __webpack_module_cache__[moduleId] = { exports: {} }; __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); return module.exports; } __webpack_require__.m = __webpack_modules__; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__; var leafPrototypes; __webpack_require__.t = function(value, mode) { if (1 & mode) value = this(value); if (8 & mode) return value; if ('object' == typeof value && value) { if (4 & mode && value.__esModule) return value; if (16 & mode && 'function' == typeof value.then) return value; } var ns = Object.create(null); __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [ null, getProto({}), getProto([]), getProto(getProto) ]; for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{ def[key] = ()=>value[key]; }); def['default'] = ()=>value; __webpack_require__.d(ns, def); return ns; }; })(); (()=>{ __webpack_require__.d = (exports, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.f = {}; __webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{ __webpack_require__.f[key](chunkId, promises); return promises; }, [])); })(); (()=>{ __webpack_require__.u = (chunkId)=>"" + chunkId + ".js"; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports, '__esModule', { value: true }); }; })(); (()=>{ var installedChunks = { index: 0 }; var installChunk = (data)=>{ var __webpack_ids__ = data.__webpack_ids__; var __webpack_modules__ = data.__webpack_modules__; var __webpack_runtime__ = data.__webpack_runtime__; var moduleId, chunkId, i = 0; for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId]; if (__webpack_runtime__) __webpack_runtime__(__webpack_require__); for(; i < __webpack_ids__.length; i++){ chunkId = __webpack_ids__[i]; if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0](); installedChunks[__webpack_ids__[i]] = 0; } }; __webpack_require__.f.j = function(chunkId, promises) { var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0; if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]); else { var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{ if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0; throw e; }); var promise = Promise.race([ promise, new Promise((resolve)=>{ installedChunkData = installedChunks[chunkId] = [ resolve ]; }) ]); promises.push(installedChunkData[1] = promise); } }; })(); var external_node_path_ = __webpack_require__("node:path"); var core_ = __webpack_require__("@rsbuild/core"); var debug = __webpack_require__("./src/debug.ts"); function applyDefaultRspeedyConfig(config) { const enableChunkSplitting = config.performance?.chunkSplit?.strategy && config.performance?.chunkSplit?.strategy !== 'all-in-one'; return (0, core_.mergeRsbuildConfig)({ mode: (()=>{ if (config.mode) return config.mode; const nodeEnv = process.env['NODE_ENV']; return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none'; })(), output: { filename: getFilename(config.output?.filename), inlineScripts: !enableChunkSplitting }, performance: { profile: (0, debug.L1)() ? true : void 0 }, tools: { rsdoctor: { experiments: { enableNativePlugin: true } } } }, config); } const DEFAULT_FILENAME = '[name].[platform].bundle'; function getFilename(filename) { if ('string' == typeof filename) return { bundle: filename, template: filename }; const finalFilename = filename?.bundle ?? filename?.template ?? DEFAULT_FILENAME; return { bundle: finalFilename, template: finalFilename }; } const DEFAULT_ENTRY = './src/index.js'; function toRsbuildEntry(entry) { if (void 0 === entry) { (0, debug.fF)(`Using default entry ${DEFAULT_ENTRY}`); return { main: DEFAULT_ENTRY }; } if (Array.isArray(entry) || 'string' == typeof entry) { (0, debug.fF)(()=>`Using single entry ${[ '' ].concat(entry).join('\n - ')}`); return { main: entry }; } return Object.fromEntries(Object.entries(entry).map(([key, value])=>{ if (Array.isArray(value) || 'string' == typeof value) { (0, debug.NW)(`Using multiple entries - ${key}`, value); return [ key, { import: value } ]; } (0, debug.NW)(`Using multiple entries - ${key}`, value.import ?? DEFAULT_ENTRY); if (void 0 === value.import) return [ key, { ...value, import: DEFAULT_ENTRY } ]; return [ key, value ]; })); } const defaultDataUriLimit = 2048; function toRsbuildConfig(config) { return { dev: { watchFiles: config.dev?.watchFiles, writeToDisk: config.dev?.writeToDisk ?? true, progressBar: config.dev?.progressBar ?? true }, environments: config.environments ?? { lynx: {} }, mode: config.mode, output: { assetPrefix: config.output?.assetPrefix, charset: 'utf8', cleanDistPath: config.output?.cleanDistPath, copy: config.output?.copy, cssModules: config.output?.cssModules, dataUriLimit: config.output?.dataUriLimit ?? defaultDataUriLimit, distPath: config.output?.distPath, filenameHash: config.output?.filenameHash, inlineScripts: config.output?.inlineScripts, legalComments: config.output?.legalComments ?? 'none', polyfill: 'off', sourceMap: config.output?.sourceMap }, resolve: { alias: config.source?.alias }, source: { assetsInclude: config.source?.assetsInclude, decorators: config.source?.decorators, define: config.source?.define, entry: toRsbuildEntry(config.source?.entry), exclude: config.source?.exclude, include: config.source?.include, preEntry: config.source?.preEntry, transformImport: config.source?.transformImport, tsconfigPath: config.source?.tsconfigPath }, server: { base: config.server?.base, headers: config.server?.headers, host: config.server?.host, port: config.server?.port, strictPort: config.server?.strictPort }, plugins: config.plugins, performance: { buildCache: config.performance?.buildCache, chunkSplit: config.performance?.chunkSplit, profile: config.performance?.profile, removeConsole: toRsbuildRemoveConsole(config), printFileSize: config.performance?.printFileSize ?? true }, tools: { bundlerChain: config.tools?.bundlerChain, cssExtract: config.tools?.cssExtract, cssLoader: config.tools?.cssLoader, htmlPlugin: false, rspack: config.tools?.rspack, swc: config.tools?.swc } }; } function toRsbuildRemoveConsole(config) { if (config.performance?.removeConsole === true) return [ 'log', 'warn', 'error', 'info', 'debug', 'profile', 'profileEnd' ]; return config.performance?.removeConsole; } async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) { const config = applyDefaultRspeedyConfig(rspeedyConfig); const [rspeedy, { applyDefaultPlugins }] = await Promise.all([ (0, core_.createRsbuild)({ cwd, loadEnv, rsbuildConfig: toRsbuildConfig(config), environment, callerName }), __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts")) ]); await applyDefaultPlugins(rspeedy, config); const inspectConfig = rspeedy.inspectConfig.bind(rspeedy); return Object.assign(rspeedy, { getRspeedyConfig: ()=>config, async inspectConfig (options) { const result = await inspectConfig(options); const { inspectRspeedyConfig } = await Promise.all([ __webpack_require__.e("vendors-node_modules_pnpm_javascript-stringify_2_1_0_node_modules_javascript-stringify_dist_i-562fbc"), __webpack_require__.e("src_plugins_inspect_plugin_ts") ]).then(__webpack_require__.bind(__webpack_require__, "./src/plugins/inspect.plugin.ts")); await inspectRspeedyConfig(rspeedyConfig, external_node_path_["default"].resolve(options.outputPath ?? rspeedy.context.distPath, '.rsbuild/rspeedy.config.js'), options.verbose ?? false); return result; } }); } function mergeRspeedyConfig(...configs) { return (0, core_.mergeRsbuildConfig)(...configs); } function defineConfig(config) { return config; } var picocolors = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"); var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors); const resolveConfigPath = (root, customConfig)=>{ if (customConfig) { (0, debug.fF)(`load custom config file ${customConfig} from ${root}`); const customConfigPath = (0, external_node_path_.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_.join)(root, customConfig); if (node_fs.existsSync(customConfigPath)) return customConfigPath; throw new Error(`Cannot find config file: ${picocolors_default().dim(customConfigPath)}`); } const CONFIG_FILES = [ 'lynx.config.ts', 'lynx.config.js', 'lynx.config.mts', 'lynx.config.mjs' ]; for (const file of CONFIG_FILES){ (0, debug.fF)(`load default config file ${file} from ${root}`); const configFile = (0, external_node_path_.join)(root, file); if (node_fs.existsSync(configFile)) { (0, debug.fF)(`default config ${configFile} found`); return configFile; } } throw new Error([ `Cannot find the default config file: ${picocolors_default().dim((0, external_node_path_.join)(root, CONFIG_FILES[0]))}.`, `Use custom config with ${picocolors_default().green('`--config <config>`')} options.` ].join(' ')); }; async function loadConfig(loadConfigOptions) { let { configPath } = loadConfigOptions; if (!configPath || !(0, external_node_path_.isAbsolute)(configPath)) configPath = resolveConfigPath(loadConfigOptions.cwd ?? process.cwd(), configPath); const specifier = pathToFileURL(configPath).toString(); let unregister; unregister = shouldUseNativeImport(configPath) ? ()=>{} : register({ load: !hasNativeTSSupport(), resolve: true }); try { const [exports, { validate }] = await Promise.all([ import(`${specifier}?t=${Date.now()}`), __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts")) ]); const content = validate('default' in exports ? exports.default : exports, configPath); return { configPath, content: 'function' == typeof content ? await content() : await content }; } finally{ unregister(); } } function shouldUseNativeImport(configPath) { return isJavaScriptPath(configPath) || isDeno(); } function hasNativeTSSupport() { if (isDeno()) return true; if (process.features.typescript) return true; if (false === process.features.typescript) return false; const { NODE_OPTIONS } = process.env; if (!NODE_OPTIONS) return false; return NODE_OPTIONS.includes('--experimental-transform-types') || NODE_OPTIONS.includes('--experimental-strip-types'); } function isJavaScriptPath(configPath) { const ext = (0, external_node_path_.extname)(configPath); return [ '.js', '.mjs', '.cjs' ].includes(ext); } function isDeno() { if ('undefined' != typeof Deno || process.versions?.deno) return true; return false; } var version = __webpack_require__("./src/version.ts"); var __webpack_exports__logger = core_.logger; var __webpack_exports__rsbuildVersion = version.Q0; var __webpack_exports__rspack = core_.rspack; var __webpack_exports__rspackVersion = version._A; var __webpack_exports__version = version.i8; export { createRspeedy, defineConfig, loadConfig, mergeRspeedyConfig, __webpack_exports__logger as logger, __webpack_exports__rsbuildVersion as rsbuildVersion, __webpack_exports__rspack as rspack, __webpack_exports__rspackVersion as rspackVersion, __webpack_exports__version as version };