@flatjs/evolve 1.7.2 → 1.8.1-next.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +10 -46
  4. package/dist/constants.d.ts +15 -0
  5. package/dist/constants.js +1 -0
  6. package/dist/create-webpack/create-externals.d.ts +4 -0
  7. package/dist/create-webpack/create-externals.js +1 -0
  8. package/dist/create-webpack/create-optimization.d.ts +3 -0
  9. package/dist/create-webpack/create-optimization.js +1 -0
  10. package/dist/create-webpack/create-output.d.ts +3 -0
  11. package/dist/create-webpack/create-output.js +1 -0
  12. package/dist/create-webpack/create-performance.d.ts +2 -0
  13. package/dist/create-webpack/create-performance.js +1 -0
  14. package/dist/create-webpack/create-plugins.d.ts +4 -0
  15. package/dist/create-webpack/create-plugins.js +1 -0
  16. package/dist/create-webpack/create-resolve.d.ts +2 -0
  17. package/dist/create-webpack/create-resolve.js +1 -0
  18. package/dist/create-webpack/create-rule-sets.d.ts +4 -0
  19. package/dist/create-webpack/create-rule-sets.js +1 -0
  20. package/dist/create-webpack/load-webpack-config.d.ts +10 -0
  21. package/dist/create-webpack/load-webpack-config.js +1 -0
  22. package/dist/create-webpack/rule-sets/constants.d.ts +3 -0
  23. package/dist/create-webpack/rule-sets/constants.js +1 -0
  24. package/dist/create-webpack/rule-sets/rule-assets.d.ts +10 -0
  25. package/dist/create-webpack/rule-sets/rule-assets.js +1 -0
  26. package/dist/create-webpack/rule-sets/rule-css.d.ts +11 -0
  27. package/dist/create-webpack/rule-sets/rule-css.js +1 -0
  28. package/dist/create-webpack/rule-sets/rule-less.d.ts +9 -0
  29. package/dist/create-webpack/rule-sets/rule-less.js +1 -0
  30. package/dist/create-webpack/rule-sets/rule-scripts.d.ts +3 -0
  31. package/dist/create-webpack/rule-sets/rule-scripts.js +1 -0
  32. package/dist/create-webpack/rule-sets/rule-svg-icon.d.ts +6 -0
  33. package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -0
  34. package/dist/create-webpack/rule-sets/rule-utils.d.ts +7 -0
  35. package/dist/create-webpack/rule-sets/rule-utils.js +1 -0
  36. package/dist/create-webpack/types.d.ts +2 -0
  37. package/dist/create-webpack/types.js +1 -0
  38. package/dist/default-options.d.ts +2 -0
  39. package/dist/default-options.js +1 -0
  40. package/dist/define-config/define-config.d.ts +6 -0
  41. package/dist/define-config/define-config.js +1 -0
  42. package/dist/define-config/index.d.ts +1 -0
  43. package/dist/define-config/index.js +1 -0
  44. package/dist/dev-server/add-compiler-to-dev-server.d.ts +10 -0
  45. package/dist/dev-server/add-compiler-to-dev-server.js +1 -0
  46. package/dist/dev-server/create-app-page-route.d.ts +7 -0
  47. package/dist/dev-server/create-app-page-route.js +1 -0
  48. package/dist/dev-server/create-dev-server-compiler-tasks.d.ts +3 -0
  49. package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -0
  50. package/dist/dev-server/create-dev-server-entries.d.ts +4 -0
  51. package/dist/dev-server/create-dev-server-entries.js +1 -0
  52. package/dist/dev-server/create-dev-server.d.ts +6 -0
  53. package/dist/dev-server/create-dev-server.js +1 -0
  54. package/dist/dev-server/index.d.ts +6 -0
  55. package/dist/dev-server/index.js +1 -0
  56. package/dist/dev-server/middlewares/create-page-middleware.d.ts +37 -0
  57. package/dist/dev-server/middlewares/create-page-middleware.js +1 -0
  58. package/dist/dev-server/middlewares/create-public-assets-middleware.d.ts +2 -0
  59. package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -0
  60. package/dist/dev-server/middlewares/index.d.ts +2 -0
  61. package/dist/dev-server/middlewares/index.js +1 -0
  62. package/dist/helpers/allow-px2rem-for-module.d.ts +3 -0
  63. package/dist/helpers/allow-px2rem-for-module.js +1 -0
  64. package/dist/helpers/assert-only-single-entry-item.d.ts +7 -0
  65. package/dist/helpers/assert-only-single-entry-item.js +1 -0
  66. package/dist/helpers/enable-bundle-hashname-for-module.d.ts +3 -0
  67. package/dist/helpers/enable-bundle-hashname-for-module.js +1 -0
  68. package/dist/helpers/get-bundle-file-name.d.ts +14 -0
  69. package/dist/helpers/get-bundle-file-name.js +1 -0
  70. package/dist/helpers/get-html-plugin-config.d.ts +12 -0
  71. package/dist/helpers/get-html-plugin-config.js +1 -0
  72. package/dist/helpers/get-pacakge-dir.d.ts +1 -0
  73. package/dist/helpers/get-pacakge-dir.js +1 -0
  74. package/dist/helpers/index.d.ts +14 -0
  75. package/dist/helpers/index.js +1 -0
  76. package/dist/helpers/merge-babel-options.d.ts +4 -0
  77. package/dist/helpers/merge-babel-options.js +1 -0
  78. package/dist/helpers/normalize-entry-map.d.ts +15 -0
  79. package/dist/helpers/normalize-entry-map.js +1 -0
  80. package/dist/helpers/open-page.d.ts +7 -0
  81. package/dist/helpers/open-page.js +1 -0
  82. package/dist/helpers/print-log.d.ts +2 -0
  83. package/dist/helpers/print-log.js +1 -0
  84. package/dist/helpers/refresh-evolve-mock-options.d.ts +3 -0
  85. package/dist/helpers/refresh-evolve-mock-options.js +1 -0
  86. package/dist/helpers/script-injects.d.ts +11 -0
  87. package/dist/helpers/script-injects.js +1 -0
  88. package/dist/helpers/should-enable-react-fast-refresh.d.ts +3 -0
  89. package/dist/helpers/should-enable-react-fast-refresh.js +1 -0
  90. package/dist/helpers/split-to-multi-compiler.d.ts +8 -0
  91. package/dist/helpers/split-to-multi-compiler.js +1 -0
  92. package/dist/index.d.ts +4 -0
  93. package/dist/index.js +1 -0
  94. package/dist/load-config/index.d.ts +1 -0
  95. package/dist/load-config/index.js +1 -0
  96. package/dist/load-config/load-evolve-config.d.ts +9 -0
  97. package/dist/load-config/load-evolve-config.js +1 -0
  98. package/dist/loaders/loader-icon.cjs +33 -0
  99. package/dist/loaders/loader-icon.d.cts +1 -0
  100. package/dist/main/env-verify.d.ts +2 -0
  101. package/dist/main/env-verify.js +1 -0
  102. package/dist/main/index.d.ts +3 -0
  103. package/dist/main/index.js +1 -0
  104. package/dist/main/prepare-build.d.ts +13 -0
  105. package/dist/main/prepare-build.js +1 -0
  106. package/dist/main/prepare-serve.d.ts +9 -0
  107. package/dist/main/prepare-serve.js +1 -0
  108. package/dist/main/prepare-static.d.ts +7 -0
  109. package/dist/main/prepare-static.js +1 -0
  110. package/dist/main/start-build.d.ts +13 -0
  111. package/dist/main/start-build.js +1 -0
  112. package/dist/main/start-serve.d.ts +11 -0
  113. package/dist/main/start-serve.js +1 -0
  114. package/dist/main/start-static.d.ts +10 -0
  115. package/dist/main/start-static.js +1 -0
  116. package/dist/minimizer/create-minimizers.d.ts +3 -0
  117. package/dist/minimizer/create-minimizers.js +1 -0
  118. package/dist/minimizer/default-options.d.ts +2 -0
  119. package/dist/minimizer/default-options.js +1 -0
  120. package/dist/minimizer/image-minimizer.d.ts +7 -0
  121. package/dist/minimizer/image-minimizer.js +1 -0
  122. package/dist/minimizer/index.d.ts +1 -0
  123. package/dist/minimizer/index.js +1 -0
  124. package/dist/minimizer/terser-minimizer.d.ts +6 -0
  125. package/dist/minimizer/terser-minimizer.js +3 -0
  126. package/dist/minimizer/types.d.ts +2 -0
  127. package/dist/minimizer/types.js +1 -0
  128. package/dist/plugins/clean-webpack/clean-webpack-plugin.d.ts +67 -0
  129. package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -0
  130. package/dist/plugins/clean-webpack/index.d.ts +9 -0
  131. package/dist/plugins/clean-webpack/index.js +1 -0
  132. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.d.ts +8 -0
  133. package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -0
  134. package/dist/plugins/module-federation/external-template-remotes.d.ts +4 -0
  135. package/dist/plugins/module-federation/external-template-remotes.js +1 -0
  136. package/dist/plugins/module-federation/index.d.ts +1 -0
  137. package/dist/plugins/module-federation/index.js +1 -0
  138. package/dist/plugins/module-federation/module-federation.d.ts +4 -0
  139. package/dist/plugins/module-federation/module-federation.js +1 -0
  140. package/dist/plugins/multi-html/index.d.ts +4 -0
  141. package/dist/plugins/multi-html/index.js +1 -0
  142. package/dist/plugins/multi-html/multi-html-cdn-plugin.d.ts +17 -0
  143. package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -0
  144. package/dist/plugins/multi-html/multi-html-plugin.d.ts +11 -0
  145. package/dist/plugins/multi-html/multi-html-plugin.js +1 -0
  146. package/dist/types/index.d.ts +8 -0
  147. package/dist/types/index.js +1 -0
  148. package/dist/types/types-dev-server.d.ts +51 -0
  149. package/dist/types/types-dev-server.js +1 -0
  150. package/dist/types/types-entry-map.d.ts +66 -0
  151. package/dist/types/types-entry-map.js +1 -0
  152. package/dist/types/types-federation.d.ts +120 -0
  153. package/dist/types/types-federation.js +1 -0
  154. package/dist/types/types-loader-options.d.ts +61 -0
  155. package/dist/types/types-loader-options.js +1 -0
  156. package/dist/types/types-modular-import.d.ts +38 -0
  157. package/dist/types/types-modular-import.js +1 -0
  158. package/dist/types/types-multi-html.d.ts +74 -0
  159. package/dist/types/types-multi-html.js +1 -0
  160. package/dist/types/types-options.d.ts +98 -0
  161. package/dist/types/types-options.js +1 -0
  162. package/dist/types/types-webpack.d.ts +70 -0
  163. package/dist/types/types-webpack.js +1 -0
  164. package/index.js +1 -4
  165. package/package.json +107 -59
  166. package/templates/html-plugin/index-dev.html +34 -50
  167. package/templates/html-plugin/index-inte.html +34 -50
  168. package/templates/html-plugin/index-inte2.html +34 -50
  169. package/templates/html-plugin/index-inte3.html +34 -50
  170. package/templates/html-plugin/index-inte4.html +34 -50
  171. package/templates/html-plugin/index-me.html +34 -50
  172. package/templates/html-plugin/index-prod.html +34 -50
  173. package/templates/html-plugin/index-rc.html +33 -50
  174. package/templates/html-plugin/index-uat.html +34 -50
  175. package/templates/main.html +2 -2
  176. package/templates/module-404.html +4 -2
  177. package/templates/module.html +51 -66
  178. package/cjs/index.js +0 -4
  179. package/cjs/loader-icon.js +0 -2
  180. package/index.d.ts +0 -713
