@lynx-js/rspeedy
Version:
A webpack/rspack-based frontend toolchain for Lynx
49 lines (48 loc) • 3.46 kB
JavaScript
export const __webpack_ids__ = [
"src_plugins_inspect_plugin_ts"
];
export const __webpack_modules__ = {
"./src/config/output/dist-path.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
A: ()=>DEFAULT_DIST_PATH_INTERMEDIATE
});
const DEFAULT_DIST_PATH_INTERMEDIATE = '.rspeedy';
},
"./src/plugins/inspect.plugin.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
inspectRspeedyConfig: ()=>inspectRspeedyConfig,
pluginInspect: ()=>pluginInspect
});
var node_fs_promises__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs/promises");
var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:path");
var _rsbuild_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@rsbuild/core");
var javascript_stringify__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../../../node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/index.js");
var picocolors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
var picocolors__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/ __webpack_require__.n(picocolors__WEBPACK_IMPORTED_MODULE_6__);
var _config_output_dist_path_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/config/output/dist-path.ts");
var _debug_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./src/debug.ts");
function pluginInspect(config) {
return {
name: 'lynx:rsbuild:inspect',
setup (api) {
api.onBeforeBuild(async ()=>{
await inspectRspeedyConfig(config, node_path__WEBPACK_IMPORTED_MODULE_1__["default"].join(api.context.distPath, _config_output_dist_path_js__WEBPACK_IMPORTED_MODULE_4__.A, 'rspeedy.config.js'), false);
});
}
};
}
async function inspectRspeedyConfig(config, path, verbose) {
const stringifiedConfig = (0, javascript_stringify__WEBPACK_IMPORTED_MODULE_3__.stringify)(config, (value, _, stringify)=>{
if ('function' == typeof value && !verbose && value.toString().length > 100) return "function () { /* omitted long function */ }";
return stringify(value);
}, 2);
if (!stringifiedConfig) return void (0, _debug_js__WEBPACK_IMPORTED_MODULE_5__.fF)('No Rspeedy config found, skip inspect config.');
await (0, node_fs_promises__WEBPACK_IMPORTED_MODULE_0__.mkdir)((0, node_path__WEBPACK_IMPORTED_MODULE_1__.dirname)(path), {
recursive: true
});
await (0, node_fs_promises__WEBPACK_IMPORTED_MODULE_0__.writeFile)(path, `export default ${stringifiedConfig}`);
_rsbuild_core__WEBPACK_IMPORTED_MODULE_2__.logger.success(`Inspect Rspeedy config succeed, open following files to view the content: \n\n - ${picocolors__WEBPACK_IMPORTED_MODULE_6___default().bold(picocolors__WEBPACK_IMPORTED_MODULE_6___default().yellow('Rspeedy'))}: ${picocolors__WEBPACK_IMPORTED_MODULE_6___default().underline(path)}\n`);
}
}
};