@flatjs/evolve 1.5.29 → 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 +108 -60
  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
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @flatjs/evolve
2
+
3
+ ## 1.8.1-next.17
4
+
5
+ ### Patch Changes
6
+
7
+ - cdc0604: Replace veresion pattern from `^` to `*`
8
+ - ab0bc1f: Add evolve module
9
+ - 05a29d9: update dependencies as fixed version
10
+ - Updated dependencies [cdc0604]
11
+ - Updated dependencies [b2586d8]
12
+ - Updated dependencies [05a29d9]
13
+ - Updated dependencies [fd260b2]
14
+ - @flatjs/forge-postcss-plugin-pixel@1.8.1-next.8
15
+ - @flatjs/common@1.8.1-next.8
16
+ - @flatjs/evolve-preset-babel@1.8.1-next.5
17
+ - @flatjs/mock@1.8.1-next.17
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2021 Yingchun Tian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,54 +1,18 @@
1
1
  # @flatjs/evolve
2
2
 
3
- > The webpack based dev tools `evolve` of flatjs
3
+ ## Note: because below configuration of `tsconfig.json `
4
4
 
5
- ## The usages
6
-
7
- ```sh
8
- npm i @flatjs/evolve
9
- ```
10
-
11
- Need production assets optimization
12
-
13
- ```sh
14
- brew install libpng
15
- brew install gifsicle
16
- npm install imagemin-gifsicle -D
17
- npm install imagemin-jpegtran -D
18
- npm install imagemin-pngquant -D
19
- npm install imagemin-svgo -D
5
+ ```json
6
+ { "baseUrl": "./src" }
20
7
  ```
21
8
 
22
- ## Features
9
+ We should not create folder name like `webpack` in `src/webpack`;
23
10
 
24
- - Integrated Mock system using `@flatjs/mock`
25
- - Provide some standard built-in plug-ins `clean-webpack`,`context-replacement`, `mini-css-extract`
26
- - Support multi cdn configuration for each `individual` entry `dev` `inte` `rc` `ntv` `prod`
27
- - Support multi html template file output `index.html`, `index-dev.html`, `index-rc.html`, `index-ntv.html`
28
- - Support `express` to proxy all `serve` `static` page `modules`.
29
- - Support us filter dynamic import using `import()`
30
- - Allow us attach customized `middleware` to handle page render.
31
- - Allow individual define some configuration for each `entry item`.
32
- - Builtin `parallel` build for production `build`
33
- - Allow us specified extra `babel` presets or plugins to handle your webapp.
34
- - Builtin loaders `icon` `babel` `css` `less` `image` `svg` `font`
35
- - Split `mock` and `evolve` configuration into `flatjs.mock.js`, `flatjs.evolve.js`.
11
+ 1. while we use `import { moduleX } from webpack`; it will resolve `moduleX` from `src/webpack` instead import from `node_modules`
12
+ 2. while use `vitest` it may broken cause of wrong `webpack` imported.
13
+ 3. change `src/webpack` to `src/create-webpack` is ok.
36
14
 
37
- ## Notes
15
+ ### Notes: cause of `esm`
38
16
 
39
- For evolve dts cause of `lerna` package `symlinks`, if we want to import `types` without `inline` mode. we must do as below:
40
-
41
- 1. update `flatjs.dts.js` add `followSymlinks: false,`
42
- 2. remove `paths:{}` from `compilerOptions` of tsconfig.json
43
- 3. SEE: ([monorepo will be inlined?](https://github.com/timocov/dts-bundle-generator/issues/91))
44
- 4. Cause of `webpack@5` there are some typings issue for `plugins`, we remove these typings from `devDependencies` e.g. `mini-css-extract`, `webpack-dev-server`, `clean-webpack-plugin`
45
- 5. 注意一旦使用 antd 作为 externals, 此处要去掉 `antd` modularImports `flatjs.evolve.js`
46
-
47
- ```json
48
- {
49
- libraryName: 'antd',
50
- libraryDirectory: 'es',
51
- style: true,
52
- transformToDefaultImport: true,
53
- },
54
- ```
17
+ 1. `import { webpack } from 'webpack'` should be change to `import webpack from 'webpack'`
18
+ 2. `import { merge } from 'lodash'` should be change to `import _ from 'lodash'`
@@ -0,0 +1,15 @@
1
+ export declare const moduleName = "@flatjs/evolve";
2
+ /**
3
+ * the configuration file of `flat-evolve`
4
+ * flatjs-evolve.config.ts,.mjs,.mts
5
+ */
6
+ export declare const configFileName = "flatjs-evolve";
7
+ /**
8
+ * `viewport.js`, Used to support the mobile `rem` adaptive solution.
9
+ * The viewport code is dynamically inserted to `html` file via `html-plugin`
10
+ */
11
+ export declare const viewportScripts = "(function(d){var j;var b=1;var i=1;var h=750;var c=100;function e(s,o){var q=d.document;var l=q.documentElement;var k=navigator.userAgent;var m=k.toLowerCase().indexOf(\"android\")>-1;i=d.devicePixelRatio||1;if(i>3){i=3}if(m){i=1}console.log(\"current devicePixelRatio:\",i);l.setAttribute(\"data-dpr\",i.toString());var p=q.querySelector('meta[name=\"viewport\"]');if(!p){b=1/i;p=q.createElement(\"meta\");p.setAttribute(\"name\",\"viewport\");q.head.appendChild(p);p.setAttribute([\"content\",\"width=device-width,user-scalable=no,initial-scale=\",b,\",maximum-scale=\",b,\",minimum-scale=\",b].join(\"\"))}function n(){var t=document.documentElement.clientWidth;j=t/o*(s/i)*i;q.documentElement.style.fontSize=String(j)+\"px\"}var r;d.addEventListener(\"resize\",function(){clearTimeout(r);r=setTimeout(n,300)},false);d.addEventListener(\"onload\",n,false);n()}e(c,h);window.fabricViewport={currRem:j,currDpr:i,currScale:b,dpiPX2px:function f(k){return parseFloat(k.toString())/j*100+\"px\"},px2DPIpx:function a(k){return parseFloat(k.toString())/100*j+\"px\"},px2rem:function g(k){return parseFloat(k.toString())/100+\"rem\"}}})(window);";
12
+ /**
13
+ * https://polyfill.io
14
+ */
15
+ export declare const polyfill: string[];
@@ -0,0 +1 @@
1
+ export const moduleName="@flatjs/evolve";export const configFileName="flatjs-evolve";export const viewportScripts='(function(d){var j;var b=1;var i=1;var h=750;var c=100;function e(s,o){var q=d.document;var l=q.documentElement;var k=navigator.userAgent;var m=k.toLowerCase().indexOf("android")>-1;i=d.devicePixelRatio||1;if(i>3){i=3}if(m){i=1}console.log("current devicePixelRatio:",i);l.setAttribute("data-dpr",i.toString());var p=q.querySelector(\'meta[name="viewport"]\');if(!p){b=1/i;p=q.createElement("meta");p.setAttribute("name","viewport");q.head.appendChild(p);p.setAttribute(["content","width=device-width,user-scalable=no,initial-scale=",b,",maximum-scale=",b,",minimum-scale=",b].join(""))}function n(){var t=document.documentElement.clientWidth;j=t/o*(s/i)*i;q.documentElement.style.fontSize=String(j)+"px"}var r;d.addEventListener("resize",function(){clearTimeout(r);r=setTimeout(n,300)},false);d.addEventListener("onload",n,false);n()}e(c,h);window.fabricViewport={currRem:j,currDpr:i,currScale:b,dpiPX2px:function f(k){return parseFloat(k.toString())/j*100+"px"},px2DPIpx:function a(k){return parseFloat(k.toString())/100*j+"px"},px2rem:function g(k){return parseFloat(k.toString())/100+"rem"}}})(window);';export const polyfill=["https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CArray.isArray%2CArray.of%2CArray.prototype.entries%2CArray.prototype.every%2CArray.prototype.fill%2CArray.prototype.filter%2CArray.prototype.find%2CArray.prototype.findIndex%2CArray.prototype.flat%2CArray.prototype.forEach%2CArray.prototype.flatMap%2CArray.prototype.keys%2CArray.prototype.indexOf%2CArray.prototype.includes%2CArray.prototype.lastIndexOf%2CArray.prototype.map%2CArray.prototype.reduce%2CArray.prototype.reduceRight%2CArray.prototype.some%2CArray.prototype.sort%2CArray.prototype.values%2CArrayBuffer%2CBlob%2CDataView%2CDate.now%2CObject.assign%2CObject.create%2CObject.defineProperties%2CObject.defineProperty%2CObject.entries%2CObject.freeze%2CObject.fromEntries%2CObject.getOwnPropertySymbols%2CObject.getOwnPropertyNames%2CObject.getOwnPropertyDescriptors%2CObject.getOwnPropertyDescriptor%2CObject.getPrototypeOf%2CObject.is%2CObject.isExtensible%2CObject.isFrozen%2CObject.isSealed%2CObject.keys%2CObject.values%2CObject.setPrototypeOf%2CPromise%2CPromise.prototype.finally%2CReflect%2CReflect.apply%2CReflect.construct%2CReflect.defineProperty%2CReflect.deleteProperty%2CReflect.getPrototypeOf%2CReflect.getOwnPropertyDescriptor%2CReflect.get%2CReflect.ownKeys%2CReflect.isExtensible%2CReflect.has%2CReflect.preventExtensions%2CReflect.set%2CReflect.setPrototypeOf%2CSet%2CString.prototype.trimStart%2CString.prototype.trimEnd%2CString.prototype.trim%2CString.prototype.startsWith%2CString.prototype.repeat%2CString.prototype.replaceAll%2CString.prototype.padStart%2CString.prototype.padEnd%2CMap%2CObject.seal%2Cconsole.groupEnd%2Cconsole.group"];
@@ -0,0 +1,4 @@
1
+ import { type Configuration } from 'webpack';
2
+ import { type EntryMapItem } from '../types/types-entry-map.js';
3
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
4
+ export declare const createExternals: (externals: FlatEvolveWebpackOptions['externals'], entryItem: EntryMapItem) => Configuration['externals'];
@@ -0,0 +1 @@
1
+ import{mergeOptions}from"@flatjs/common";export const createExternals=(t={},e)=>{const o=e[1],r=o.options?.externals||{};return mergeOptions(t,r)};
@@ -0,0 +1,3 @@
1
+ import { type Configuration } from 'webpack';
2
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
3
+ export declare const createOptimization: (serveMode: boolean, webpackOptions?: FlatEvolveWebpackOptions) => Configuration['optimization'];
@@ -0,0 +1 @@
1
+ import{createMinimizers}from"../minimizer/index.js";export const createOptimization=(e,i)=>({nodeEnv:e?"development":"production",chunkIds:"named",moduleIds:"named",minimize:!1!==i?.minimizer&&!e,minimizer:createMinimizers(e,i),splitChunks:{name:!1,chunks:"all",minSize:25e5,cacheGroups:{default:!1,defaultVendors:!1}}});
@@ -0,0 +1,3 @@
1
+ import { type Configuration } from 'webpack';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export declare const createOutput: (serveMode: boolean, evolveOptions: FlatEvolveOptions) => Configuration['output'];
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{getBundleFileName}from"../helpers/get-bundle-file-name.js";export const createOutput=(e,t)=>{const{projectCwd:a,webpack:n}=t;let o="auto";n?.publicPath&&"auto"!==n.publicPath&&(o=ensureSlash(n.publicPath,!0));return{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${join(e,t)}`,environment:{},pathinfo:!1,path:join(a,"public"),publicPath:o,filename:`[name]/${getBundleFileName("js",e,n?.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].js"}};
@@ -0,0 +1,2 @@
1
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
2
+ export declare const createPerformance: (serveMode: boolean, performanceOptions?: FlatEvolveWebpackOptions['performance']) => FlatEvolveWebpackOptions['performance'];
@@ -0,0 +1 @@
1
+ export const createPerformance=(n,e={})=>{const r={hints:!n&&"warning"};return Object.assign(r,e)};
@@ -0,0 +1,4 @@
1
+ import { type EntryMapItem } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
4
+ export declare const createPlugins: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => FlatEvolveWebpackOptions['plugins'];
@@ -0,0 +1 @@
1
+ import{logger}from"@flatjs/common";import ReactRefreshWebpackPlugin from"@pmmmwh/react-refresh-webpack-plugin";import CaseSensitivePathsPlugin from"case-sensitive-paths-webpack-plugin";import ForkTsCheckerWebpackPlugin from"fork-ts-checker-webpack-plugin";import MiniCssExtractPlugin from"mini-css-extract-plugin";import{BundleAnalyzerPlugin}from"webpack-bundle-analyzer";import{enableBundleHashNameForModule}from"../helpers/enable-bundle-hashname-for-module.js";import{getBundleFileName}from"../helpers/get-bundle-file-name.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{createCleanWebpackPlugin}from"../plugins/clean-webpack/index.js";import{createModuleFederationPlugin}from"../plugins/module-federation/index.js";import{createHtmlPlugins}from"../plugins/multi-html/index.js";export const createPlugins=(e,n,a)=>{const[r,l]=n,s=enableBundleHashNameForModule(a,l?.options),i=[new CaseSensitivePathsPlugin,new MiniCssExtractPlugin({filename:`[name]/${getBundleFileName("css",e,s)}`,chunkFilename:"[id].[contenthash].css"}),...createCleanWebpackPlugin(e,n,a),...createModuleFederationPlugin(e,n,a),...createHtmlPlugins(e,n,a)],{analyzer:t,loaderOptions:o,webpack:u}=a;o.runTsChecker&&i.push(new ForkTsCheckerWebpackPlugin({async:e})),t&&i.push(new BundleAnalyzerPlugin({analyzerPort:"auto",analyzerMode:"server",...t}));const c=shouldEnableReactFastRefresh(e,n,a);c&&i.push(new ReactRefreshWebpackPlugin({overlay:!1})),!c&&e&&logger.warn(`The HMR has disabled cause of ("${r}":"moduleFederation")`);const m=u?.plugins||[];return i.concat(m)};
@@ -0,0 +1,2 @@
1
+ import { type FlatEvolveWebpackOptions } from '../types/types-webpack.js';
2
+ export declare const createResolve: (webpackOptions?: FlatEvolveWebpackOptions) => import("webpack").ResolveOptions;
@@ -0,0 +1 @@
1
+ import{mergeOptions}from"@flatjs/common";export const createResolve=e=>mergeOptions({mainFields:["browser","module","main"],extensions:[".ts",".tsx",".js",".json",".vue"]},e?.resolve||{});
@@ -0,0 +1,4 @@
1
+ import { type RuleSetRule } 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 createRuleSets: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => RuleSetRule[];
@@ -0,0 +1 @@
1
+ import{ruleAssets}from"./rule-sets/rule-assets.js";import{ruleCss}from"./rule-sets/rule-css.js";import{ruleLess}from"./rule-sets/rule-less.js";import{ruleScripts}from"./rule-sets/rule-scripts.js";import{ruleSvgIcon}from"./rule-sets/rule-svg-icon.js";export const createRuleSets=(s,e,r)=>{const t=[ruleSvgIcon(),ruleAssets(e,r),ruleCss(s,e,r),ruleLess(s,e,r),ruleScripts(s,e,r)],l=r.webpack?.ruleSets||[];return t.concat(l)};
@@ -0,0 +1,10 @@
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
+ * Try to organization the configuraiton object of `webpack`
6
+ * @param mode Enable production optimizations or development hints.
7
+ * @param entryMap The only single one `servedEntry` or `toBuildEntry`
8
+ * @param overrideOptions The manually override configuration options for flatjsEvolve
9
+ */
10
+ export declare const loadWebpackConfig: (mode: 'production' | 'development', entryMap: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Omit<Configuration, 'entry'>;
@@ -0,0 +1 @@
1
+ import{assertOnlySingleEntryItem}from"../helpers/assert-only-single-entry-item.js";import{createExternals}from"./create-externals.js";import{createOptimization}from"./create-optimization.js";import{createOutput}from"./create-output.js";import{createPerformance}from"./create-performance.js";import{createPlugins}from"./create-plugins.js";import{createResolve}from"./create-resolve.js";import{createRuleSets}from"./create-rule-sets.js";export const loadWebpackConfig=(e,t,r)=>{const a="development"===e,{projectCwd:o,webpack:s,devServer:n}=r,c=n?.watchOptions,i=assertOnlySingleEntryItem(t,r),m=createRuleSets(a,i,r);return{mode:e,plugins:createPlugins(a,i,r),watchOptions:c,context:o,target:s?.target??["web","es5"],resolve:createResolve(s),module:{rules:m},devtool:a?"eval-source-map":s?.sourceMap||!1,externals:createExternals(s?.externals,i),output:createOutput(a,r),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,s),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
@@ -0,0 +1,3 @@
1
+ export declare const ICON_PATH_REGEX: RegExp;
2
+ export declare const IMAGE_PATH_REGEX: RegExp;
3
+ export declare const FONT_PATH_REGEX: RegExp;
@@ -0,0 +1 @@
1
+ export const ICON_PATH_REGEX=/svg-icons\//;export const IMAGE_PATH_REGEX=/\.(?:jpe?g|png|gif|svg)$/;export const FONT_PATH_REGEX=/\.(?:ttf|eot|woff|woff2)(?:\?.+)?$/;
@@ -0,0 +1,10 @@
1
+ import { type RuleSetRule } from 'webpack';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ /**
5
+ * Preparing image loader for normal pictures except stored in folder `icons`
6
+ * Webpack@5 don't need `file-loader`, `raw-loader`, `url-loader` provider us `asset-modules`
7
+ * https://webpack.js.org/guides/asset-modules/
8
+ * @param entryItem The available entries, `development` it contains multiple enties, `production` only one entry in once build.
9
+ */
10
+ export declare const ruleAssets: (entryItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => RuleSetRule;
@@ -0,0 +1 @@
1
+ import{dirname,join,relative,resolve}from"node:path";import{FONT_PATH_REGEX,IMAGE_PATH_REGEX}from"./constants.js";import{isIconSvg}from"./rule-utils.js";const getEntryAssetFileName=(e,t,r)=>{const[n,s]=t,{projectCwd:o,projectVirtualPath:i}=r;let a=dirname(join(i,e.replace(/^src/,"")));const m=s.entry.map((e=>dirname(join(o,e)))),l=resolve(o,e),c=m.find((e=>l.startsWith(e)));return c&&(a=dirname(join(n,relative(c,l)))),`${a}/[name]-[contenthash:8][ext]`};export const ruleAssets=(e,t)=>({type:"asset",test:e=>FONT_PATH_REGEX.test(e)||IMAGE_PATH_REGEX.test(e)&&!isIconSvg(e),generator:{filename:({filename:r})=>getEntryAssetFileName(r,e,t)},parser:{dataUrlCondition:{maxSize:4096}}});
@@ -0,0 +1,11 @@
1
+ import { type RuleSetRule } from 'webpack';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ /**
5
+ * Actually, style-loader is the one that is responsible for CSS HMR
6
+ * https://github.com/webpack-contrib/style-loader/blob/master/src/index.js#L31-L42
7
+ * @param serveMode
8
+ * @param entryMapItem
9
+ * @param evolveOptions `builtin` loaders
10
+ */
11
+ export declare const ruleCss: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => RuleSetRule;
@@ -0,0 +1 @@
1
+ import{forgePostcssPluginPixel}from"@flatjs/forge-postcss-plugin-pixel";import cssnano from"cssnano";import MiniCssExtractPlugin from"mini-css-extract-plugin";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";const getPostcssOptions=(s,o={},e={})=>{const r=[cssnano({preset:["default",{discardComments:{removeAll:!s},reduceInitial:!1,normalizeWhitespace:!s,...e}]})];return!1!==o&&r.push(forgePostcssPluginPixel(o)),{plugins:r}};export const ruleCss=(s,o,e)=>{const r={test:/\.css$/i,use:[{loader:MiniCssExtractPlugin.loader,options:{esModule:!0}},{loader:"css-loader",options:{sourceMap:s}}]},{pixelOptions:t,cssnanoOptions:i}=e.loaderOptions,l=allowPx2remForModule(o,e);return Array.isArray(r.use)&&r.use.push({loader:"postcss-loader",options:{postcssOptions:getPostcssOptions(s,!!l&&t,i),sourceMap:s}}),r};
@@ -0,0 +1,9 @@
1
+ import { type RuleSetRule } from 'webpack';
2
+ import { type EntryMapItem } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ /**
5
+ * Preparing configurations for `less-loader`
6
+ * @param serveMode The value indicates if we are in `built` or `serve` mode.
7
+ * @param pluginLoaderOptions `builtin` loaders
8
+ */
9
+ export declare const ruleLess: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => RuleSetRule;
@@ -0,0 +1 @@
1
+ import{requireResolve}from"@flatjs/common";import{ruleCss}from"./rule-css.js";export const ruleLess=(s,e,r)=>{const o=ruleCss(s,e,r);o.test=/\.less$/i;const l=r.loaderOptions.lessOptions;return Array.isArray(o.use)&&o.use.push({loader:requireResolve("less-loader"),options:{sourceMap:s,lessOptions:{sourceMap:s,javascriptEnabled:!0,...l}}}),o};
@@ -0,0 +1,3 @@
1
+ import { type RuleSetRule } from 'webpack';
2
+ import { type EntryMapItem, type FlatEvolveOptions } from '../../types/index.js';
3
+ export declare const ruleScripts: (serveMode: boolean, entryMapItem: EntryMapItem, evolveOptions: FlatEvolveOptions) => RuleSetRule;
@@ -0,0 +1 @@
1
+ import{requireResolve}from"@flatjs/common";import{mergeBabelOption}from"../../helpers/merge-babel-options.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";export const ruleScripts=(e,r,s)=>{const{babelOptions:o={},modularImports:l=[]}=s.loaderOptions,t=mergeBabelOption(l,o);shouldEnableReactFastRefresh(e,r,s)&&(t.plugins?t.plugins.push(requireResolve("react-refresh/babel")):t.plugins=[requireResolve("react-refresh/babel")]);return{test:/\.(tsx|ts|js|jsx)$/,use:[{loader:requireResolve("babel-loader"),options:t}]}};
@@ -0,0 +1,6 @@
1
+ import { type RuleSetRule } from 'webpack';
2
+ /**
3
+ * Preparing svg loader for `icons`
4
+ * Note we must be put all *.svg into folder `icons`
5
+ */
6
+ export declare const ruleSvgIcon: () => RuleSetRule;
@@ -0,0 +1 @@
1
+ import{getDirname}from"@armit/file-utility";import{isIconSvg}from"./rule-utils.js";export const ruleSvgIcon=()=>({test:e=>isIconSvg(e),use:[{loader:getDirname(import.meta.url,"../../loaders/loader-icon.cjs"),options:{svgo:{plugins:[{name:"removeTitle"},{name:"removeDimensions"}]}}}]});
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Causeof we expose a component <Icon /> from `@wove/react` it can be optimized via icon-loader.
3
+ * limitation assets match `svg-icons/**\/*.svg` to icon loader resolver.
4
+ * @param resource
5
+ * @returns
6
+ */
7
+ export declare const isIconSvg: (resource: string) => boolean;
@@ -0,0 +1 @@
1
+ import{ICON_PATH_REGEX}from"./constants.js";export const isIconSvg=s=>ICON_PATH_REGEX.test(s)&&s.endsWith(".svg");
@@ -0,0 +1,2 @@
1
+ import { type WebpackPluginInstance, type Compiler } from 'webpack';
2
+ export type WebpackPlugin = ((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance;
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,2 @@
1
+ import { type FlatEvolveOptions } from './types/types-options.js';
2
+ export declare const defaultEvolveOptions: FlatEvolveOptions;
@@ -0,0 +1 @@
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,mockOptions:{mockBaseDir:"mocks"},middlewares:[],watchOptions:{poll:1e3,ignored:/node_modules/,aggregateTimeout:500},defaultServeGlobalData:()=>({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},enableBundleHashName:!0},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},cssnanoOptions:{},pixelOptions:{rootValue:{px:100,rpx:1},outputUnit:"rem"},modularImports:[]},entryMap:{},multiHtmlCdn:{},multiHtmlCdnEnvResolver:function cdnResolver(){},needVerifyPackages:{},packageInstallChecker:{enabled:!1,detectModules:["@dimjs/*"],throwError:!1,showAllInstalledGraph:!0}};
@@ -0,0 +1,6 @@
1
+ import { type DeepPartial, type UserConfigExport, type ConfigEnvBase } from '@flatjs/common';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export interface EvolveConfigBase extends ConfigEnvBase {
4
+ command: 'build' | 'serve' | 'static';
5
+ }
6
+ export declare const defineConfig: (userConfig: UserConfigExport<DeepPartial<FlatEvolveOptions>, EvolveConfigBase>) => UserConfigExport<DeepPartial<FlatEvolveOptions>, EvolveConfigBase>;
@@ -0,0 +1 @@
1
+ import{defineConfig as myDefineConfig}from"@flatjs/common";export const defineConfig=f=>myDefineConfig(f);
@@ -0,0 +1 @@
1
+ export * from './define-config.js';
@@ -0,0 +1 @@
1
+ export*from"./define-config.js";
@@ -0,0 +1,10 @@
1
+ import { type Compiler } from 'webpack';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Integrated webpack-dev-server with `mock` server together
5
+ * @param compiler Webpack compiler(s)
6
+ * @param enableHmr Value indicates if we need to liveReload or `HMR`
7
+ * @param devPort The port number of `@flatjs/mock`
8
+ * @param evolveOptions The configuration of `@flatjs/evolve` (FlatEvolveOptions)
9
+ */
10
+ export declare const addCompilerToDevServer: (compiler: Compiler, enableHmr: boolean, devPort: number, evolveOptions: FlatEvolveOptions) => Promise<boolean>;
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import WebpackDevServer from"webpack-dev-server";export const addCompilerToDevServer=(e,r,o,t)=>{const{projectCwd:s,devServer:p}=t,i=new WebpackDevServer({server:{type:p?.https?"https":"http",options:{...p?.https}},open:!1,compress:!0,port:o,hot:r,liveReload:!r,allowedHosts:"all",static:{directory:`${join(s,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:!0,overlay:{errors:!0,warnings:!1}}},e);return new Promise(((e,r)=>{i.startCallback((o=>{if(o)return r(o);e(!0)}))}))};
@@ -0,0 +1,7 @@
1
+ import { type Application } from 'express';
2
+ import { type FlatEvolveOptions } from '../types/index.js';
3
+ import { type EvolveDevServerEntryMap } from './middlewares/index.js';
4
+ /**
5
+ * Add route `/pages`, `*` to main web-server
6
+ */
7
+ export declare const createAppPageRoute: (projectCwd: string, app: Application, devHostUri: string, servedDevServerEntries: EvolveDevServerEntryMap, evolveOptions: FlatEvolveOptions) => void;
@@ -0,0 +1 @@
1
+ import{createPageMiddleware,createPublicAssetsMiddleware}from"./middlewares/index.js";export const createAppPageRoute=(e,a,r,t,s)=>{const{devServer:d}=s;a.use("/pages",...createPageMiddleware(r,d?.mockOptions?.apiContext||"api",t,s)),a.use("*",createPublicAssetsMiddleware(e))};
@@ -0,0 +1,3 @@
1
+ import { type FlatEvolveOptions } from '../types/types-options.js';
2
+ import { type EvolveDevServerEntryMap } from './middlewares/create-page-middleware.js';
3
+ export declare const createDevServerCompilerTasks: (projectCwd: string, mainPage: string, servedDevServerEntries: EvolveDevServerEntryMap, evolveOptions: FlatEvolveOptions) => Promise<boolean>[];
@@ -0,0 +1 @@
1
+ import{relative}from"node:path";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTasks=(e,o,r,t)=>{const i=[];for(const[a,n]of Object.entries(r)){const l=n.entryConfig,s=l.options?.moduleFederation,p=shouldEnableReactFastRefresh(!0,[a,l],t);(s?.remotes||[]).forEach((e=>{e.endpoint=e=>{const o=r[e];if(!o)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(o?.devServerHostUri,["/public"])}}));const{devServerPort:c,devServerHostUri:m}=r[a],f={[a]:l},d=urlJoin(m,["public"]),v=loadWebpackConfig("development",f,mergeOptions(t,{webpack:{publicPath:d}})),h=webpack(splitToMultiCompilerConfigs(f,v,t)[0]);i.push(addCompilerToDevServer(h,p,c,t));const g=h.name||"";h.hooks.invalid.tap("fileChange",(o=>{const r=relative(e,o||"");logger.info(`file change ➩ ${chalk(["cyan"])(r)}`,g)})),h.hooks.done.tap("compileDone",(()=>{logger.info(`debug page ➩ ${chalk(["cyan"])(o)}`,g)}))}return i};
@@ -0,0 +1,4 @@
1
+ import { type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ import { type EvolveDevServerEntryMap } from './middlewares/create-page-middleware.js';
4
+ export declare const createDevServerEntries: (startPort: number, servedEntries: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => Promise<EvolveDevServerEntryMap>;
@@ -0,0 +1 @@
1
+ import{mergeOptions}from"@flatjs/common";import{prepareMockDomain}from"@flatjs/mock";import{normalizeEvolveEntryName}from"../helpers/normalize-entry-map.js";export const createDevServerEntries=async(r,e,o)=>{const{devServer:t,projectVirtualPath:n}=o,m={};let a=r;for(const[r,o]of Object.entries(e)){a+=1;const{mockPort:e,hostUri:i}=await prepareMockDomain(mergeOptions(t?.mockOptions||{},{port:a})),s=normalizeEvolveEntryName(r,n);m[r]={entryConfig:o,devServerPort:e,devServerHostUri:i,normalizedEntryName:s}}return m};
@@ -0,0 +1,6 @@
1
+ import { type FlatEvolveOptions } from '../types/index.js';
2
+ export declare const createDevServer: (evolveOptions: FlatEvolveOptions) => Promise<{
3
+ devPort: number;
4
+ devHostUri: string;
5
+ app: import("express-serve-static-core").Express;
6
+ }>;
@@ -0,0 +1 @@
1
+ import https from"node:https";import{prepareMockDomain}from"@flatjs/mock";import express from"express";export const createDevServer=async e=>{const r=express(),t=e.devServer?.mockOptions,{mockPort:o,hostUri:s}=await prepareMockDomain(t||{});return new Promise((t=>{const p=e.devServer?.https?https.createServer(e.devServer?.https,r):r;r.set("hostUri",s),p.listen(o,(()=>{t({app:r,devHostUri:s,devPort:o})}))}))};
@@ -0,0 +1,6 @@
1
+ export * from './middlewares/index.js';
2
+ export * from './add-compiler-to-dev-server.js';
3
+ export * from './create-dev-server.js';
4
+ export * from './create-app-page-route.js';
5
+ export * from './create-dev-server-entries.js';
6
+ export * from './create-dev-server-compiler-tasks.js';
@@ -0,0 +1 @@
1
+ export*from"./middlewares/index.js";export*from"./add-compiler-to-dev-server.js";export*from"./create-dev-server.js";export*from"./create-app-page-route.js";export*from"./create-dev-server-entries.js";export*from"./create-dev-server-compiler-tasks.js";
@@ -0,0 +1,37 @@
1
+ import { type RequestHandler } from 'express';
2
+ import { type EvolveEntryMapContent } from '../../types/types-entry-map.js';
3
+ import { type FlatEvolveOptions } from '../../types/types-options.js';
4
+ export type EvolveDevServerEntryMap = {
5
+ /**
6
+ * entryName: `home`
7
+ */
8
+ [entryName: string]: {
9
+ /**
10
+ * entryMapItem config options.
11
+ */
12
+ entryConfig: EvolveEntryMapContent;
13
+ /**
14
+ * dev server port number
15
+ */
16
+ devServerPort: number;
17
+ /**
18
+ * dev server host uri.
19
+ */
20
+ devServerHostUri: string;
21
+ /**
22
+ * entryName: `home` should be normallized to ${`projectVirtualPath`}/home
23
+ */
24
+ normalizedEntryName: string;
25
+ };
26
+ };
27
+ /**
28
+ * A middleware to proxy the page modules template.
29
+ * @example `http://dev.flatjs.com:3001/pages`
30
+ * @param mode The mode of this dev server instance.
31
+ * @param hostUri The main host base url.
32
+ * @param apiContext apiBase e.g. `api`
33
+ * @param servedDevServerEntries The served webpack entries
34
+ * @param forPageMiddlewares Allow us provider customized middlewares for `page`, `modules`
35
+ * @param evolveOptions The evolve config options
36
+ */
37
+ export declare const createPageMiddleware: (devHostUri: string, apiContext: string, servedDevServerEntries: EvolveDevServerEntryMap, evolveOptions: FlatEvolveOptions) => RequestHandler[];
@@ -0,0 +1 @@
1
+ import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{injectFederationScripts}from"../../helpers/script-injects.js";const getPageMainHtml=async(e,t,l)=>{const r=getPackageDir(),o=readFileSync(join(r,"./templates/main.html"),"utf-8"),a=[],i=l.projectVirtualPath.replace(/^\//,"");for(const[r,o]of Object.entries(l.entryMap)){const l=o.options?.servePageMainLinkFn||(e=>e),n=Object.keys(e).includes(r),s=normalizeEvolveEntryName(r,i),m=urlJoin(t,["pages",s],{env:"me"});a.push({name:r.replace(i,"").replace(/^\//,""),link:l(m,{hostUri:t,entryName:r,virtualPath:i}),flagText:n?"serve":"static",isServed:n?1:0})}const n={title:"@flatjs/evolve",modules:a.sort(((e,t)=>t.isServed-e.isServed))};return _.template(o)(n)},getPageModuleHtml=async(e,t,l,r,o)=>{const{entryMap:a,projectVirtualPath:i}=o,n=Object.keys(a).sort(((e,t)=>t.length-e.length)),s=getPackageDir(),m=n.find((e=>{const l=normalizeEvolveEntryName(e,i);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(l,!0))}));if(!m){const e=readFileSync(join(s,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:s},{name:"served entry names",value:JSON.stringify(n)},{name:"module path",value:`${t.path}`}]})}const p=normalizeEvolveEntryName(m,i),c=a[m],d=c.options,u=e[m],g=u?.devServerHostUri||l,f=d?.serveModuleTemplate||"./templates/module.html",v=join(o.projectCwd,"./templates/module.html"),h=readFileSync(isAbsolute(f)?f:existsSync(v)?v:join(s,"./templates/module.html"),"utf-8"),S=o.devServer,y=S?.defaultServeGlobalData?S.defaultServeGlobalData(c,l):{},j={title:getHtmlPluginConfig("title","development",d?.title),favicon:getHtmlPluginConfig("favicon","development",d?.favicon),viewport:allowPx2remForModule([m,c],o)?getHtmlPluginConfig("viewport","development",d?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags","development",d?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts","development",d?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles","development",d?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts","development",d?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts","development",d?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(l,["public"])]},o.multiHtmlCdnEnvResolver),global:{hostUrl:l,apiBase:urlJoin(l,[r]),virtualPath:join("/pages",i),moduleName:m.replace(i,"").replace(/^\//,""),...y,...d?.serveGlobalData||{}},styles:[urlJoin(g,[join("public",p,"bundle.css")])],scripts:[urlJoin(g,[join("public",p,"bundle.js")])]};return _.template(h)(j)};export const createPageMiddleware=(e,t,l,r)=>(r.devServer?.middlewares||[]).concat((async(o,a)=>{let i;i="/"===o.path?await getPageMainHtml(l,e,r):await getPageModuleHtml(l,o,e,t,r),a.send(i)}));
@@ -0,0 +1,2 @@
1
+ import { type RequestHandler } from 'express';
2
+ export declare const createPublicAssetsMiddleware: (projectCwd: string) => RequestHandler;
@@ -0,0 +1 @@
1
+ import{extname,join}from"node:path";import{fileWalk}from"@armit/file-utility";export const createPublicAssetsMiddleware=e=>async(i,s)=>{const t=i.baseUrl;if(t.startsWith("/public")){const i=await fileWalk(join("public/","**/*.{js,css}"),{cwd:e}),a=extname(t),l=i.find((e=>extname(e)===a&&-1!==e.indexOf(t.replace(/\.(?:js|css)$/,""))));l?s.sendFile(l):s.sendFile(join(e,t))}else s.redirect("/pages")};
@@ -0,0 +1,2 @@
1
+ export * from './create-page-middleware.js';
2
+ export * from './create-public-assets-middleware.js';
@@ -0,0 +1 @@
1
+ export*from"./create-page-middleware.js";export*from"./create-public-assets-middleware.js";
@@ -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 allowPx2remForModule: (entryItem?: EntryMapItem, evolveOptions?: FlatEvolveOptions) => boolean;
@@ -0,0 +1 @@
1
+ export const allowPx2remForModule=(o,e)=>{const l=e?.loaderOptions?.pixelOptions;return!!((o&&o[1]?.options?.allowPx2rem)??l)};
@@ -0,0 +1,7 @@
1
+ import { type EntryMapItem, type EvolveEntryMap } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ /**
4
+ * Only fetch single one entry map once `serve`,`build` recycle.
5
+ * @returns
6
+ */
7
+ export declare const assertOnlySingleEntryItem: (entryMap: EvolveEntryMap, evolveOptions: FlatEvolveOptions) => EntryMapItem;
@@ -0,0 +1 @@
1
+ import{normalizeEvolveEntryName}from"./normalize-entry-map.js";export const assertOnlySingleEntryItem=(e,r)=>{if(Object.keys(e).length>1)throw new Error("Only single one entry map support right now for `serve`, `build`!");let t;for(const[r,o]of Object.entries(e)){t=[r,o];break}if(!t)throw new Error('No entry map found while "serve", "build" process!');const[o,n]=t;return[normalizeEvolveEntryName(o,r.projectVirtualPath),n]};
@@ -0,0 +1,3 @@
1
+ import { type EvolveEntryItemOption } from '../types/types-entry-map.js';
2
+ import { type FlatEvolveOptions } from '../types/types-options.js';
3
+ export declare const enableBundleHashNameForModule: (evolveOptions: FlatEvolveOptions, entryItemOption?: EvolveEntryItemOption) => boolean;
@@ -0,0 +1 @@
1
+ export const enableBundleHashNameForModule=(e,a)=>{const n=e.webpack?.enableBundleHashName;return!!(a?.enableBundleHashName??n)};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Get current timestramp as `string`
3
+ */
4
+ export declare const currNow: () => string;
5
+ /**
6
+ * Generate bundle file name from rules
7
+ * 1. if `serveMode`, always return `bundle
8
+ * 2. else if `enableBundleHashName` always return `bundle[contenthash].{css,js}`
9
+ * 3. otherwise return `bundle.{css,js}?${currNow}`
10
+ * @param type `js` | `css`
11
+ * @param serveMode If we are run `serve` mode
12
+ * @param enableBundleHashName If we need to generate bundle file name with `[contenthash]`
13
+ */
14
+ export declare const getBundleFileName: (type: 'css' | 'js', serveMode: boolean, enableBundleHashName?: boolean) => string;
@@ -0,0 +1 @@
1
+ export const currNow=()=>Date.now().toString();export const getBundleFileName=(t,n,e=!0)=>{const o="js"===t?".js":".css";return n?`bundle${o}`:e?`bundle[contenthash]${o}`:`bundle${o}?${Date.now().toString()}`};
@@ -0,0 +1,12 @@
1
+ import { type MultiHtmlCDNEntryItem } from '../types/types-multi-html.js';
2
+ export declare const defaultHtmlPluginConfig: Required<MultiHtmlCDNEntryItem>;
3
+ type Json = undefined | null | boolean | number | string | Json[] | {
4
+ [prop: string]: Json;
5
+ };
6
+ /**
7
+ * 获取html plugin 模版相关定义字段.
8
+ * @param preferredValue 用户首选的值, 如果返回为undefined, 将使用默认值
9
+ * @returns
10
+ */
11
+ export declare const getHtmlPluginConfig: <T extends Json>(key: keyof typeof defaultHtmlPluginConfig, mode: 'development' | 'production', preferredValue?: T | ((mode: 'development' | 'production') => T) | undefined) => T;
12
+ export {};
@@ -0,0 +1 @@
1
+ import{polyfill,viewportScripts}from"../constants.js";import{getPackageDir}from"./get-pacakge-dir.js";export const defaultHtmlPluginConfig={title:"",favicon:"",headBeforeHtmlTags:[],inlineScripts:[],headBeforeStyles:[],headBeforeScripts:[...polyfill],bodyAfterScripts:[],viewport:viewportScripts,excludeCdnEnvs:["me","dev","ntv"],htmlMinify:!0,templatePath:getPackageDir("templates/html-plugin/index-{0}.html")};export const getHtmlPluginConfig=(t,e,i)=>{let o;if(void 0!==i&&(o="function"==typeof i?i(e):i),void 0===o){const i=defaultHtmlPluginConfig[t];return"function"==typeof i?i(e):i}return o};
@@ -0,0 +1 @@
1
+ export declare const getPackageDir: (...paths: string[]) => string;
@@ -0,0 +1 @@
1
+ import{join}from"node:path";import{getDirname}from"@armit/file-utility";import{searchPackageDir}from"@armit/package";export const getPackageDir=(...r)=>{const e=getDirname(import.meta.url),o=searchPackageDir({cwd:e});if(!o)throw new Error("Could not resolve package root for `flatjs/evolve`");return join(o,...r)};
@@ -0,0 +1,14 @@
1
+ export * from './allow-px2rem-for-module.js';
2
+ export * from './assert-only-single-entry-item.js';
3
+ export * from './enable-bundle-hashname-for-module.js';
4
+ export * from './get-bundle-file-name.js';
5
+ export * from './get-html-plugin-config.js';
6
+ export * from './get-pacakge-dir.js';
7
+ export * from './merge-babel-options.js';
8
+ export * from './normalize-entry-map.js';
9
+ export * from './open-page.js';
10
+ export * from './print-log.js';
11
+ export * from './refresh-evolve-mock-options.js';
12
+ export * from './script-injects.js';
13
+ export * from './should-enable-react-fast-refresh.js';
14
+ export * from './split-to-multi-compiler.js';
@@ -0,0 +1 @@
1
+ export*from"./allow-px2rem-for-module.js";export*from"./assert-only-single-entry-item.js";export*from"./enable-bundle-hashname-for-module.js";export*from"./get-bundle-file-name.js";export*from"./get-html-plugin-config.js";export*from"./get-pacakge-dir.js";export*from"./merge-babel-options.js";export*from"./normalize-entry-map.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-multi-compiler.js";
@@ -0,0 +1,4 @@
1
+ import { type TransformOptions } from '@babel/core';
2
+ import { type BuiltinBabelOptions } from '../types/types-loader-options.js';
3
+ import { type ModularImportOption } from '../types/types-modular-import.js';
4
+ export declare const mergeBabelOption: (modularImports?: ModularImportOption[], options?: BuiltinBabelOptions) => TransformOptions;
@@ -0,0 +1 @@
1
+ import{logger,requireResolve}from"@flatjs/common";import{reactBabelPreset,vueBabelPreset}from"@flatjs/evolve-preset-babel";import babelMerge from"babel-merge";import{moduleName}from"../constants.js";export const mergeBabelOption=(e=[],r={usePreset:"react"})=>{const t=e.map((e=>[requireResolve("babel-plugin-import"),{transformToDefaultImport:!1,libraryDirectory:"dist",...e},e.libraryName])),{usePreset:a="react",...l}=r,o="react"===a?reactBabelPreset():"vue"===a?vueBabelPreset():reactBabelPreset();let s={};try{s=babelMerge(o,l),s.plugins?s.plugins.unshift(...t):s.plugins=t}catch(e){logger.error(e,moduleName)}return{...s,babelrc:!1}};