@modern-js/builder 2.46.1 → 3.0.0-alpha.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/LICENSE +1 -1
- package/README.md +14 -16
- package/compiled/postcss-load-config/index.d.ts +1 -0
- package/compiled/postcss-load-config/index.js +14 -0
- package/compiled/postcss-load-config/license +20 -0
- package/compiled/postcss-load-config/package.json +1 -0
- package/dist/createBuilder.d.ts +8 -2
- package/dist/createBuilder.js +124 -39
- package/dist/index.d.ts +8 -4
- package/dist/index.js +18 -7
- package/dist/plugins/babel-post.d.ts +5 -0
- package/dist/plugins/{asset.js → babel-post.js} +21 -22
- package/dist/plugins/devtools.d.ts +4 -0
- package/dist/plugins/{devtool.js → devtools.js} +15 -16
- package/dist/plugins/emitRouteFile.d.ts +6 -0
- package/dist/plugins/{cleanOutput.js → emitRouteFile.js} +34 -16
- package/dist/plugins/environmentDefaults.d.ts +3 -0
- package/dist/plugins/environmentDefaults.js +99 -0
- package/dist/plugins/globalVars.d.ts +3 -0
- package/dist/plugins/{moment.js → globalVars.js} +23 -16
- package/dist/plugins/htmlMinify.d.ts +2 -0
- package/dist/plugins/htmlMinify.js +126 -0
- package/dist/plugins/manifest.d.ts +2 -0
- package/dist/plugins/{entry.js → manifest.js} +18 -16
- package/dist/plugins/postcss.d.ts +6 -0
- package/dist/plugins/postcss.js +133 -0
- package/dist/plugins/runtimeChunk.d.ts +2 -0
- package/dist/plugins/runtimeChunk.js +55 -0
- package/dist/rsc/common.d.ts +22 -0
- package/dist/rsc/common.js +174 -0
- package/dist/rsc/plugins/rsbuild-rsc-plugin.d.ts +7 -0
- package/dist/rsc/plugins/rsbuild-rsc-plugin.js +166 -0
- package/dist/rsc/plugins/rspack-rsc-client-plugin.d.ts +14 -0
- package/dist/rsc/plugins/rspack-rsc-client-plugin.js +233 -0
- package/dist/rsc/plugins/rspack-rsc-server-plugin.d.ts +32 -0
- package/dist/rsc/plugins/rspack-rsc-server-plugin.js +290 -0
- package/dist/rsc/rsc-client-loader.d.ts +7 -0
- package/dist/rsc/rsc-client-loader.js +70 -0
- package/dist/rsc/rsc-css-loader.d.ts +2 -0
- package/dist/{plugins/yaml.js → rsc/rsc-css-loader.js} +11 -17
- package/dist/rsc/rsc-server-loader.d.ts +6 -0
- package/dist/rsc/rsc-server-loader.js +95 -0
- package/dist/rsc/rsc-ssr-loader.d.ts +6 -0
- package/dist/rsc/rsc-ssr-loader.js +58 -0
- package/dist/shared/devServer.d.ts +6 -0
- package/dist/shared/devServer.js +83 -0
- package/dist/shared/getCssSupport.d.ts +1 -0
- package/dist/shared/getCssSupport.js +113 -0
- package/dist/shared/manifest.d.ts +2 -0
- package/dist/{plugins/toml.js → shared/manifest.js} +16 -14
- package/dist/shared/parseCommonConfig.d.ts +8 -0
- package/dist/shared/parseCommonConfig.js +232 -0
- package/dist/shared/utils.d.ts +12 -0
- package/dist/shared/utils.js +109 -0
- package/dist/types.d.ts +283 -0
- package/dist/types.js +16 -0
- package/package.json +54 -59
- package/dist/cli/commands.d.ts +0 -2
- package/dist/cli/commands.js +0 -45
- package/dist/cli/config.d.ts +0 -14
- package/dist/cli/config.js +0 -72
- package/dist/cli/index.d.ts +0 -6
- package/dist/cli/index.js +0 -51
- package/dist/cli/provider.d.ts +0 -2
- package/dist/cli/provider.js +0 -73
- package/dist/plugins/antd.d.ts +0 -3
- package/dist/plugins/antd.js +0 -63
- package/dist/plugins/arco.d.ts +0 -2
- package/dist/plugins/arco.js +0 -61
- package/dist/plugins/asset.d.ts +0 -2
- package/dist/plugins/assetsRetry.d.ts +0 -2
- package/dist/plugins/assetsRetry.js +0 -64
- package/dist/plugins/bundleAnalyzer.d.ts +0 -2
- package/dist/plugins/bundleAnalyzer.js +0 -59
- package/dist/plugins/cache.d.ts +0 -2
- package/dist/plugins/cache.js +0 -129
- package/dist/plugins/checkSyntax.d.ts +0 -2
- package/dist/plugins/checkSyntax.js +0 -73
- package/dist/plugins/cleanOutput.d.ts +0 -2
- package/dist/plugins/define.d.ts +0 -2
- package/dist/plugins/define.js +0 -68
- package/dist/plugins/devtool.d.ts +0 -2
- package/dist/plugins/entry.d.ts +0 -2
- package/dist/plugins/externals.d.ts +0 -2
- package/dist/plugins/externals.js +0 -48
- package/dist/plugins/fileSize.d.ts +0 -4
- package/dist/plugins/fileSize.js +0 -164
- package/dist/plugins/html.d.ts +0 -3
- package/dist/plugins/html.js +0 -236
- package/dist/plugins/index.d.ts +0 -2
- package/dist/plugins/index.js +0 -74
- package/dist/plugins/inlineChunk.d.ts +0 -2
- package/dist/plugins/inlineChunk.js +0 -82
- package/dist/plugins/moment.d.ts +0 -2
- package/dist/plugins/networkPerformance.d.ts +0 -2
- package/dist/plugins/networkPerformance.js +0 -54
- package/dist/plugins/nodeAddons.d.ts +0 -2
- package/dist/plugins/nodeAddons.js +0 -73
- package/dist/plugins/performance.d.ts +0 -5
- package/dist/plugins/performance.js +0 -66
- package/dist/plugins/preloadOrPrefetch.d.ts +0 -2
- package/dist/plugins/preloadOrPrefetch.js +0 -57
- package/dist/plugins/rem.d.ts +0 -2
- package/dist/plugins/rem.js +0 -106
- package/dist/plugins/sourceBuild.d.ts +0 -15
- package/dist/plugins/sourceBuild.js +0 -121
- package/dist/plugins/splitChunks.d.ts +0 -4
- package/dist/plugins/splitChunks.js +0 -249
- package/dist/plugins/startUrl.d.ts +0 -3
- package/dist/plugins/startUrl.js +0 -86
- package/dist/plugins/svg.d.ts +0 -2
- package/dist/plugins/svg.js +0 -89
- package/dist/plugins/target.d.ts +0 -2
- package/dist/plugins/target.js +0 -73
- package/dist/plugins/toml.d.ts +0 -2
- package/dist/plugins/tsChecker.d.ts +0 -2
- package/dist/plugins/tsChecker.js +0 -109
- package/dist/plugins/wasm.d.ts +0 -2
- package/dist/plugins/wasm.js +0 -51
- package/dist/plugins/yaml.d.ts +0 -2
- package/vitest.config.ts +0 -19
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
> DEPRECATED: use [Rsbuild](https://github.com/web-infra-dev/rsbuild) instead.
|
|
2
|
-
|
|
3
1
|
<p align="center">
|
|
4
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
5
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
6
7
|
<p align="center">
|
|
7
|
-
|
|
8
|
-
<br/>
|
|
9
|
-
<a href="https://modernjs.dev/builder/en" target="blank">
|
|
10
|
-
modernjs.dev/builder
|
|
11
|
-
</a>
|
|
12
|
-
</p>
|
|
13
|
-
<p align="center">
|
|
14
|
-
An Rspack-based build tool for web development.
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
15
9
|
</p>
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
## Getting Started
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
20
14
|
|
|
21
|
-
##
|
|
15
|
+
## Documentation
|
|
22
16
|
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
25
19
|
|
|
26
20
|
## Contributing
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export = any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(()=>{var __webpack_modules__={920:(module,__unused_webpack_exports,__nccwpck_require__)=>{const path=__nccwpck_require__(928);const fs=__nccwpck_require__(896);const os=__nccwpck_require__(857);const url=__nccwpck_require__(16);const fsReadFileAsync=fs.promises.readFile;function getDefaultSearchPlaces(e,t){return["package.json",`.${e}rc.json`,`.${e}rc.js`,`.${e}rc.cjs`,...t?[]:[`.${e}rc.mjs`],`.config/${e}rc`,`.config/${e}rc.json`,`.config/${e}rc.js`,`.config/${e}rc.cjs`,...t?[]:[`.config/${e}rc.mjs`],`${e}.config.js`,`${e}.config.cjs`,...t?[]:[`${e}.config.mjs`]]}function parentDir(e){return path.dirname(e)||path.sep}const jsonLoader=(e,t)=>JSON.parse(t);const requireFunc=true?eval("require"):0;const defaultLoadersSync=Object.freeze({".js":requireFunc,".json":requireFunc,".cjs":requireFunc,noExt:jsonLoader});module.exports.defaultLoadersSync=defaultLoadersSync;const dynamicImport=async e=>{try{const t=url.pathToFileURL(e).href;const r=await import(t);return r.default}catch(t){try{return requireFunc(e)}catch(e){if(e.code==="ERR_REQUIRE_ESM"||e instanceof SyntaxError&&e.toString().includes("Cannot use import statement outside a module")){throw t}throw e}}};const defaultLoaders=Object.freeze({".js":dynamicImport,".mjs":dynamicImport,".cjs":dynamicImport,".json":jsonLoader,noExt:jsonLoader});module.exports.defaultLoaders=defaultLoaders;function getOptions(e,t,r){const n={stopDir:os.homedir(),searchPlaces:getDefaultSearchPlaces(e,r),ignoreEmptySearchPlaces:true,cache:true,transform:e=>e,packageProp:[e],...t,loaders:{...r?defaultLoadersSync:defaultLoaders,...t.loaders}};n.searchPlaces.forEach((e=>{const t=path.extname(e)||"noExt";const r=n.loaders[t];if(!r){throw new Error(`Missing loader for extension "${e}"`)}if(typeof r!=="function"){throw new Error(`Loader for extension "${e}" is not a function: Received ${typeof r}.`)}}));return n}function getPackageProp(e,t){if(typeof e==="string"&&e in t)return t[e];return(Array.isArray(e)?e:e.split(".")).reduce(((e,t)=>e===undefined?e:e[t]),t)||null}function validateFilePath(e){if(!e)throw new Error("load must pass a non-empty string")}function validateLoader(e,t){if(!e)throw new Error(`No loader specified for extension "${t}"`);if(typeof e!=="function")throw new Error("loader is not a function")}const makeEmplace=e=>(t,r,n)=>{if(e)t.set(r,n);return n};module.exports.lilconfig=function lilconfig(e,t){const{ignoreEmptySearchPlaces:r,loaders:n,packageProp:o,searchPlaces:a,stopDir:s,transform:c,cache:i}=getOptions(e,t??{},false);const f=new Map;const l=new Map;const u=makeEmplace(i);return{async search(e=process.cwd()){const t={config:null,filepath:""};const l=new Set;let u=e;e:while(true){if(i){const e=f.get(u);if(e!==undefined){for(const t of l)f.set(t,e);return e}l.add(u)}for(const e of a){const a=path.join(u,e);try{await fs.promises.access(a)}catch{continue}const s=String(await fsReadFileAsync(a));const c=path.extname(e)||"noExt";const i=n[c];if(e==="package.json"){const e=await i(a,s);const r=getPackageProp(o,e);if(r!=null){t.config=r;t.filepath=a;break e}continue}const f=s.trim()==="";if(f&&r)continue;if(f){t.isEmpty=true;t.config=undefined}else{validateLoader(i,c);t.config=await i(a,s)}t.filepath=a;break e}if(u===s||u===parentDir(u))break e;u=parentDir(u)}const p=t.filepath===""&&t.config===null?c(null):c(t);if(i){for(const e of l)f.set(e,p)}return p},async load(e){validateFilePath(e);const t=path.resolve(process.cwd(),e);if(i&&l.has(t)){return l.get(t)}const{base:a,ext:s}=path.parse(t);const f=s||"noExt";const p=n[f];validateLoader(p,f);const d=String(await fsReadFileAsync(t));if(a==="package.json"){const e=await p(t,d);return u(l,t,c({config:getPackageProp(o,e),filepath:t}))}const _={config:null,filepath:t};const g=d.trim()==="";if(g&&r)return u(l,t,c({config:undefined,filepath:t,isEmpty:true}));_.config=g?undefined:await p(t,d);return u(l,t,c(g?{..._,isEmpty:g,config:undefined}:_))},clearLoadCache(){if(i)l.clear()},clearSearchCache(){if(i)f.clear()},clearCaches(){if(i){l.clear();f.clear()}}}};module.exports.lilconfigSync=function lilconfigSync(e,t){const{ignoreEmptySearchPlaces:r,loaders:n,packageProp:o,searchPlaces:a,stopDir:s,transform:c,cache:i}=getOptions(e,t??{},true);const f=new Map;const l=new Map;const u=makeEmplace(i);return{search(e=process.cwd()){const t={config:null,filepath:""};const l=new Set;let u=e;e:while(true){if(i){const e=f.get(u);if(e!==undefined){for(const t of l)f.set(t,e);return e}l.add(u)}for(const e of a){const a=path.join(u,e);try{fs.accessSync(a)}catch{continue}const s=path.extname(e)||"noExt";const c=n[s];const i=String(fs.readFileSync(a));if(e==="package.json"){const e=c(a,i);const r=getPackageProp(o,e);if(r!=null){t.config=r;t.filepath=a;break e}continue}const f=i.trim()==="";if(f&&r)continue;if(f){t.isEmpty=true;t.config=undefined}else{validateLoader(c,s);t.config=c(a,i)}t.filepath=a;break e}if(u===s||u===parentDir(u))break e;u=parentDir(u)}const p=t.filepath===""&&t.config===null?c(null):c(t);if(i){for(const e of l)f.set(e,p)}return p},load(e){validateFilePath(e);const t=path.resolve(process.cwd(),e);if(i&&l.has(t)){return l.get(t)}const{base:a,ext:s}=path.parse(t);const f=s||"noExt";const p=n[f];validateLoader(p,f);const d=String(fs.readFileSync(t));if(a==="package.json"){const e=p(t,d);return c({config:getPackageProp(o,e),filepath:t})}const _={config:null,filepath:t};const g=d.trim()==="";if(g&&r)return u(l,t,c({filepath:t,config:undefined,isEmpty:true}));_.config=g?undefined:p(t,d);return u(l,t,c(g?{..._,isEmpty:g,config:undefined}:_))},clearLoadCache(){if(i)l.clear()},clearSearchCache(){if(i)f.clear()},clearCaches(){if(i){l.clear();f.clear()}}}}},109:(e,t,r)=>{const{resolve:n}=r(760);const o=r(920);const a=r(471);const s=r(697);const c=r(257);const interopRequireDefault=e=>e&&e.__esModule?e:{default:e};async function processResult(e,t){let r=t.filepath||"";let n=interopRequireDefault(t.config).default||{};if(typeof n==="function"){n=n(e)}else{n=Object.assign({},n,e)}if(!n.plugins){n.plugins=[]}let o={file:r,options:await a(n,r),plugins:await s(n,r)};delete n.plugins;return o}function createContext(e){e=Object.assign({cwd:process.cwd(),env:process.env.NODE_ENV},e);if(!e.env){process.env.NODE_ENV="development"}return e}async function loader(e){return c(e)}let i;async function yamlLoader(e,t){if(!i){try{i=await Promise.resolve().then(r.t.bind(r,160,23))}catch(e){throw new Error(`'yaml' is required for the YAML configuration files. Make sure it is installed\nError: ${e.message}`)}}return i.parse(t)}const withLoaders=(e={})=>{let t="postcss";return{...e,loaders:{...e.loaders,".cjs":loader,".cts":loader,".js":loader,".mjs":loader,".mts":loader,".ts":loader,".yaml":yamlLoader,".yml":yamlLoader},searchPlaces:[...e.searchPlaces||[],"package.json",`.${t}rc`,`.${t}rc.json`,`.${t}rc.yaml`,`.${t}rc.yml`,`.${t}rc.ts`,`.${t}rc.cts`,`.${t}rc.mts`,`.${t}rc.js`,`.${t}rc.cjs`,`.${t}rc.mjs`,`${t}.config.ts`,`${t}.config.cts`,`${t}.config.mts`,`${t}.config.js`,`${t}.config.cjs`,`${t}.config.mjs`]}};function rc(e,t,r){e=createContext(e);t=t?n(t):process.cwd();return o.lilconfig("postcss",withLoaders(r)).search(t).then((r=>{if(!r){throw new Error(`No PostCSS Config found in: ${t}`)}return processResult(e,r)}))}
|
|
2
|
+
/**
|
|
3
|
+
* Autoload Config for PostCSS
|
|
4
|
+
*
|
|
5
|
+
* @author Michael Ciniawsky @michael-ciniawsky <michael.ciniawsky@gmail.com>
|
|
6
|
+
* @license MIT
|
|
7
|
+
*
|
|
8
|
+
* @module postcss-load-config
|
|
9
|
+
* @version 2.1.0
|
|
10
|
+
*
|
|
11
|
+
* @requires comsiconfig
|
|
12
|
+
* @requires ./options
|
|
13
|
+
* @requires ./plugins
|
|
14
|
+
*/e.exports=rc},471:(e,t,r)=>{const n=r(257);async function options(e,t){if(e.parser&&typeof e.parser==="string"){try{e.parser=await n(e.parser,t)}catch(e){throw new Error(`Loading PostCSS Parser failed: ${e.message}\n\n(@${t})`)}}if(e.syntax&&typeof e.syntax==="string"){try{e.syntax=await n(e.syntax,t)}catch(e){throw new Error(`Loading PostCSS Syntax failed: ${e.message}\n\n(@${t})`)}}if(e.stringifier&&typeof e.stringifier==="string"){try{e.stringifier=await n(e.stringifier,t)}catch(e){throw new Error(`Loading PostCSS Stringifier failed: ${e.message}\n\n(@${t})`)}}return e}e.exports=options},697:(e,t,r)=>{const n=r(257);async function load(e,t,r){try{if(t===null||t===undefined||Object.keys(t).length===0){return await n(e,r)}else{return(await n(e,r))(t)}}catch(e){throw new Error(`Loading PostCSS Plugin failed: ${e.message}\n\n(@${r})`)}}async function plugins(e,t){let r=[];if(Array.isArray(e.plugins)){r=e.plugins.filter(Boolean)}else{r=Object.entries(e.plugins).filter((([,e])=>e!==false)).map((([e,r])=>load(e,r,t)));r=await Promise.all(r)}if(r.length&&r.length>0){r.forEach(((e,r)=>{if(e.default){e=e.default}if(e.postcss===true){e=e()}else if(e.postcss){e=e.postcss}if(!(typeof e==="object"&&Array.isArray(e.plugins)||typeof e==="object"&&e.postcssPlugin||typeof e==="function")){throw new TypeError(`Invalid PostCSS Plugin found at: plugins[${r}]\n\n(@${t})`)}}))}return r}e.exports=plugins},257:(e,t,r)=>{const{createRequire:n}=r(995);const{pathToFileURL:o}=r(136);const a=/\.[mc]?ts$/;let s;let c;let i=[];async function req(e,t=__filename){let r=n(t).resolve(e);try{return(await import(`${o(r)}?t=${Date.now()}`)).default}catch(e){if(!a.test(r)){throw e}}if(s===undefined){try{s=await import("tsx/cjs/api")}catch(e){i.push(e)}}if(s){let r=s.require(e,t);return r&&"__esModule"in r?r.default:r}if(c===undefined){try{c=(await import("jiti")).default}catch(e){i.push(e)}}if(c){return c(t,{interopDefault:true})(e)}throw new Error(`'tsx' or 'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${i.map((e=>e.message)).join("\n")}`)}e.exports=req},896:e=>{"use strict";e.exports=require("fs")},995:e=>{"use strict";e.exports=require("node:module")},760:e=>{"use strict";e.exports=require("node:path")},136:e=>{"use strict";e.exports=require("node:url")},857:e=>{"use strict";e.exports=require("os")},928:e=>{"use strict";e.exports=require("path")},16:e=>{"use strict";e.exports=require("url")},160:e=>{"use strict";e.exports=require("yaml")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var r=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e](r,r.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return r.exports}(()=>{var e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;var t;__nccwpck_require__.t=function(r,n){if(n&1)r=this(r);if(n&8)return r;if(typeof r==="object"&&r){if(n&4&&r.__esModule)return r;if(n&16&&typeof r.then==="function")return r}var o=Object.create(null);__nccwpck_require__.r(o);var a={};t=t||[null,e({}),e([]),e(e)];for(var s=n&2&&r;typeof s=="object"&&!~t.indexOf(s);s=e(s)){Object.getOwnPropertyNames(s).forEach((e=>a[e]=()=>r[e]))}a["default"]=()=>r;__nccwpck_require__.d(o,a);return o}})();(()=>{__nccwpck_require__.d=(e,t)=>{for(var r in t){if(__nccwpck_require__.o(t,r)&&!__nccwpck_require__.o(e,r)){Object.defineProperty(e,r,{enumerable:true,get:t[r]})}}}})();(()=>{__nccwpck_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{__nccwpck_require__.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__=__nccwpck_require__(109);module.exports=__webpack_exports__})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright Michael Ciniawsky <michael.ciniawsky@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"postcss-load-config","author":"Michael Ciniawky <michael.ciniawsky@gmail.com>","version":"6.0.1","funding":[{"type":"opencollective","url":"https://opencollective.com/postcss/"},{"type":"github","url":"https://github.com/sponsors/ai"}],"license":"MIT","types":"index.d.ts"}
|
package/dist/createBuilder.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { RsbuildConfig, RsbuildInstance, RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type { BuilderConfig, CreateBuilderCommonOptions, CreateBuilderOptions } from './types';
|
|
3
|
+
export declare function parseConfig(builderConfig: BuilderConfig, options: CreateBuilderCommonOptions): Promise<{
|
|
4
|
+
rsbuildConfig: RsbuildConfig;
|
|
5
|
+
rsbuildPlugins: RsbuildPlugin[];
|
|
6
|
+
}>;
|
|
7
|
+
export type BuilderInstance = RsbuildInstance;
|
|
8
|
+
export declare function createRspackBuilder(options: CreateBuilderOptions): Promise<BuilderInstance>;
|
package/dist/createBuilder.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,54 +17,137 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var createBuilder_exports = {};
|
|
20
30
|
__export(createBuilder_exports, {
|
|
21
|
-
|
|
31
|
+
createRspackBuilder: () => createRspackBuilder,
|
|
32
|
+
parseConfig: () => parseConfig
|
|
22
33
|
});
|
|
23
34
|
module.exports = __toCommonJS(createBuilder_exports);
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
var import_core = require("@rsbuild/core");
|
|
36
|
+
var import_rsbuild_rsc_plugin = require("./rsc/plugins/rsbuild-rsc-plugin");
|
|
37
|
+
var import_parseCommonConfig = require("./shared/parseCommonConfig");
|
|
38
|
+
var import_utils = require("./shared/utils");
|
|
39
|
+
async function parseConfig(builderConfig, options) {
|
|
40
|
+
var _builderConfig_tools, _builderConfig_server;
|
|
41
|
+
var _builderConfig, _builderConfig_performance;
|
|
42
|
+
var _performance;
|
|
43
|
+
(_performance = (_builderConfig = builderConfig).performance) !== null && _performance !== void 0 ? _performance : _builderConfig.performance = {};
|
|
44
|
+
var _buildCache;
|
|
45
|
+
(_buildCache = (_builderConfig_performance = builderConfig.performance).buildCache) !== null && _buildCache !== void 0 ? _buildCache : _builderConfig_performance.buildCache = true;
|
|
46
|
+
const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(builderConfig, options);
|
|
47
|
+
const { sri } = builderConfig.security || {};
|
|
48
|
+
if (sri) {
|
|
49
|
+
if (sri === true) {
|
|
50
|
+
rsbuildConfig.security.sri = {
|
|
51
|
+
enable: "auto"
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
const algorithm = Array.isArray(sri.hashFuncNames) ? sri.hashFuncNames[0] : void 0;
|
|
55
|
+
rsbuildConfig.security.sri = {
|
|
56
|
+
enable: sri.enabled,
|
|
57
|
+
algorithm
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (Boolean(rsbuildConfig.tools.lightningcssLoader) === false) {
|
|
62
|
+
var _builderConfig_tools1;
|
|
63
|
+
const { pluginPostcss } = await Promise.resolve().then(() => __toESM(require("./plugins/postcss")));
|
|
64
|
+
rsbuildPlugins.push(pluginPostcss({
|
|
65
|
+
autoprefixer: (_builderConfig_tools1 = builderConfig.tools) === null || _builderConfig_tools1 === void 0 ? void 0 : _builderConfig_tools1.autoprefixer
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
const hasEnvironmentBabelConfig = Object.values(builderConfig.environments || {}).some((c) => {
|
|
69
|
+
var _c_tools;
|
|
70
|
+
return ((_c_tools = c.tools) === null || _c_tools === void 0 ? void 0 : _c_tools.babel) !== void 0;
|
|
71
|
+
});
|
|
72
|
+
if (hasEnvironmentBabelConfig) {
|
|
73
|
+
const mergeSharedBabelConfig = (config) => {
|
|
74
|
+
var _builderConfig_tools3;
|
|
75
|
+
if ((_builderConfig_tools3 = builderConfig.tools) === null || _builderConfig_tools3 === void 0 ? void 0 : _builderConfig_tools3.babel) {
|
|
76
|
+
var _builderConfig_tools12;
|
|
77
|
+
return (0, import_utils.castArray)(config).concat(...(0, import_utils.castArray)((_builderConfig_tools12 = builderConfig.tools) === null || _builderConfig_tools12 === void 0 ? void 0 : _builderConfig_tools12.babel));
|
|
78
|
+
}
|
|
79
|
+
return config;
|
|
80
|
+
};
|
|
81
|
+
const { pluginBabel } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-babel")));
|
|
82
|
+
const { pluginBabelPost } = await Promise.resolve().then(() => __toESM(require("./plugins/babel-post")));
|
|
83
|
+
Object.entries(builderConfig.environments).forEach(([name, config]) => {
|
|
84
|
+
var _rsbuildConfig_environments, _config_tools, _builderConfig_tools3;
|
|
85
|
+
const environmentConfig = (_rsbuildConfig_environments = rsbuildConfig.environments) === null || _rsbuildConfig_environments === void 0 ? void 0 : _rsbuildConfig_environments[name];
|
|
86
|
+
if (!environmentConfig) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.babel) {
|
|
90
|
+
var _config_tools1;
|
|
91
|
+
var _environmentConfig;
|
|
92
|
+
var _plugins;
|
|
93
|
+
(_plugins = (_environmentConfig = environmentConfig).plugins) !== null && _plugins !== void 0 ? _plugins : _environmentConfig.plugins = [];
|
|
94
|
+
environmentConfig.plugins.push(pluginBabel({
|
|
95
|
+
babelLoaderOptions: mergeSharedBabelConfig((_config_tools1 = config.tools) === null || _config_tools1 === void 0 ? void 0 : _config_tools1.babel)
|
|
96
|
+
}), pluginBabelPost());
|
|
97
|
+
} else if ((_builderConfig_tools3 = builderConfig.tools) === null || _builderConfig_tools3 === void 0 ? void 0 : _builderConfig_tools3.babel) {
|
|
98
|
+
var _builderConfig_tools12;
|
|
99
|
+
var _environmentConfig1;
|
|
100
|
+
var _plugins1;
|
|
101
|
+
(_plugins1 = (_environmentConfig1 = environmentConfig).plugins) !== null && _plugins1 !== void 0 ? _plugins1 : _environmentConfig1.plugins = [];
|
|
102
|
+
environmentConfig.plugins.push(pluginBabel({
|
|
103
|
+
babelLoaderOptions: (_builderConfig_tools12 = builderConfig.tools) === null || _builderConfig_tools12 === void 0 ? void 0 : _builderConfig_tools12.babel
|
|
104
|
+
}), pluginBabelPost());
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
} else if ((_builderConfig_tools = builderConfig.tools) === null || _builderConfig_tools === void 0 ? void 0 : _builderConfig_tools.babel) {
|
|
108
|
+
var _builderConfig_tools2;
|
|
109
|
+
const { pluginBabel } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-babel")));
|
|
110
|
+
const { pluginBabelPost } = await Promise.resolve().then(() => __toESM(require("./plugins/babel-post")));
|
|
111
|
+
rsbuildPlugins.push(pluginBabel({
|
|
112
|
+
babelLoaderOptions: (_builderConfig_tools2 = builderConfig.tools) === null || _builderConfig_tools2 === void 0 ? void 0 : _builderConfig_tools2.babel
|
|
113
|
+
}), pluginBabelPost());
|
|
114
|
+
}
|
|
115
|
+
var _builderConfig_server_rsc;
|
|
116
|
+
const enableRsc = (_builderConfig_server_rsc = (_builderConfig_server = builderConfig.server) === null || _builderConfig_server === void 0 ? void 0 : _builderConfig_server.rsc) !== null && _builderConfig_server_rsc !== void 0 ? _builderConfig_server_rsc : false;
|
|
117
|
+
if (enableRsc) {
|
|
118
|
+
const { rscClientRuntimePath, rscServerRuntimePath, internalDirectory } = options;
|
|
119
|
+
rsbuildPlugins.push((0, import_rsbuild_rsc_plugin.rsbuildRscPlugin)({
|
|
120
|
+
appDir: options.cwd,
|
|
121
|
+
rscClientRuntimePath,
|
|
122
|
+
rscServerRuntimePath,
|
|
123
|
+
internalDirectory
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
rsbuildConfig,
|
|
128
|
+
rsbuildPlugins
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function createRspackBuilder(options) {
|
|
132
|
+
const { cwd = process.cwd(), config, rscClientRuntimePath, rscServerRuntimePath, ...rest } = options;
|
|
133
|
+
const { rsbuildConfig, rsbuildPlugins } = await parseConfig(config, {
|
|
134
|
+
...rest,
|
|
135
|
+
cwd
|
|
136
|
+
});
|
|
137
|
+
rsbuildConfig.plugins = [
|
|
138
|
+
...rsbuildPlugins,
|
|
139
|
+
...rsbuildConfig.plugins || []
|
|
140
|
+
];
|
|
141
|
+
const rsbuild = await (0, import_core.createRsbuild)({
|
|
142
|
+
cwd,
|
|
143
|
+
rsbuildConfig
|
|
33
144
|
});
|
|
34
|
-
(0, import_builder_shared.debug)("add default plugins");
|
|
35
|
-
await applyDefaultPlugins(pluginStore);
|
|
36
|
-
(0, import_builder_shared.debug)("add default plugins done");
|
|
37
145
|
return {
|
|
38
|
-
...
|
|
39
|
-
"addPlugins",
|
|
40
|
-
"removePlugins",
|
|
41
|
-
"isPluginExists"
|
|
42
|
-
]),
|
|
43
|
-
...(0, import_builder_shared.pick)(pluginAPI, [
|
|
44
|
-
"onBeforeBuild",
|
|
45
|
-
"onBeforeCreateCompiler",
|
|
46
|
-
"onBeforeStartDevServer",
|
|
47
|
-
"onAfterBuild",
|
|
48
|
-
"onAfterCreateCompiler",
|
|
49
|
-
"onAfterStartDevServer",
|
|
50
|
-
"onDevCompileDone",
|
|
51
|
-
"onExit",
|
|
52
|
-
"getHTMLPaths",
|
|
53
|
-
"getBuilderConfig",
|
|
54
|
-
"getNormalizedConfig"
|
|
55
|
-
]),
|
|
56
|
-
serve,
|
|
57
|
-
build,
|
|
58
|
-
createCompiler,
|
|
59
|
-
initConfigs,
|
|
60
|
-
inspectConfig,
|
|
61
|
-
startDevServer,
|
|
62
|
-
context: publicContext
|
|
146
|
+
...rsbuild
|
|
63
147
|
};
|
|
64
148
|
}
|
|
65
149
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
150
|
0 && (module.exports = {
|
|
67
|
-
|
|
151
|
+
createRspackBuilder,
|
|
152
|
+
parseConfig
|
|
68
153
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
1
|
+
import { type BuilderInstance, createRspackBuilder } from './createBuilder';
|
|
2
|
+
import type { CreateBuilderOptions } from './types';
|
|
3
|
+
export type { CreateBuilderOptions, BuilderInstance };
|
|
4
|
+
export type { BuilderConfig, BundlerType, ToolsDevServerConfig, MetaOptions, Stats, MultiStats, RspackConfig, CacheGroup, } from './types';
|
|
5
|
+
export { createRspackBuilder as createBuilder };
|
|
6
|
+
export { logger, type ConfigChain, type RsbuildPlugin, type ChainIdentifier, type RspackChain, type Rspack, type RsbuildContext, type RsbuildConfig, type RsbuildTarget, type NormalizedConfig, } from '@rsbuild/core';
|
|
7
|
+
export { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled, castArray, } from './shared/utils';
|
|
8
|
+
export { parseConfig as parseRspackConfig } from './createBuilder';
|
package/dist/index.js
CHANGED
|
@@ -18,17 +18,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
RUNTIME_CHUNK_NAME: () => import_utils.RUNTIME_CHUNK_NAME,
|
|
22
|
+
RUNTIME_CHUNK_REGEX: () => import_utils.RUNTIME_CHUNK_REGEX,
|
|
23
|
+
SERVICE_WORKER_ENVIRONMENT_NAME: () => import_utils.SERVICE_WORKER_ENVIRONMENT_NAME,
|
|
24
|
+
castArray: () => import_utils.castArray,
|
|
25
|
+
createBuilder: () => import_createBuilder.createRspackBuilder,
|
|
26
|
+
isHtmlDisabled: () => import_utils.isHtmlDisabled,
|
|
27
|
+
logger: () => import_core.logger,
|
|
28
|
+
parseRspackConfig: () => import_createBuilder2.parseConfig
|
|
24
29
|
});
|
|
25
30
|
module.exports = __toCommonJS(src_exports);
|
|
26
31
|
var import_createBuilder = require("./createBuilder");
|
|
27
|
-
var
|
|
28
|
-
var
|
|
32
|
+
var import_core = require("@rsbuild/core");
|
|
33
|
+
var import_utils = require("./shared/utils");
|
|
34
|
+
var import_createBuilder2 = require("./createBuilder");
|
|
29
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
36
|
0 && (module.exports = {
|
|
31
|
-
|
|
37
|
+
RUNTIME_CHUNK_NAME,
|
|
38
|
+
RUNTIME_CHUNK_REGEX,
|
|
39
|
+
SERVICE_WORKER_ENVIRONMENT_NAME,
|
|
40
|
+
castArray,
|
|
32
41
|
createBuilder,
|
|
33
|
-
|
|
42
|
+
isHtmlDisabled,
|
|
43
|
+
logger,
|
|
44
|
+
parseRspackConfig
|
|
34
45
|
});
|
|
@@ -26,33 +26,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var babel_post_exports = {};
|
|
30
|
+
__export(babel_post_exports, {
|
|
31
|
+
pluginBabelPost: () => pluginBabelPost
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
const
|
|
37
|
-
name:
|
|
33
|
+
module.exports = __toCommonJS(babel_post_exports);
|
|
34
|
+
var import_isEqual = __toESM(require("lodash/isEqual"));
|
|
35
|
+
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
36
|
+
const pluginBabelPost = () => ({
|
|
37
|
+
name: "builder:babel-post",
|
|
38
38
|
setup(api) {
|
|
39
|
-
api.modifyBundlerChain(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
39
|
+
api.modifyBundlerChain({
|
|
40
|
+
handler: async (chain, { CHAIN_ID, environment }) => {
|
|
41
|
+
if (chain.module.rules.get(CHAIN_ID.RULE.JS)) {
|
|
42
|
+
const { cacheIdentifier, ...babelLoaderOptions } = chain.module.rule(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.BABEL).get("options");
|
|
43
|
+
const { config } = environment;
|
|
44
|
+
if (babelLoaderOptions && (0, import_isEqual.default)((0, import_plugin_babel.getDefaultBabelOptions)(config, api.context), babelLoaderOptions)) {
|
|
45
|
+
chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
// other plugins can modify babel config in modifyBundlerChain 'default order'
|
|
50
|
+
order: "post"
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
});
|
|
55
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
55
|
0 && (module.exports = {
|
|
57
|
-
|
|
56
|
+
pluginBabelPost
|
|
58
57
|
});
|
|
@@ -16,28 +16,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var devtools_exports = {};
|
|
20
|
+
__export(devtools_exports, {
|
|
21
|
+
pluginDevtool: () => pluginDevtool
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name: "builder-plugin-devtool",
|
|
23
|
+
module.exports = __toCommonJS(devtools_exports);
|
|
24
|
+
const pluginDevtool = (options) => ({
|
|
25
|
+
name: "builder:devtool",
|
|
27
26
|
setup(api) {
|
|
27
|
+
var _options_sourceMap;
|
|
28
|
+
const devtoolJs = typeof options.sourceMap === "boolean" || ((_options_sourceMap = options.sourceMap) === null || _options_sourceMap === void 0 ? void 0 : _options_sourceMap.js) !== void 0;
|
|
29
|
+
if (devtoolJs) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
28
32
|
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} else {
|
|
33
|
-
const prodDevTool = isServer ? "source-map" : "hidden-source-map";
|
|
34
|
-
const devtool = isProd ? prodDevTool : "cheap-module-source-map";
|
|
35
|
-
chain.devtool(devtool);
|
|
36
|
-
}
|
|
33
|
+
const prodDevTool = isServer ? "source-map" : "hidden-source-map";
|
|
34
|
+
const devtool = isProd ? prodDevTool : "cheap-module-source-map";
|
|
35
|
+
chain.devtool(devtool);
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
40
|
0 && (module.exports = {
|
|
42
|
-
|
|
41
|
+
pluginDevtool
|
|
43
42
|
});
|
|
@@ -26,27 +26,45 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var emitRouteFile_exports = {};
|
|
30
|
+
__export(emitRouteFile_exports, {
|
|
31
|
+
isFileExists: () => isFileExists,
|
|
32
|
+
pluginEmitRouteFile: () => pluginEmitRouteFile
|
|
32
33
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
module.exports = __toCommonJS(emitRouteFile_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = require("node:path");
|
|
37
|
+
async function isFileExists(file) {
|
|
38
|
+
return import_node_fs.default.promises.access(file, import_node_fs.default.constants.F_OK).then(() => true).catch(() => false);
|
|
39
|
+
}
|
|
40
|
+
const pluginEmitRouteFile = () => ({
|
|
41
|
+
name: "builder:emit-route-file",
|
|
36
42
|
setup(api) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
api.onBeforeStartDevServer(async ({ environments }) => {
|
|
44
|
+
const { fs: fs2, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
45
|
+
const routeFilePath = (0, import_node_path.join)(api.context.distPath, ROUTE_SPEC_FILE);
|
|
46
|
+
const htmlPaths = Object.values(environments).reduce((prev, curr) => {
|
|
47
|
+
return {
|
|
48
|
+
...prev,
|
|
49
|
+
...curr.htmlPaths
|
|
50
|
+
};
|
|
51
|
+
}, {});
|
|
52
|
+
const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index) => ({
|
|
53
|
+
urlPath: index === 0 ? "/" : `/${entryName}`,
|
|
54
|
+
entryName,
|
|
55
|
+
entryPath: filename,
|
|
56
|
+
isSPA: true
|
|
57
|
+
}));
|
|
58
|
+
if (!await isFileExists(routeFilePath) && routesInfo.length) {
|
|
59
|
+
await fs2.outputFile(routeFilePath, JSON.stringify({
|
|
60
|
+
routes: routesInfo
|
|
61
|
+
}, null, 2));
|
|
43
62
|
}
|
|
44
|
-
};
|
|
45
|
-
api.onBeforeBuild(clean);
|
|
46
|
-
api.onBeforeStartDevServer(clean);
|
|
63
|
+
});
|
|
47
64
|
}
|
|
48
65
|
});
|
|
49
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
67
|
0 && (module.exports = {
|
|
51
|
-
|
|
68
|
+
isFileExists,
|
|
69
|
+
pluginEmitRouteFile
|
|
52
70
|
});
|