@flatjs/evolve 3.1.0-next.0 → 3.1.0-next.1
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/dist/compiler/create-build-server-compiler.js +1 -1
- package/dist/default-options.js +1 -1
- package/dist/dev-server/middlewares/get-page-module-html.js +1 -1
- package/dist/helpers/assert-multi-html-cdn.d.ts +2 -0
- package/dist/helpers/assert-multi-html-cdn.js +1 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/main/prepare-build.js +1 -1
- package/dist/plugins/rspack/module-federation/index.js +1 -1
- package/dist/plugins/rspack/multi-html/index.js +1 -1
- package/dist/plugins/rspack/multi-html/multi-html-cdn-rspack-plugin.js +1 -1
- package/dist/plugins/rspack/multi-html/multi-html-rspack-plugin.js +1 -1
- package/dist/plugins/webpack/module-federation/index.js +1 -1
- package/dist/plugins/webpack/multi-html/index.js +1 -1
- package/dist/plugins/webpack/multi-html/multi-html-cdn-webpack-plugin.js +1 -1
- package/dist/plugins/webpack/multi-html/multi-html-webpack-plugins.js +1 -1
- package/dist/types/types-options.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import webpack from"webpack";import{ensureSlash,mergeOptions}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{loadWebpackConfig}from"../core/webpack/load-webpack-config.js";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{assertSingleWebpackCompiler}from"../helpers/assert-single-compiler.js";import{printCompilerError}from"../helpers/print-log.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";export const createBuildServerCompiler=async(r,o,e)=>{const t=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const
|
|
1
|
+
import webpack from"webpack";import{ensureSlash,mergeOptions}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{loadWebpackConfig}from"../core/webpack/load-webpack-config.js";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{assertMultiHtmlCdn}from"../helpers/assert-multi-html-cdn.js";import{assertSingleWebpackCompiler}from"../helpers/assert-single-compiler.js";import{printCompilerError}from"../helpers/print-log.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";export const createBuildServerCompiler=async(r,o,e)=>{const t=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const s=assertMultiHtmlCdn(o)?.prod||[];if(!s.length)throw new Error(`No CDN config for env:"prod", groupName: ${t.groupName}`);const i=ensureSlash(s[Math.floor(Math.random()*s.length)],!0);try{const s=t.options?.useRelativeAssetPath,n=mergeOptions(o,{webpack:{publicPath:s?"auto":i}}),p=await loadWebpackConfig("production",r,n,e),a=assertSingleWebpackCompiler(r,p,n,!1);return webpack(a)}catch(r){const o=printCompilerError(r);throw new EvolveBuildError("BUILD_ERROR",o)}};
|
package/dist/default-options.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",routeBaseName:"/pages",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},webSocketURL:"localIp",middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({}),bundleDirResolver:e=>e},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},globalCompilerOptions:{runTsChecker:!0},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},ci:{basedBranch:"origin/master"},isolation:!1,maxEntryGroupSize:10,compiler:"webpack",openRsdoctor:!1,inspector:{keys:["$mod","i"],customLaunchEditorEndpoint:"/__hps_inspector",trustedEditor:"code",injectClient:!0}};
|
|
1
|
+
export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",routeBaseName:"/pages",rejectWarnings:!1,channel:"default",devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},webSocketURL:"localIp",middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({}),bundleDirResolver:e=>e},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},lessOptions:{},postcssOptions:{cssnanoOptions:{}},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},globalCompilerOptions:{runTsChecker:!0},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0},ci:{basedBranch:"origin/master"},isolation:!1,maxEntryGroupSize:10,compiler:"webpack",openRsdoctor:!1,inspector:{keys:["$mod","i"],customLaunchEditorEndpoint:"/__hps_inspector",trustedEditor:"code",injectClient:!0}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../helpers/check-html-template-options.js";import{getHtmlMaxOrder,getHtmlMinOrder}from"../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{loadEnvConfig}from"../../helpers/load-env-config.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{ErrorModuleParser}from"./error-module-parser.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,n)=>{const{entryMap:s,projectVirtualPath:i}=n,a=Object.keys(s).sort((e,t)=>t.length-e.length),l=getPackageDir(),m=a.find(e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))});if(!m){const e=readFileSync(join(l,"./templates/module-404.html"),"utf-8");return new ErrorModuleParser(e,{title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:l},{name:"served entry names",value:JSON.stringify(a)},{name:"module path",value:`${t.path}`}]}).serialize()}const p=s[m],d=p.options,u=getDevServerHostUri(e,m,r),c=d?.templatePath||"./templates/module.html",g=join(n.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(c)?c:existsSync(g)?g:join(l,"./templates/module.html"),"utf-8"),f=n.devServer,v=f?.defaultServeGlobalData?await f.defaultServeGlobalData(p,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(m,i,e,f),S=normalizePageProxy(n.routeBaseName||"/pages"),H=normalizeTemplateInjectTokens(j,d);checkHtmlTemplateOptions(H);const
|
|
1
|
+
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import{parseTemplate}from"@hyperse/html-webpack-plugin-loader";import{envVariablesName}from"../../constants.js";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{assertMultiHtmlCdn}from"../../helpers/assert-multi-html-cdn.js";import{checkHtmlTemplateOptions}from"../../helpers/check-html-template-options.js";import{getHtmlMaxOrder,getHtmlMinOrder}from"../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{getRuntimeCDNBase}from"../../helpers/get-runtime-cdn-base.js";import{loadEnvConfig}from"../../helpers/load-env-config.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{normalizeTemplateInjectTokens}from"../../helpers/normalize-template-inject-tokens.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{ErrorModuleParser}from"./error-module-parser.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,n)=>{const{entryMap:s,projectVirtualPath:i}=n,a=Object.keys(s).sort((e,t)=>t.length-e.length),l=getPackageDir(),m=a.find(e=>{const r=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))});if(!m){const e=readFileSync(join(l,"./templates/module-404.html"),"utf-8");return new ErrorModuleParser(e,{title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:l},{name:"served entry names",value:JSON.stringify(a)},{name:"module path",value:`${t.path}`}]}).serialize()}const p=s[m],d=p.options,u=getDevServerHostUri(e,m,r),c=d?.templatePath||"./templates/module.html",g=join(n.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(c)?c:existsSync(g)?g:join(l,"./templates/module.html"),"utf-8"),f=n.devServer,v=f?.defaultServeGlobalData?await f.defaultServeGlobalData(p,r):{},j={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(m,i,e,f),S=normalizePageProxy(n.routeBaseName||"/pages"),H=normalizeTemplateInjectTokens(j,d);checkHtmlTemplateOptions(H);const M=parseTemplate(h);M.upsertTitleTag(getHtmlPluginConfig("title",j,d?.title));const N=H.favicon;N&&M.upsertFaviconTag(N.href,N.rel,N.attributes);const P=H.headMetaTags||[];M.upsertHeadMetaTags(P);const b=H.headStyles||[],w=getHtmlMaxOrder(b),C=getBundleAsset(u,y,".css");b.push({id:C,href:C,position:"end",order:w+1}),M.upsertHeadStyles(b);const k=H.headScripts||[],x=getHtmlMinOrder(k);getHmrRuntimeChunks(e,m,y,p,n,u).forEach(e=>{k.unshift({id:e,src:e,position:"end",order:x-1})}),M.upsertHeadScripts(k);const z=H.headInlineScripts||[],O=getHtmlMaxOrder(z),E=getHtmlMinOrder(z),T=Math.min(E,x),B=await loadEnvConfig("me",n)||{};z.push({id:"envVariables",content:`window.${envVariablesName}=${JSON.stringify({env:"me",appName:n.projectVirtualPath,routeBaseName:n.routeBaseName,projectVirtualPath:i,moduleName:m.replace(i,"").replace(/^\//,""),...B})}`,position:"beginning",order:-99});const D={hostUrl:r,apiBase:urlJoin(r,[o]),virtualPath:join(S,i),moduleName:m.replace(i,"").replace(/^\//,""),...v,...d?.serveGlobalData||{}};z.push({id:"globalData",content:`window.GLOBAL=${JSON.stringify(D)}`,position:"end",order:T-2}),allowPx2remForModule([m,p],n)&&z.push({id:"viewport",content:getHtmlPluginConfig("viewport",j,d?.viewport),position:"end",order:E-1});const F=getRuntimeCDNBase(assertMultiHtmlCdn(n),n.multiHtmlCdnEnvResolver||function cdnResolver(){});z.push({id:"flatjsMultiCdn",content:F,position:"end",order:O+1});const J=injectFederationScripts({me:[urlJoin(r,["public"])]},n.multiHtmlCdnEnvResolver);z.push({id:"evolveFetchMicroWidgets",content:J,position:"end",order:O+2}),M.upsertHeadInlineScripts(z);const R=H.headInlineStyles||[];M.upsertHeadInlineStyles(R);const A=H.bodyScripts||[],I=getHtmlMaxOrder(A),V=getBundleAsset(u,y,".js");return A.push({id:V,src:V,position:"end",order:I+1}),M.upsertBodyScripts(A),M.serialize()};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const assertMultiHtmlCdn=t=>{const{multiHtmlCdn:n,channel:e="default"}=t;return"function"==typeof n?n(e):n};
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./allow-px2rem-for-module.js";export*from"./assert-group-entry-item.js";export*from"./assert-single-compiler.js";export*from"./check-runtime-env.js";export*from"./chunk-entry-map.js";export*from"./custom-listr-renderer.js";export*from"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.js";export*from"./format-spinner-text.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./get-runtime-cdn-base.js";export*from"./get-stats-file-name.js";export*from"./is-deep-equal.js";export*from"./json-serializer.js";export*from"./merge-babel-options.js";export*from"./normalize-check-entry-options.js";export*from"./normalize-entry-map.js";export*from"./normalize-group-name.js";export*from"./normalize-page-proxy.js";export*from"./normalize-resolve-alias.js";export*from"./normalize-template-inject-tokens.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-entry-group.js";export*from"./verify-group-entry-options.js";
|
|
1
|
+
export*from"./allow-px2rem-for-module.js";export*from"./assert-group-entry-item.js";export*from"./assert-multi-html-cdn.js";export*from"./assert-single-compiler.js";export*from"./check-runtime-env.js";export*from"./chunk-entry-map.js";export*from"./custom-listr-renderer.js";export*from"./delete-object-keys.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./flat-entry-map.js";export*from"./format-spinner-text.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./get-runtime-cdn-base.js";export*from"./get-stats-file-name.js";export*from"./is-deep-equal.js";export*from"./json-serializer.js";export*from"./merge-babel-options.js";export*from"./normalize-check-entry-options.js";export*from"./normalize-entry-map.js";export*from"./normalize-group-name.js";export*from"./normalize-page-proxy.js";export*from"./normalize-resolve-alias.js";export*from"./normalize-template-inject-tokens.js";export*from"./open-page.js";export*from"./print-log.js";export*from"./refresh-evolve-mock-options.js";export*from"./script-injects.js";export*from"./should-enable-react-fast-refresh.js";export*from"./split-to-entry-group.js";export*from"./verify-group-entry-options.js";
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./build-server/index.js";export*from"./define-config/index.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-build.js";export*from"./types/types-cli-options.js";export*from"./types/types-entry-map.js";export*from"./types/types-options.js";
|
|
1
|
+
export*from"./build-server/index.js";export*from"./define-config/index.js";export*from"./helpers/assert-multi-html-cdn.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-build.js";export*from"./types/types-cli-options.js";export*from"./types/types-entry-map.js";export*from"./types/types-options.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ensureSlash,mergeOptions}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{startRspackBuild}from"../core/rspack/start-rspack-build.js";import{startWebpackBuild}from"../core/webpack/index.js";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{printCompilerError}from"../helpers/print-log.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";export const prepareBuild=async(r,o,t)=>{const{compiler:e}=o,s=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const i=o
|
|
1
|
+
import{ensureSlash,mergeOptions}from"@flatjs/common";import{ignoreEntryOptionKeys}from"../constants.js";import{startRspackBuild}from"../core/rspack/start-rspack-build.js";import{startWebpackBuild}from"../core/webpack/index.js";import{EvolveBuildError}from"../errors/evolve-build-error.js";import{assertMultiHtmlCdn}from"../helpers/assert-multi-html-cdn.js";import{printCompilerError}from"../helpers/print-log.js";import{verifyGroupEntryOptions}from"../helpers/verify-group-entry-options.js";export const prepareBuild=async(r,o,t)=>{const{compiler:e}=o,s=Object.values(r)[0];if(!verifyGroupEntryOptions(r,ignoreEntryOptionKeys,!0))throw new Error("The entry options in a group must be the same.");const i=assertMultiHtmlCdn(o)?.prod||[];if(!i.length)throw new Error(`No CDN config for env:"prod", groupName: ${s.groupName}`);const p=ensureSlash(i[Math.floor(Math.random()*i.length)],!0);try{const i=s.options?.useRelativeAssetPath,n=mergeOptions(o,{webpack:{publicPath:i?"auto":p}});return"webpack"===e?await startWebpackBuild(r,n,t):await startRspackBuild(r,n,t)}catch(r){const o=printCompilerError(r);throw new EvolveBuildError("BUILD_ERROR",o)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{normalizeEvolveEntryName}from"../../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../../helpers/script-injects.js";import{HtmlInjectScriptWebpackPlugin}from"../../webpack/html-inject-scripts/index.js";import{ExternalTemplateRemotesRspackPlugin}from"./external-template-remotes-rspack-plugin.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationRspackPlugins=(e,t,r)=>{const o=r.projectVirtualPath,n=r
|
|
1
|
+
import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{normalizeEvolveEntryName}from"../../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../../helpers/script-injects.js";import{HtmlInjectScriptWebpackPlugin}from"../../webpack/html-inject-scripts/index.js";import{ExternalTemplateRemotesRspackPlugin}from"./external-template-remotes-rspack-plugin.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationRspackPlugins=(e,t,r)=>{const o=r.projectVirtualPath,n=assertMultiHtmlCdn(r),m=r.multiHtmlCdnEnvResolver,i=[];for(const r of t){const[t,s]=r,a=s.options?.moduleFederation;if(a){const{remotes:r,exposes:s,...l}=a,p=remoteFileName(t),c=normalizeWidgetName(t),u=(s?Array.isArray(s)?s:[s]:[]).map(e=>{const r={};for(const[o,n]of Object.entries(e))r[o]={...n,name:join(t,n.name.replace(/^\//,""))};return r}),d=(r||[]).map(({name:e,endpoint:t})=>{const r=normalizeEvolveEntryName(e,o),n=normalizeWidgetName(r),m=remoteFileName(r),i=t?ensureSlash(t(e,r),!1):"[window.evolveFetchMicroWidgets()]";return{[n]:`${n}@${i}/${m}`}});i.push(new rspack.container.ModuleFederationPlugin({...l,name:c,filename:p,remotes:d,exposes:u}),new ExternalTemplateRemotesRspackPlugin),e||i.unshift(new HtmlInjectScriptWebpackPlugin([injectFederationScripts(n,m)]))}}return i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FlatEvolveMultiCdnRspackPlugin}from"./multi-html-cdn-rspack-plugin.js";import{createMultiHtmlRspackPlugins}from"./multi-html-rspack-plugin.js";export const createHtmlRspackPlugins=async(t,l,s)=>{const i=[];if(t)return i;const n=Object.keys(s
|
|
1
|
+
import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{FlatEvolveMultiCdnRspackPlugin}from"./multi-html-cdn-rspack-plugin.js";import{createMultiHtmlRspackPlugins}from"./multi-html-rspack-plugin.js";export const createHtmlRspackPlugins=async(t,l,s)=>{const i=[];if(t)return i;const n=Object.keys(assertMultiHtmlCdn(s));return i.push(...await createMultiHtmlRspackPlugins(t,s,l,n)),i.push(new FlatEvolveMultiCdnRspackPlugin(s,l)),i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnRspackPlugin{constructor(e
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnRspackPlugin{constructor(t,e){if(this.pluginName="FlatEvolveMultiCdnRspackPlugin",this.requireFn=rspack.RuntimeGlobals.publicPath,this.config=assertMultiHtmlCdn(t),this.entryMapItemList=e,this.cdnResolver=t.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(t){t.hooks.compilation.tap(this.pluginName,t=>{t.hooks.runtimeModule.tap(this.pluginName,(t,e)=>{const s=this.entryMapItemList.find(t=>t[0]===e.name);if("public_path"===t.name&&s&&t.source){const e=t.source.source.toString("utf-8"),s=["","// Dynamic assets path override...",getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn)].join("\n");t.source.source=Buffer.from(`${e}\n${s}`,"utf-8")}})}),t.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,t=>{const{assets:e,plugin:s,outputName:n}=t,i=s?.options?.chunks||[],r=Array.isArray(i)?i.find(t=>n.includes(ensureSlash(t,!0))):i,{userOptions:o}=t.plugin;if(!r)throw new Error("We must have current chunk!");const a=e.js.filter(t=>t.includes(ensureSlash(r,!0))),l=e.css.filter(t=>t.includes(ensureSlash(r,!0))),p=o.multiCdn,u=e.publicPath,c=a.map(t=>{if(p.disabled)return basename(t);const e=findEnvCdn(this.config,p.env);return httpUrlJoin(e,t.replace(u,""))}),m=l.map(t=>{if(p.disabled)return basename(t);const e=findEnvCdn(this.config,p.env);return httpUrlJoin(e,t.replace(u,""))});return t.assets.js=c,t.assets.css=m,t}),e.hooks.processAssets.tap({name:this.pluginName,stage:t.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE},s=>{if(t.options.output.library)for(const t of Object.keys(s))t.endsWith(".html")&&delete e.assets[t]})})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyRspackPlugin}from"./multi-html-modify-rspack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlRspackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyRspackPlugin(t,l)],{options:r}=n,
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyRspackPlugin}from"./multi-html-modify-rspack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlRspackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyRspackPlugin(t,l)],{options:r}=n,s=e?"development":"production",p=l.map(e=>e[0]);for(const e of i){const l={mode:s,envCdn:findEnvCdn(assertMultiHtmlCdn(t),e)},i=normalizeTemplateInjectTokens(l,r);checkHtmlTemplateOptions(i);const n=i?.headInlineScripts||[];if(allowPx2remForModule(o,t)){const e=getHtmlMinOrder(n),t=getHtmlPluginConfig("viewport",l,r?.viewport);n.push({id:"viewport",content:t,position:"end",order:e-1})}let a=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(a)||(logger.warn(`The template file ${a} is not exists, use \`prod\` instead!`),a=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod"));a=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${a}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:p,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:a,templateParameters:{title:"",...i,headInlineScripts:n},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{normalizeEvolveEntryName}from"../../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../../helpers/script-injects.js";import{HtmlInjectScriptWebpackPlugin}from"../html-inject-scripts/index.js";import{ExternalTemplateRemotesWebpackPlugin}from"./external-template-remotes-webpack-plugin.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationWebpackPlugins=(e,t,
|
|
1
|
+
import{join}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{normalizeEvolveEntryName}from"../../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../../helpers/script-injects.js";import{HtmlInjectScriptWebpackPlugin}from"../html-inject-scripts/index.js";import{ExternalTemplateRemotesWebpackPlugin}from"./external-template-remotes-webpack-plugin.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationWebpackPlugins=(e,t,r)=>{const o=r.projectVirtualPath,n=assertMultiHtmlCdn(r),m=r.multiHtmlCdnEnvResolver,i=[];for(const r of t){const[t,a]=r,s=a.options?.moduleFederation;if(s){const{remotes:r,exposes:a,...l}=s,p=remoteFileName(t),c=normalizeWidgetName(t),u=(a?Array.isArray(a)?a:[a]:[]).map(e=>{const r={};for(const[o,n]of Object.entries(e))r[o]={...n,name:join(t,n.name.replace(/^\//,""))};return r}),d=(r||[]).map(({name:e,endpoint:t})=>{const r=normalizeEvolveEntryName(e,o),n=normalizeWidgetName(r),m=remoteFileName(r),i=t?ensureSlash(t(e,r),!1):"[window.evolveFetchMicroWidgets()]";return{[n]:`${n}@${i}/${m}`}});i.push(new webpack.container.ModuleFederationPlugin({...l,name:c,filename:p,remotes:d,exposes:u}),new ExternalTemplateRemotesWebpackPlugin),e||i.unshift(new HtmlInjectScriptWebpackPlugin([injectFederationScripts(n,m)]))}}return i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FlatEvolveMultiCdnWebpackPlugin}from"./multi-html-cdn-webpack-plugin.js";import{createMultiHtmlWebpackPlugins}from"./multi-html-webpack-plugins.js";export const createHtmlWebpackPlugins=async(t,l,e)=>{const i=[];if(t)return i;const
|
|
1
|
+
import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{FlatEvolveMultiCdnWebpackPlugin}from"./multi-html-cdn-webpack-plugin.js";import{createMultiHtmlWebpackPlugins}from"./multi-html-webpack-plugins.js";export const createHtmlWebpackPlugins=async(t,l,e)=>{const i=[];if(t)return i;const s=Object.keys(assertMultiHtmlCdn(e));return i.push(...await createMultiHtmlWebpackPlugins(t,e,l,s)),i.push(new FlatEvolveMultiCdnWebpackPlugin(e)),i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnWebpackPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnWebpackPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnWebpackPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnWebpackPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=assertMultiHtmlCdn(e),this.cdnResolver=e.multiHtmlCdnEnvResolver||function cdnResolver(){},!this.config?.prod)throw new Error("We must setup `prod` for each CDN config node!")}apply(e){e.hooks.thisCompilation.tap(this.pluginName,e=>{e.mainTemplate.hooks.requireExtensions.tap(this.pluginName,(t,s)=>{const n=[];n.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const i=e.chunkGraph?.getTreeRuntimeRequirements(s);return i&&i.has(webpack.RuntimeGlobals.requireScope)&&n.push(webpack.Template.indent(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn))),webpack.Template.asString(n)})}),e.hooks.compilation.tap(this.pluginName,t=>{HtmlWebpackPlugin.getHooks(t).beforeAssetTagGeneration.tap(this.pluginName,e=>{const{assets:t,plugin:s,outputName:n}=e,i=s?.options?.chunks||[],r=Array.isArray(i)?i.find(e=>n.includes(ensureSlash(e,!0))):i,{userOptions:o}=e.plugin;if(!r)throw new Error("We must have current chunk!");const a=t.js.filter(e=>e.includes(ensureSlash(r,!0))),l=t.css.filter(e=>e.includes(ensureSlash(r,!0))),p=o.multiCdn,u=t.publicPath,m=a.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}),c=l.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))});return e.assets.js=m,e.assets.css=c,e}),t.hooks.processAssets.tap({name:this.pluginName,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE},s=>{if(e.options.output.library)for(const e of Object.keys(s))e.endsWith(".html")&&delete t.assets[e]})})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyWebpackPlugin}from"./multi-html-modify-webpack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyWebpackPlugin(t,l)],{options:r}=n,p=e?"development":"production",s=l.map(e=>e[0]);for(const e of i){const l={mode:p,envCdn:findEnvCdn(t
|
|
1
|
+
import HtmlWebpackPlugin from"html-webpack-plugin";import{existsSync}from"node:fs";import{logger,requireResolve}from"@flatjs/common";import{allowPx2remForModule}from"../../../helpers/allow-px2rem-for-module.js";import{assertMultiHtmlCdn}from"../../../helpers/assert-multi-html-cdn.js";import{checkHtmlTemplateOptions}from"../../../helpers/check-html-template-options.js";import{getHtmlMinOrder}from"../../../helpers/get-html-max-order.js";import{getHtmlPluginConfig}from"../../../helpers/get-html-plugin-config.js";import{normalizeTemplateInjectTokens}from"../../../helpers/normalize-template-inject-tokens.js";import{findEnvCdn}from"../../../helpers/script-injects.js";import{MultiHtmlModifyWebpackPlugin}from"./multi-html-modify-webpack-plugin.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugins=async(e,t,l,i)=>{const o=l[0],[,n]=o,m=[new MultiHtmlModifyWebpackPlugin(t,l)],{options:r}=n,p=e?"development":"production",s=l.map(e=>e[0]);for(const e of i){const l={mode:p,envCdn:findEnvCdn(assertMultiHtmlCdn(t),e)},i=normalizeTemplateInjectTokens(l,r);checkHtmlTemplateOptions(i);const n=i?.headInlineScripts||[],a=getHtmlMinOrder(n);if(allowPx2remForModule(o,t)){const e=getHtmlPluginConfig("viewport",l,r?.viewport);n.unshift({id:"viewport",content:e,position:"end",order:a-1})}let c=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}",e.trim());existsSync(c)||(logger.warn(`The template file ${c} is not exists, use \`prod\` instead!`),c=getHtmlPluginConfig("templatePath",l,r?.templatePath).replace("{0}","prod"));c=`${requireResolve(import.meta.url,"@hyperse/html-webpack-plugin-loader/loader")}!${c}`,m.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",l,r?.title),chunks:s,minify:!1!==r?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:t=>`${t}/index${"prod"===e?"":`-${e}`}.html`,template:c,templateParameters:{title:"",...i,headInlineScripts:n},multiCdn:{env:e,disabled:(r?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}))}return m};
|
|
@@ -71,12 +71,17 @@ export interface FlatEvolveOptions {
|
|
|
71
71
|
* The configurations of `dev-server`.
|
|
72
72
|
*/
|
|
73
73
|
devServer?: FlatEvolveDevServerOptions;
|
|
74
|
+
/**
|
|
75
|
+
* The channel of build environment.
|
|
76
|
+
* @default 'default'
|
|
77
|
+
*/
|
|
78
|
+
channel?: FlatEvolveChannel;
|
|
74
79
|
/**
|
|
75
80
|
* We can define multiple `CDN` for my project.
|
|
76
81
|
* --
|
|
77
82
|
* Note: We do not support `//` as prefix please use `https://` or `http://`
|
|
78
83
|
*/
|
|
79
|
-
multiHtmlCdn: EvolveMultiCDNConfig;
|
|
84
|
+
multiHtmlCdn: EvolveMultiCDNConfig | ((channel: FlatEvolveChannel) => EvolveMultiCDNConfig);
|
|
80
85
|
/**
|
|
81
86
|
* Allow us customized to resolve current runtime environment.
|
|
82
87
|
* ignore resolver if return undefined, otherwise use it to match environment.
|
|
@@ -191,3 +196,4 @@ export interface FlatEvolveOptions {
|
|
|
191
196
|
*/
|
|
192
197
|
codeChecker?: CodeCheckerPluginOptions;
|
|
193
198
|
}
|
|
199
|
+
export type FlatEvolveChannel = 'default' | string;
|