@@ -0,0 +1,15 @@
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ /**
3
+ * Make sure that we have correct `virtualPath` for each webpack `entry`
4
+ * @param entryName the entryName defined via `flatjs-evolve.config.mts`.
5
+ * @param evolveOptions
6
+ * @returns
7
+ */
8
+ export declare const normalizeEvolveEntryName: (entryName: string, projectVirtualPath: string) => string;
9
+ /**
10
+ * Normalize flatjs.evolve entry map definition data.
11
+ * Merge default entry item configuration values.
12
+ * @param activedEntryMap actived entries
13
+ * @param definedEntryMap defined entries in flatjs.evolve.js
14
+ */
15
+ export declare const normalizeEvolveEntryMap: (activedEntryMap?: EvolveEntryMap, definedEntryMap?: EvolveEntryMap) => EvolveEntryMap;
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import _ from"lodash";export const normalizeEvolveEntryName=(o,e)=>{const r=o.replace(/^\//,""),t=e.replace(/^\//,"");return(r.startsWith(t)?r:join(t,r)).replace(/\/$/,"")};export const normalizeEvolveEntryMap=(o={},e={})=>{const r={};for(const[t,n]of Object.entries(e)){const e={options:{}};o[t]&&(r[t]=_.merge({},e,n,o[t])),_.merge(n,e)}return r};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A better opn. Reuse the same tab on Chrome for
3
+ * @example
4
+ * `http://xxx.domain.com:3001/pages`
5
+ * @param openUrl the page url try to open.
6
+ */
7
+ export declare const openPage: (openUrl: string) => void;
@@ -0,0 +1 @@
1
+ import opn from"better-opn";export const openPage=n=>{try{opn(n)}catch(n){console.warn("Unable to open browser. If you are running in a headless environment\n")}};
@@ -0,0 +1,2 @@
1
+ export declare const printInfo: (message: string, silent?: boolean) => void;
2
+ export declare const printError: (message: string | Error) => void;
@@ -0,0 +1 @@
1
+ import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";export const printInfo=(o,r=!1)=>{r||logger.info(o,moduleName)};export const printError=o=>{logger.error(o,moduleName)};
@@ -0,0 +1,3 @@
1
+ import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export declare const refreshEvolveMockOptions: (projectCwd: string, evolveOptions: FlatEvolveOptions, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
@@ -0,0 +1 @@
1
+ import{loadMockConfig}from"@flatjs/mock";import _ from"lodash";export const refreshEvolveMockOptions=async(o,t,s)=>{const c=t.devServer,i=await loadMockConfig(o,c?.mockOptions||{},_.merge({},s,{configFile:"flatjs-mock"}));return c&&(c.mockOptions=i||{},c.mockOptions&&!c.mockOptions.https&&(c.mockOptions.https=c?.https)),t};
@@ -0,0 +1,11 @@
1
+ import { type EvolveMultiCdnEnvType, type EvolveMultiCDNConfig, type EvolveMultiCDNEnvResolver } from '../types/types-multi-html.js';
2
+ export declare function httpUrlJoin(first?: string, second?: string): string;
3
+ /**
4
+ * To extract the best matched CDN configuration url address, either use URL `query.env` or customize the `envRresolver`
5
+ * @param cdnConfig List of pre-configured cdn urls for each environment
6
+ * @param envResolver Get the specific environment variable by the currently requested host url address.
7
+ * @returns Returns the best matching address with a suffix (`/`)
8
+ */
9
+ export declare function cdnFinder(cdnConfig: EvolveMultiCDNConfig, envResolver?: EvolveMultiCDNEnvResolver): string;
10
+ export declare function findEnvCdn(cdnConfig?: EvolveMultiCDNConfig, env?: EvolveMultiCdnEnvType): string;
11
+ export declare function injectFederationScripts(cdnConfig: EvolveMultiCDNConfig, cdnResolver?: EvolveMultiCDNEnvResolver): string;
@@ -0,0 +1 @@
1
+ export function httpUrlJoin(n="",e=""){return n.replace(/\/$/,"")+"/"+e.replace(/^\//,"")}export function cdnFinder(n,e){const r=window.location.href,o=/[?&]env(=([^&#]*)|&|#|$)/.exec(r);let t=o&&o[2]?decodeURIComponent(o[2].replace(/\+/g," ")):"prod";t=e&&e(r)||t;const c=n[t]||n.prod||[];return c[Math.floor(Math.random()*c.length)].replace(/\/$/,"")+"/"}export function findEnvCdn(n={},e="prod"){const r=n[e]||n.prod||[];return r[Math.floor(Math.random()*r.length)]}export function injectFederationScripts(n,e=function cdnResolver(){}){return`window.evolveFetchMicroWidgets = function () {\n var cdnConfig = ${JSON.stringify(n)};\n var cdnResolver = ${e.toString()};\n var cdnFinder = ${cdnFinder.toString()};\n return (cdnFinder(cdnConfig, cdnResolver) || '').replace(/\\/$/, '');\n }\n `}
@@ -0,0 +1,3 @@
1
+ import { type EntryMapItem } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export declare const shouldEnableReactFastRefresh: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => boolean;
@@ -0,0 +1 @@
1
+ export const shouldEnableReactFastRefresh=(e,t,o)=>{const s=t[1],n=!!s.options?.moduleFederation;return e&&"react"===o.loaderOptions.babelOptions?.usePreset&&!n};
@@ -0,0 +1,8 @@
1
+ import { type Configuration } from 'webpack';
2
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../types/types-options.js';
4
+ /**
5
+ * Split the `webpack` to make sure that we have separated compiler process for each module
6
+ * @param webpackConfig `Omit<Configuration, 'entry'>` webpack final configuration
7
+ */
8
+ export declare function splitToMultiCompilerConfigs(servedEntries: EvolveEntryMap, webpackConfig: Omit<Configuration, 'entry'>, evolveOptions: FlatEvolveOptions): Configuration[];
@@ -0,0 +1 @@
1
+ import{mergeOptions}from"@flatjs/common";import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export function splitToMultiCompilerConfigs(e,o,t){const r=[];for(const[o,n]of Object.entries(e)){const e=normalizeEvolveEntryName(o,t.projectVirtualPath);r.push({[e]:n.entry})}return r.map((e=>mergeOptions(o,{name:Object.keys(e)[0],entry:e})))}
@@ -0,0 +1,4 @@
1
+ export * from './define-config/index.js';
2
+ export * from './load-config/index.js';
3
+ export * from './main/index.js';
4
+ export * from './types/types-options.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export*from"./define-config/index.js";export*from"./load-config/index.js";export*from"./main/index.js";export*from"./types/types-options.js";
@@ -0,0 +1 @@
1
+ export * from './load-evolve-config.js';
@@ -0,0 +1 @@
1
+ export*from"./load-evolve-config.js";
@@ -0,0 +1,9 @@
1
+ import { type DeepPartial, type ConfigEnvBase } from '@flatjs/common';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export type ConfigLoaderOptions = {
4
+ configFile: string;
5
+ esmLoaderOptions: {
6
+ externals: string[];
7
+ };
8
+ };
9
+ export declare const loadEvolveConfig: (configEnv: ConfigEnvBase, projectCwd: string, overrideOptions?: DeepPartial<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<FlatEvolveOptions>;
@@ -0,0 +1 @@
1
+ import{mergeOptions,logger,searchConfig}from"@flatjs/common";import{configFileName,moduleName}from"../constants.js";import{defaultEvolveOptions}from"../default-options.js";import{refreshEvolveMockOptions}from"../helpers/refresh-evolve-mock-options.js";export const loadEvolveConfig=async(o,e,t={},i={configFile:configFileName,esmLoaderOptions:{externals:["@flatjs/evolve"]}})=>{const{configFile:n,esmLoaderOptions:s}=i,r=await searchConfig(n,e,{esm:s});let f={};f="function"==typeof r?.config?r?.config(o):r?.config||{};const l=mergeOptions(defaultEvolveOptions,f),m=mergeOptions(l,t),a=mergeOptions(m,{projectCwd:e}),c=await refreshEvolveMockOptions(e,a,i);return logger.debug(c,moduleName),c};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const svgo_1 = require("svgo");
4
+ const VIEWBOX_REGEX = /viewBox="([^"]*)"/;
5
+ const SVG_REGEX = /<svg[^>]*>|<\/svg>/g;
6
+ const FILL_REGEX = /fill="[^"]*"/g;
7
+ const svgOptimize = (buffer, svgoOption) => {
8
+ const { data } = (0, svgo_1.optimize)(buffer, svgoOption);
9
+ return data;
10
+ };
11
+ const iconLoader = function iconLoader(source) {
12
+ this.cacheable && this.cacheable(true);
13
+ const options = this.getOptions();
14
+ const callback = this.async();
15
+ try {
16
+ const optimizedSource = svgOptimize(source, options.svgo);
17
+ const finalSource = optimizedSource.replace(FILL_REGEX, (fill) => {
18
+ return fill.includes('#FFF') ? 'fill="currentColor"' : '';
19
+ });
20
+ // Issue with ESLint recognizing this as needing an object destructure
21
+ const viewBoxMatch = VIEWBOX_REGEX.exec(finalSource);
22
+ const viewBox = viewBoxMatch ? viewBoxMatch[1] : '';
23
+ const svgExport = JSON.stringify({
24
+ viewBox,
25
+ body: finalSource.replace(SVG_REGEX, ''),
26
+ });
27
+ callback(null, `module.exports.default = module.exports = ${svgExport}`);
28
+ }
29
+ catch (err) {
30
+ callback(err);
31
+ }
32
+ };
33
+ module.exports = iconLoader;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type FlatEvolveOptions } from '../types/types-options.js';
2
+ export declare const envVerify: (projectCwd: string, evolveOptions: FlatEvolveOptions) => Promise<void>;
@@ -0,0 +1 @@
1
+ import{illegalPackageChecker,keepPackageDepsUpToDateForNonMonoRepo}from"@armit/package";export const envVerify=async(e,a)=>{const{packageInstallChecker:o,needVerifyPackages:r}=a;!1!==o&&o?.enabled&&await illegalPackageChecker({cwd:e,modules:o?.detectModules,throwError:o?.throwError,showAllInstalledGraph:o?.showAllInstalledGraph}),!1!==r&&await keepPackageDepsUpToDateForNonMonoRepo({cwd:e,autoUpgrade:!0,needVerifyPackages:r||{}})};
@@ -0,0 +1,3 @@
1
+ export * from './start-build.js';
2
+ export * from './start-serve.js';
3
+ export * from './start-static.js';
@@ -0,0 +1 @@
1
+ export*from"./start-build.js";export*from"./start-serve.js";export*from"./start-static.js";
@@ -0,0 +1,13 @@
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export type EvolveBuildResult = {
4
+ name?: string;
5
+ warningStats?: any;
6
+ };
7
+ /**
8
+ * The main entry to start an evolve `build`
9
+ * @param buildEntries All webpack entries we prepare to build.
10
+ * @param evolveOptions FlatEvolveOptions
11
+ * @param clearCache The value indicates if we need to clear webpack cache resources.
12
+ */
13
+ export declare const prepareBuild: (projectCwd: string, buildEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<EvolveBuildResult[]>;
@@ -0,0 +1 @@
1
+ import{ensureSlash,mergeOptions}from"@flatjs/common";import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";import{envVerify}from"./env-verify.js";const startSingleEntryBuild=(r,o)=>{const t=loadWebpackConfig("production",r,o),e=splitToMultiCompilerConfigs(r,t,o);if(e.length>1)throw new Error("startSingleEntryBuild() only support `compiler` at a time");const n=e[0];return new Promise(((r,t)=>{webpack(n,((e,i)=>{if(e)return t(e);const s=i?.toJson();return s?.errors?.length?t(s.errors):o.rejectWarnings&&s?.warnings?.length?t(s.warnings):void r({name:n.name,warningStats:s?.warnings})}))}))};export const prepareBuild=async(r,o,t)=>{await envVerify(r,t);const e=t.multiHtmlCdn?.prod||[];if(!e.length)throw new Error('No CDN configuration for env: "prod"');const n=[],i=ensureSlash(e[Math.floor(Math.random()*e.length)],!0);for(const[r,e]of Object.entries(o)){const o={[r]:e},s=e.options?.useRelativeAssetPath;n.push(startSingleEntryBuild(o,mergeOptions(t,{webpack:{publicPath:s?"auto":i}})))}return Promise.all(n)};
@@ -0,0 +1,9 @@
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * The main entry to start evolve serve
5
+ * @param projectCwd The Root directory (workspace) of this project.
6
+ * @param servedEntries All normalized webpack entries we have served.
7
+ * @param evolveOptions FlatEvolveOptions
8
+ */
9
+ export declare const prepareServe: (projectCwd: string, servedEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<import("express-serve-static-core").Express>;
@@ -0,0 +1 @@
1
+ import{urlJoin}from"@flatjs/common";import{attachMockMiddlewares}from"@flatjs/mock";import{createAppPageRoute,createDevServer,createDevServerCompilerTasks,createDevServerEntries}from"../dev-server/index.js";import{openPage}from"../helpers/index.js";import{envVerify}from"./env-verify.js";export const prepareServe=async(e,r,t)=>{await envVerify(e,t);const{app:o,devPort:a,devHostUri:s}=await createDevServer(t);attachMockMiddlewares(o,{...t.devServer?.mockOptions,projectCwd:e});const v=await createDevServerEntries(a,r,t);createAppPageRoute(e,o,s,v,t);const i=urlJoin(s,["/pages"]);t.devServer?.autoOpen&&openPage(i);const p=createDevServerCompilerTasks(e,i,v,t);return Promise.all(p).then((()=>o))};
@@ -0,0 +1,7 @@
1
+ import { type FlatEvolveOptions } from '../types/index.js';
2
+ /**
3
+ * The main entry to start evolve serve
4
+ * @param projectCwd The Root directory (workspace) of this project.
5
+ * @param evolveOptions FlatEvolveOptions
6
+ */
7
+ export declare const prepareStatic: (evolveOptions: FlatEvolveOptions) => Promise<import("express-serve-static-core").Express>;
@@ -0,0 +1 @@
1
+ import{chalk,logger,urlJoin}from"@flatjs/common";import{createDevServer}from"../dev-server/create-dev-server.js";export const prepareStatic=async e=>createDevServer(e).then((({app:e,devHostUri:r})=>{const t=urlJoin(r,["/pages"]);return logger.info(`${"static page".padEnd(12," ")} ➩ ${chalk(["cyan"])(t)}`),e}));
@@ -0,0 +1,13 @@
1
+ import { type DeepPartial } from '@flatjs/common';
2
+ import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
3
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
4
+ import { type FlatEvolveOptions } from '../types/types-options.js';
5
+ import { type EvolveBuildResult } from './prepare-build.js';
6
+ /**
7
+ * The main entry to start an evolve `build`
8
+ * @param projectCwd The Root directory (workspace) of this project.
9
+ * @param buildEntries All webpack entries we prepare to build.
10
+ * @param evolveOptions FlatEvolveOptions
11
+ * @param clearCache The value indicates if we need to clear webpack cache resources.
12
+ */
13
+ export declare const startBuild: (projectCwd: string, buildEntries: EvolveEntryMap, overrideEvolveOptions?: DeepPartial<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<EvolveBuildResult[]>;
@@ -0,0 +1 @@
1
+ import _ from"lodash";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareBuild}from"./prepare-build.js";export const startBuild=async(o,r,e={},a)=>{const l=await loadEvolveConfig({command:"build"},o,_.merge({},e,{entryMap:r}),a),i=normalizeEvolveEntryMap(r,l.entryMap);return prepareBuild(o,i,l)};
@@ -0,0 +1,11 @@
1
+ import { type DeepPartial } from '@flatjs/common';
2
+ import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
3
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
4
+ import { type FlatEvolveOptions } from '../types/types-options.js';
5
+ /**
6
+ * The main entry to start evolve serve
7
+ * @param projectCwd The Root directory (workspace) of this project.
8
+ * @param servedEntries All webpack entries we have served.
9
+ * @param evolveOptions FlatEvolveOptions
10
+ */
11
+ export declare const startServe: (projectCwd: string, servedEntries: EvolveEntryMap, overrideEvolveOptions?: DeepPartial<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<import("express-serve-static-core").Express>;
@@ -0,0 +1 @@
1
+ import _ from"lodash";import{normalizeEvolveEntryMap}from"../helpers/normalize-entry-map.js";import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareServe}from"./prepare-serve.js";export const startServe=async(e,r,o={},a)=>{const n=await loadEvolveConfig({command:"serve"},e,_.merge({},o,{entryMap:r}),a),p=normalizeEvolveEntryMap(r,n.entryMap);return prepareServe(e,p,n)};
@@ -0,0 +1,10 @@
1
+ import { type DeepPartial } from '@flatjs/common';
2
+ import { type ConfigLoaderOptions } from '../load-config/load-evolve-config.js';
3
+ import { type FlatEvolveOptions } from '../types/types-options.js';
4
+ /**
5
+ * The main entry to start evolve static server to proxy all modules of `production` build
6
+ * @param projectCwd The Root directory (workspace) of this project.
7
+ * @param evolveOptions FlatEvolveOptions
8
+ * @param configLoaderOptions FlatMockOptions
9
+ */
10
+ export declare const startStatic: (projectCwd: string, overrideEvolveOptions?: DeepPartial<FlatEvolveOptions>, configLoaderOptions?: ConfigLoaderOptions) => Promise<import("express-serve-static-core").Express>;
@@ -0,0 +1 @@
1
+ import{loadEvolveConfig}from"../load-config/load-evolve-config.js";import{prepareStatic}from"./prepare-static.js";export const startStatic=async(o,t={},a)=>{const r=await loadEvolveConfig({command:"static"},o,t,a);return prepareStatic(r)};
@@ -0,0 +1,3 @@
1
+ import { type WebpackPlugin } from '../create-webpack/types.js';
2
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
3
+ export declare const createMinimizers: (serveMode: boolean, webpackOptions?: FlatEvolveWebpackOptions) => WebpackPlugin[];
@@ -0,0 +1 @@
1
+ import{logger}from"@flatjs/common";import{moduleName}from"../constants.js";import{printInfo}from"../helpers/print-log.js";import{imageMinimizer}from"./image-minimizer.js";import{terserMinimizer}from"./terser-minimizer.js";export const createMinimizers=(i,r)=>{const e=[];if(i)return logger.debug("Ignore minimizer plugin for `serve` mode",moduleName),e;if(!1===r?.minimizer)return printInfo("Note `minimizer` has been disabled for now"),e;const m=imageMinimizer();m&&r?.minimizer?.imageMin&&e.push(m);const n=terserMinimizer(r?.minimizer?.terserOptions||{});return e.push(n),e};
@@ -0,0 +1,2 @@
1
+ import { type TerserMinimizerOptions } from './types.js';
2
+ export declare const defaultTerserOptions: TerserMinimizerOptions;
@@ -0,0 +1 @@
1
+ export const defaultTerserOptions={ecma:void 0,parse:{},compress:{},mangle:!0,module:!1,output:void 0,toplevel:!1,ie8:!1,keep_classnames:void 0,keep_fnames:!1,safari10:!1};
@@ -0,0 +1,7 @@
1
+ import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
2
+ /**
3
+ * brew install libpng
4
+ * brew install gifsicle
5
+ * @returns
6
+ */
7
+ export declare const imageMinimizer: () => ImageMinimizerPlugin<unknown, unknown> | null;
@@ -0,0 +1 @@
1
+ import{projectHasYarn}from"@armit/package";import{chalk,logger,requireResolve}from"@flatjs/common";import ImageMinimizerPlugin from"image-minimizer-webpack-plugin";import{moduleName}from"../constants.js";const logs=new Map;export const imageMinimizer=()=>{const e=[["svgo",{}],["gifsicle",{}],["jpegtran",{}],["pngquant",{}]].map((e=>{const i=e[0];try{return requireResolve(`imagemin-${i}`),e}catch(e){if(!logs.get(i)){logs.set(i,!0);const e=chalk(["magenta"])(`"${projectHasYarn()?"yarn add":"npm install"} imagemin-${i} -D"`);logger.warn(`Execute ${e} for assets optimization`,moduleName)}return null}})).filter(Boolean);return e.length?new ImageMinimizerPlugin({minimizer:{implementation:ImageMinimizerPlugin.imageminMinify,options:{plugins:e}}}):null};
@@ -0,0 +1 @@
1
+ export * from './create-minimizers.js';
@@ -0,0 +1 @@
1
+ export*from"./create-minimizers.js";
@@ -0,0 +1,6 @@
1
+ import { type WebpackPlugin } from '../create-webpack/types.js';
2
+ import { type TerserMinimizerOptions } from './types.js';
3
+ /**
4
+ * https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
5
+ */
6
+ export declare const terserMinimizer: (terserOptions: TerserMinimizerOptions) => WebpackPlugin;
@@ -0,0 +1,3 @@
1
+ import{mergeOptions}from"@flatjs/common";import TerserPlugin from"terser-webpack-plugin";import{defaultTerserOptions}from"./default-options.js";export const terserMinimizer=e=>new TerserPlugin({parallel:!0,
2
+ // Disable Extract all or some (use /^\**!|@preserve|@license|@cc_on/i RegExp) comments.
3
+ extractComments:!1,terserOptions:mergeOptions(defaultTerserOptions,e)});
@@ -0,0 +1,2 @@
1
+ import { type TerserOptions } from 'terser-webpack-plugin';
2
+ export type TerserMinimizerOptions = Omit<TerserOptions, 'nameCache' | 'sourceMap'>;
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,67 @@
1
+ import { type Compilation, type Compiler, type Stats } from 'webpack';
2
+ export interface Options {
3
+ /**
4
+ * The project root.
5
+ */
6
+ projectCwd?: string;
7
+ /**
8
+ * Write Logs to Console
9
+ * (Always enabled when dry is true)
10
+ *
11
+ * default: false
12
+ */
13
+ verbose?: boolean;
14
+ /**
15
+ * Automatically remove all unused webpack assets on rebuild
16
+ *
17
+ * default: true
18
+ */
19
+ cleanStaleWebpackAssets?: boolean;
20
+ /**
21
+ * Do not allow removal of current webpack assets
22
+ *
23
+ * default: true
24
+ */
25
+ protectWebpackAssets?: boolean;
26
+ /**
27
+ * Removes files once prior to Webpack compilation
28
+ * Not included in rebuilds (watch mode)
29
+ *
30
+ * Use !negative patterns to exclude files
31
+ *
32
+ * default: ['**\/*']
33
+ */
34
+ cleanOnceBeforeBuildPatterns?: string[];
35
+ /**
36
+ * Removes files after every build (including watch mode) that match this pattern.
37
+ * Used for files that are not created directly by Webpack.
38
+ *
39
+ * Use !negative patterns to exclude files
40
+ *
41
+ * default: []
42
+ */
43
+ cleanAfterEveryBuildPatterns?: string[];
44
+ }
45
+ export declare class CleanWebpackPlugin {
46
+ private readonly verbose;
47
+ private readonly cleanStaleWebpackAssets;
48
+ private readonly protectWebpackAssets;
49
+ private readonly cleanAfterEveryBuildPatterns;
50
+ private readonly cleanOnceBeforeBuildPatterns;
51
+ private currentAssets;
52
+ private initialClean;
53
+ private outputPath;
54
+ private projectCwd;
55
+ constructor(options?: Options);
56
+ apply(compiler: Compiler): void;
57
+ /**
58
+ * Initially remove files from output directory prior to build.
59
+ *
60
+ * Only happens once.
61
+ *
62
+ * Warning: It is recommended to initially clean your build directory outside of webpack to minimize unexpected behavior.
63
+ */
64
+ handleInitial(compilation: Compilation): void;
65
+ handleDone(stats: Stats): void;
66
+ removeFiles(patterns: string[]): void;
67
+ }
@@ -0,0 +1 @@
1
+ import{rmSync}from"node:fs";import{relative}from"node:path";import{fileWalkSync}from"@armit/file-utility";import{logger}from"@flatjs/common";import{moduleName}from"../../constants.js";export class CleanWebpackPlugin{constructor(e={}){this.verbose=!0===e.verbose||!1,this.projectCwd=e.projectCwd||process.cwd(),this.cleanStaleWebpackAssets=!0!==e.cleanStaleWebpackAssets&&!1!==e.cleanStaleWebpackAssets||e.cleanStaleWebpackAssets,this.protectWebpackAssets=!0!==e.protectWebpackAssets&&!1!==e.protectWebpackAssets||e.protectWebpackAssets,this.cleanAfterEveryBuildPatterns=Array.isArray(e.cleanAfterEveryBuildPatterns)?e.cleanAfterEveryBuildPatterns:[],this.cleanOnceBeforeBuildPatterns=Array.isArray(e.cleanOnceBeforeBuildPatterns)?e.cleanOnceBeforeBuildPatterns:["**/*"],this.currentAssets=[],this.initialClean=!1,this.outputPath="",this.apply=this.apply.bind(this),this.handleInitial=this.handleInitial.bind(this),this.handleDone=this.handleDone.bind(this),this.removeFiles=this.removeFiles.bind(this)}apply(e){if(!e.options.output||!e.options.output.path)return void logger.warn("clean-webpack-plugin: options.output.path not defined. Plugin disabled...",moduleName);this.outputPath=e.options.output.path;const t=e.hooks;0!==this.cleanOnceBeforeBuildPatterns.length&&t.emit.tap("clean-webpack-plugin",(e=>{this.handleInitial(e)})),t.done.tap("clean-webpack-plugin",(e=>{this.handleDone(e)}))}handleInitial(e){if(this.initialClean)return;e.getStats().hasErrors()||(this.initialClean=!0,this.removeFiles(this.cleanOnceBeforeBuildPatterns))}handleDone(e){if(e.hasErrors())return void(this.verbose&&logger.warn("clean-webpack-plugin: pausing due to webpack errors",moduleName));const t=(e.toJson({assets:!0}).assets||[]).map((e=>e.name)),s=this.currentAssets.filter((e=>!1===t.includes(e)));this.currentAssets=t.sort();const i=[];!0===this.cleanStaleWebpackAssets&&0!==s.length&&i.push(...s),0!==this.cleanAfterEveryBuildPatterns.length&&i.push(...this.cleanAfterEveryBuildPatterns),0!==i.length&&this.removeFiles(i)}removeFiles(e){try{const t=fileWalkSync(e,{absolute:!0,unique:!0,cwd:this.outputPath,dot:!0,ignore:this.protectWebpackAssets?this.currentAssets:[]});for(const e of t)rmSync(e,{force:!0,recursive:!0});this.verbose&&t.forEach((e=>{const t=relative(this.projectCwd,e);logger.info(`clean-webpack-plugin: removed ${t}`,moduleName)}))}catch(e){if(/Cannot delete files\/folders outside the current working directory\./.test(e.message)){throw new Error("clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the `dangerouslyAllowCleanPatternsOutsideProject` option.")}throw e}}}
@@ -0,0 +1,9 @@
1
+ import { type WebpackPlugin } from '../../create-webpack/types.js';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ /**
5
+ * Cleaning up the /dist folder for `production` build
6
+ * @param singleEntryItem
7
+ * @returns
8
+ */
9
+ export declare const createCleanWebpackPlugin: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{CleanWebpackPlugin}from"./clean-webpack-plugin.js";export const createCleanWebpackPlugin=(e,n,o)=>e?[]:[new CleanWebpackPlugin({verbose:!0,projectCwd:o.projectCwd,cleanOnceBeforeBuildPatterns:[`${join(ensureSlash(n[0],!0),"**/*")}`]})];
@@ -0,0 +1,8 @@
1
+ import type { HtmlTagObject } from 'html-webpack-plugin';
2
+ import type { Compiler, WebpackPluginInstance } from 'webpack';
3
+ export declare class HtmlInjectScriptPlugin implements WebpackPluginInstance {
4
+ scripts: string[];
5
+ constructor(scripts?: string[]);
6
+ processScripts(): HtmlTagObject[];
7
+ apply(compiler: Compiler): void;
8
+ }
@@ -0,0 +1 @@
1
+ import htmlWebpackPlugin from"html-webpack-plugin";const PLUGIN_PREFIX="HtmlInjectScriptPlugin";export class HtmlInjectScriptPlugin{constructor(t){this.scripts=t||[]}processScripts(){return this.scripts.filter(Boolean).map((t=>({tagName:"script",innerHTML:t,voidTag:!1,attributes:{},meta:{plugin:"html-inject-script-webpack-plugin"}})))}apply(t){t.hooks.compilation.tap(`${PLUGIN_PREFIX}_compilation`,(t=>{htmlWebpackPlugin.getHooks(t).alterAssetTags.tap(`${PLUGIN_PREFIX}_alterAssetTags`,(t=>(t.assetTags.scripts.unshift(...this.processScripts()),t)))}))}}
@@ -0,0 +1,4 @@
1
+ import { type Compiler } from 'webpack';
2
+ export declare class ExternalTemplateRemotesPlugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -0,0 +1 @@
1
+ import webpackSources from"webpack-sources";const PLUGIN_NAME="ExternalTemplateRemotesPlugin",isExternalModule=e=>"ExternalModule"===e.constructor.name;function extractUrlAndGlobal(e){const t=e.indexOf("@");if(t<=0||t===e.length-1)throw new Error(`Invalid request "${e}"`);return[e.substring(t+1),e.substring(0,t)]}export class ExternalTemplateRemotesPlugin{apply(e){e.hooks.make.tap(PLUGIN_NAME,(e=>{const t=[];e.hooks.buildModule.tap(PLUGIN_NAME,(e=>{isExternalModule(e)&&"script"===e.externalType&&t.push(e)})),e.hooks.afterCodeGeneration.tap(PLUGIN_NAME,(()=>{t.forEach((t=>{const o=extractUrlAndGlobal(t.request)[0],n=toExpression(o),r=e.codeGenerationResults.get(t,void 0).sources,s=r.get("javascript");if(s){const e=new webpackSources.RawSource(s.source().toString().replace(`"${o}"`,n));r.set("javascript",e)}}))}))}))}}function toExpression(e){const t=[],o=[];let n=!1,r=!1;for(const s of e)if("["===s){if(n){r=!0;break}n=!0,o.length&&(t.push(`"${o.join("")}"`),o.length=0)}else if("]"===s){if(!n){r=!0;break}n=!1,o.length&&(t.push(`${o.join("")}`),o.length=0),o.length=0}else o.push(s);if(n||r)throw new Error(`Invalid template URL "${e}"`);return o.length&&t.push(`"${o.join("")}"`),t.join(" + ")}
@@ -0,0 +1 @@
1
+ export * from './module-federation.js';
@@ -0,0 +1 @@
1
+ export*from"./module-federation.js";
@@ -0,0 +1,4 @@
1
+ import { type WebpackPluginInstance } from 'webpack';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ export declare const createModuleFederationPlugin: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPluginInstance[];
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import webpack from"webpack";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{HtmlInjectScriptPlugin}from"../html-inject-scripts/plugin-html-inject-script.js";import{ExternalTemplateRemotesPlugin}from"./external-template-remotes.js";const normalizeWidgetName=(e="")=>e.replace(/[/-]/g,"_").toLowerCase(),remoteFileName=e=>join(e,"micro-remote-module.js");export const createModuleFederationPlugin=(e,t,r)=>{const o=r.projectVirtualPath,[n,i]=t,m=r.multiHtmlCdn,a=r.multiHtmlCdnEnvResolver,l=i.options?.moduleFederation,s=[];if(l){const{remotes:t,exposes:r,...i}=l,p=remoteFileName(n),c=normalizeWidgetName(n),u=(r?Array.isArray(r)?r:[r]:[]).map((e=>{const t={};for(const[r,o]of Object.entries(e))t[r]={...o,name:join(n,o.name.replace(/^\//,""))};return t})),d=(t||[]).map((({name:e,endpoint:t})=>{const r=normalizeEvolveEntryName(e,o),n=normalizeWidgetName(r),i=remoteFileName(r);return{[n]:`${n}@${t?ensureSlash(t(e,r),!1):"[window.evolveFetchMicroWidgets()]"}/${i}`}}));s.push(new webpack.container.ModuleFederationPlugin({name:c,filename:p,remotes:d,exposes:u,...i}),new ExternalTemplateRemotesPlugin),e||s.unshift(new HtmlInjectScriptPlugin([injectFederationScripts(m,a)]))}return s};
@@ -0,0 +1,4 @@
1
+ import { type WebpackPlugin } from '../../create-webpack/types.js';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ export declare const createHtmlPlugins: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -0,0 +1 @@
1
+ import{FlatEvolveMultiCdnPlugin}from"./multi-html-cdn-plugin.js";import{createMultiHtmlWebpackPlugin}from"./multi-html-plugin.js";export const createHtmlPlugins=(t,l,u)=>{const i=[];if(t)return i;const n=Object.keys(u.multiHtmlCdn);return i.push(...createMultiHtmlWebpackPlugin(t,u,l,n)),i.push(new FlatEvolveMultiCdnPlugin(u)),i};
@@ -0,0 +1,17 @@
1
+ import { type Compiler } from 'webpack';
2
+ import { type FlatEvolveOptions } from '../../types/index.js';
3
+ export declare class FlatEvolveMultiCdnPlugin {
4
+ private pluginName;
5
+ private requireFn;
6
+ private config;
7
+ private cdnResolver;
8
+ constructor(evolveOptions: FlatEvolveOptions);
9
+ /**
10
+ * Apply the plugin to check if there are non initial chunks which need to be imported using `require-ensure` or `import`
11
+ * https://github.com/webpack/webpack/blob/3d653290fafe385277b48e5a36807124618b9561/lib/MainTemplate.js#L158
12
+ * https://www.npmjs.com/package/vscode-webpack-debugger
13
+ * https://www.cnblogs.com/Scar007/p/9166068.html
14
+ * https://www.cnblogs.com/pluslius/p/10271537.html
15
+ */
16
+ apply(compiler: Compiler): void;
17
+ }
@@ -0,0 +1 @@
1
+ import{basename}from"node:path";import HtmlWebpackPlugin from"html-webpack-plugin";import webpack from"webpack";import{cdnFinder,findEnvCdn,httpUrlJoin}from"../../helpers/script-injects.js";export class FlatEvolveMultiCdnPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,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,((n,t)=>{const i=[];i.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const s=e.chunkGraph?.getTreeRuntimeRequirements(t);return s&&s.has(webpack.RuntimeGlobals.requireScope)&&(i.push("(function () {"),i.push(webpack.Template.indent("var flatjsMultiCdn = {")),i.push(webpack.Template.indent(webpack.Template.indent([`cdnConfig: ${JSON.stringify(this.config||{})},`]))),i.push(webpack.Template.indent(webpack.Template.indent([`cdnResolver: ${this.cdnResolver.toString()},`]))),i.push(webpack.Template.indent(webpack.Template.indent([`cdnFinder: ${cdnFinder.toString()}`]))),i.push(webpack.Template.indent("};")),i.push(webpack.Template.indent(`${this.requireFn} = flatjsMultiCdn.cdnFinder(flatjsMultiCdn.cdnConfig, flatjsMultiCdn.cdnResolver) || ${this.requireFn};`)),i.push("})();")),webpack.Template.asString(i)}))})),e.hooks.compilation.tap(this.pluginName,(e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,(e=>{const{assets:n}=e,{userOptions:t}=e.plugin,i=t.multiCdn,s=n.publicPath,a=n.js.map((e=>{if(i.disabled)return basename(e);const n=findEnvCdn(this.config,i.env);return httpUrlJoin(n,e.replace(s,""))})),p=n.css.map((e=>{if(i.disabled)return basename(e);const n=findEnvCdn(this.config,i.env);return httpUrlJoin(n,e.replace(s,""))}));return e.assets.js=a,e.assets.css=p,e}))}))}}
@@ -0,0 +1,11 @@
1
+ import { type WebpackPlugin } from '../../create-webpack/types.js';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type EvolveMultiCdnEnvType } from '../../types/types-multi-html.js';
4
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
5
+ /**
6
+ * Create `html-webpack-plugin` for this build, refer to best practices
7
+ * We'd better pass only one entry for each `build` cycle
8
+ * @param buildEntryItem the entries for this `build`
9
+ * @param allEnv
10
+ */
11
+ export declare const createMultiHtmlWebpackPlugin: (serveMode: boolean, evolveOptions: FlatEvolveOptions, entryMapItem: EntryMapItem, allEnv: Array<EvolveMultiCdnEnvType>) => WebpackPlugin[];
@@ -0,0 +1 @@
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";const minifyOpts={minifyJS:!0,removeComments:!0,collapseWhitespace:!0,collapseBooleanAttributes:!1};export const createMultiHtmlWebpackPlugin=(e,t,i,l)=>{const[o,n]=i,r=[],{options:m}=n,g=e?"development":"production";for(const e of l)r.push(new HtmlWebpackPlugin({inject:"body",title:getHtmlPluginConfig("title",g,m?.title),chunks:[o],minify:!1!==m?.htmlMinify&&!["me","dev"].includes(e)&&minifyOpts,filename:`${o}/index${"prod"===e?"":`-${e}`}.html`,template:getHtmlPluginConfig("templatePath",g,m?.templatePath).replace("{0}",e),templateParameters:{title:getHtmlPluginConfig("title",g,m?.title),favicon:getHtmlPluginConfig("favicon",g,m?.favicon),headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",g,m?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",g,m?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",g,m?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",g,m?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",g,m?.bodyAfterScripts),viewport:allowPx2remForModule(i,t)?getHtmlPluginConfig("viewport",g,m?.viewport):""},multiCdn:{env:e,disabled:(m?.excludeCdnEnvs||["me","dev","ntv"]).includes(e)}}));return r};
@@ -0,0 +1,8 @@
1
+ export * from './types-dev-server.js';
2
+ export * from './types-entry-map.js';
3
+ export * from './types-federation.js';
4
+ export * from './types-modular-import.js';
5
+ export * from './types-multi-html.js';
6
+ export * from './types-options.js';
7
+ export * from './types-loader-options.js';
8
+ export * from './types-webpack.js';
@@ -0,0 +1 @@
1
+ export*from"./types-dev-server.js";export*from"./types-entry-map.js";export*from"./types-federation.js";export*from"./types-modular-import.js";export*from"./types-multi-html.js";export*from"./types-options.js";export*from"./types-loader-options.js";export*from"./types-webpack.js";
@@ -0,0 +1,51 @@
1
+ import { type SecureContextHttps, type FlatMockOptions } from '@flatjs/mock';
2
+ import { type RequestHandler } from 'express';
3
+ import { type Configuration } from 'webpack';
4
+ import { type EvolveEntryMapContent } from './types-entry-map.js';
5
+ export interface WebpackWatchOptions {
6
+ /**
7
+ * Delay the rebuilt after the first change. Value is a time in ms.
8
+ */
9
+ aggregateTimeout?: number;
10
+ /**
11
+ * Resolve symlinks and watch symlink and real file. This is usually not needed as webpack already resolves symlinks ('resolve.symlinks').
12
+ */
13
+ followSymlinks?: boolean;
14
+ /**
15
+ * Ignore some files from watching (glob pattern or regexp).
16
+ */
17
+ ignored?: string | RegExp | string[];
18
+ /**
19
+ * Enable polling mode for watching.
20
+ */
21
+ poll?: number | boolean;
22
+ }
23
+ export type FlatEvolveDevServerOptions = {
24
+ /**
25
+ * Allow us provider customized middlewares for `page`, `modules`
26
+ */
27
+ middlewares?: RequestHandler[];
28
+ /**
29
+ * Turn on watch mode. This means that after the initial build, webpack will continue to watch for changes in any of the resolved files.
30
+ * In webpack-dev-server watch mode is enabled by default.
31
+ * This configuration will be merged into `webpack-dev-server`
32
+ */
33
+ watchOptions?: Configuration['watchOptions'];
34
+ /**
35
+ * Allow us costomized global serve data injected into `window.GLOBAL = {...globalData}`
36
+ */
37
+ defaultServeGlobalData?: (entryItem: EvolveEntryMapContent, hostUrl: string) => Record<string, unknown>;
38
+ /**
39
+ * The value indicates if we will auto open broswers page for `serve`
40
+ * @default true
41
+ */
42
+ autoOpen?: boolean;
43
+ /**
44
+ * The customized config options of `flatjs/mock`, it will override options `flatjs-mock.config.mts`
45
+ */
46
+ mockOptions?: Omit<FlatMockOptions, 'projectCwd'>;
47
+ /**
48
+ * Provide your own certificate using the https option
49
+ */
50
+ https?: SecureContextHttps;
51
+ };
@@ -0,0 +1 @@
1
+ export{};