@flatjs/evolve 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,13 @@
1
1
  import type { Plugin as RspackPlugin } from '@rspack/core';
2
2
  import { type EntryMapItem } from '../../../types/types-entry-map.js';
3
3
  import { type FlatEvolveOptions } from '../../../types/types-options.js';
4
+ /**
5
+ * Create `html-webpack-plugin` for this build, refer to best practices
6
+ *
7
+ * IF serveMode is true, not attach any plugins
8
+ * Otherwise, attach `html-webpack-plugin` and `@flatjs/evolve-plugin-multi-html-cdn`
9
+ *
10
+ * @param buildEntryItem the entries for this `build`
11
+ * @param allEnv
12
+ */
4
13
  export declare const createHtmlRspackPlugins: (serveMode: boolean, entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions) => RspackPlugin[];
@@ -1 +1 @@
1
- import{FlatEvolveMultiCdnRspackPlugin}from"./multi-html-cdn-rspack-plugin.js";import{createMultiHtmlRspackPlugins}from"./multi-html-rspack-plugin.js";export const createHtmlRspackPlugins=(t,l,i)=>{const n=[new FlatEvolveMultiCdnRspackPlugin(i,l)],u=l[0];if(t||u[1]?.options?.output?.library)return n;const s=Object.keys(i.multiHtmlCdn);return n.unshift(...createMultiHtmlRspackPlugins(t,i,l,s)),n};
1
+ import{FlatEvolveMultiCdnRspackPlugin}from"./multi-html-cdn-rspack-plugin.js";import{createMultiHtmlRspackPlugins}from"./multi-html-rspack-plugin.js";export const createHtmlRspackPlugins=(t,l,s)=>{const u=[];if(t)return u;const i=Object.keys(s.multiHtmlCdn);return u.push(...createMultiHtmlRspackPlugins(t,s,l,i)),u.push(new FlatEvolveMultiCdnRspackPlugin(s,l)),u};
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnRspackPlugin{constructor(e,t){if(this.pluginName="FlatEvolveMultiCdnRspackPlugin",this.requireFn=rspack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.entryMapItemList=t,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.compilation.tap(this.pluginName,e=>{e.hooks.runtimeModule.tap(this.pluginName,(e,t)=>{const s=this.entryMapItemList.find(e=>e[0]===t.name);if("public_path"===e.name&&s){const t=[];t.push("\n"),t.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)"),t.push(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn)),e.source.source=Buffer.from(t.join("\n"),"utf-8")}})}),e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,e=>{const{assets:t,plugin:s,outputName:n}=e,i=s?.options?.chunks||[],r=Array.isArray(i)?i.find(e=>n.includes(ensureSlash(e,!0))):i,{userOptions:o}=e.plugin;if(!r)throw new Error("We must have current chunk!");const a=t.js.filter(e=>e.includes(ensureSlash(r,!0))),l=t.css.filter(e=>e.includes(ensureSlash(r,!0))),u=o.multiCdn,p=t.publicPath,c=a.map(e=>{if(u.disabled)return basename(e);const t=findEnvCdn(this.config,u.env);return httpUrlJoin(t,e.replace(p,""))}),m=l.map(e=>{if(u.disabled)return basename(e);const t=findEnvCdn(this.config,u.env);return httpUrlJoin(t,e.replace(p,""))});return e.assets.js=c,e.assets.css=m,e})})}}
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import{ensureSlash}from"@flatjs/common";import rspack from"@rspack/core";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnRspackPlugin{constructor(e,t){if(this.pluginName="FlatEvolveMultiCdnRspackPlugin",this.requireFn=rspack.RuntimeGlobals.publicPath,this.config=e.multiHtmlCdn,this.entryMapItemList=t,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.compilation.tap(this.pluginName,e=>{e.hooks.runtimeModule.tap(this.pluginName,(e,t)=>{const s=this.entryMapItemList.find(e=>e[0]===t.name);if("public_path"===e.name&&s){const t=[];t.push("\n"),t.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)"),t.push(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn)),e.source.source=Buffer.from(t.join("\n"),"utf-8")}})}),e.hooks.compilation.tap(this.pluginName,t=>{HtmlWebpackPlugin.getHooks(t).beforeAssetTagGeneration.tap(this.pluginName,e=>{const{assets:t,plugin:s,outputName:n}=e,i=s?.options?.chunks||[],o=Array.isArray(i)?i.find(e=>n.includes(ensureSlash(e,!0))):i,{userOptions:r}=e.plugin;if(!o)throw new Error("We must have current chunk!");const a=t.js.filter(e=>e.includes(ensureSlash(o,!0))),l=t.css.filter(e=>e.includes(ensureSlash(o,!0))),p=r.multiCdn,u=t.publicPath,c=a.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}),m=l.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))});return e.assets.js=c,e.assets.css=m,e}),t.hooks.processAssets.tap({name:this.pluginName,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE},s=>{if(e.options.output.library)for(const e of Object.keys(s))e.endsWith(".html")&&delete t.assets[e]})})}}
@@ -1,4 +1,13 @@
1
1
  import { type EntryMapItem } from '../../../types/types-entry-map.js';
2
2
  import { type FlatEvolveOptions } from '../../../types/types-options.js';
3
3
  import type { WebpackPlugin } from '../../../types/types-webpack.js';
4
+ /**
5
+ * Create `html-webpack-plugin` for this build, refer to best practices
6
+ *
7
+ * IF serveMode is true, not attach any plugins
8
+ * Otherwise, attach `html-webpack-plugin` and `@flatjs/evolve-plugin-multi-html-cdn`
9
+ *
10
+ * @param buildEntryItem the entries for this `build`
11
+ * @param allEnv
12
+ */
4
13
  export declare const createHtmlWebpackPlugins: (serveMode: boolean, entryMapItemList: EntryMapItem[], evolveOptions: FlatEvolveOptions) => WebpackPlugin[];
@@ -1 +1 @@
1
- import{FlatEvolveMultiCdnWebpackPlugin}from"./multi-html-cdn-webpack-plugin.js";import{createMultiHtmlWebpackPlugins}from"./multi-html-webpack-plugins.js";export const createHtmlWebpackPlugins=(t,l,e)=>{const i=[new FlatEvolveMultiCdnWebpackPlugin(e)],n=l[0];if(t||n[1]?.options?.output?.library)return i;const u=Object.keys(e.multiHtmlCdn);return i.unshift(...createMultiHtmlWebpackPlugins(t,e,l,u)),i};
1
+ import{FlatEvolveMultiCdnWebpackPlugin}from"./multi-html-cdn-webpack-plugin.js";import{createMultiHtmlWebpackPlugins}from"./multi-html-webpack-plugins.js";export const createHtmlWebpackPlugins=(t,l,e)=>{const u=[];if(t)return u;const i=Object.keys(e.multiHtmlCdn);return u.push(...createMultiHtmlWebpackPlugins(t,e,l,i)),u.push(new FlatEvolveMultiCdnWebpackPlugin(e)),u};
@@ -1 +1 @@
1
- import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnWebpackPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnWebpackPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.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,(t,n)=>{const s=[];s.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const i=e.chunkGraph?.getTreeRuntimeRequirements(n);return i&&i.has(webpack.RuntimeGlobals.requireScope)&&s.push(webpack.Template.indent(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn))),webpack.Template.asString(s)})}),e.hooks.compilation.tap(this.pluginName,e=>{HtmlWebpackPlugin.getHooks(e).beforeAssetTagGeneration.tap(this.pluginName,e=>{const{assets:t,plugin:n,outputName:s}=e,i=n?.options?.chunks||[],r=Array.isArray(i)?i.find(e=>s.includes(ensureSlash(e,!0))):i,{userOptions:a}=e.plugin;if(!r)throw new Error("We must have current chunk!");const o=t.js.filter(e=>e.includes(ensureSlash(r,!0))),l=t.css.filter(e=>e.includes(ensureSlash(r,!0))),p=a.multiCdn,u=t.publicPath,c=o.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}),m=l.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))});return e.assets.js=c,e.assets.css=m,e})})}}
1
+ import HtmlWebpackPlugin from"html-webpack-plugin";import{basename}from"node:path";import webpack from"webpack";import{ensureSlash}from"@flatjs/common";import{getRuntimeCDNBase}from"../../../helpers/get-runtime-cdn-base.js";import{findEnvCdn,httpUrlJoin}from"../../../helpers/script-injects.js";export class FlatEvolveMultiCdnWebpackPlugin{constructor(e){if(this.pluginName="FlatEvolveMultiCdnWebpackPlugin",this.requireFn=webpack.RuntimeGlobals.publicPath,this.config=e.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,(t,s)=>{const n=[];n.push("// Dynamic assets path override(`@flatjs/evolve`) plugin-multi-html-cdn`)");const i=e.chunkGraph?.getTreeRuntimeRequirements(s);return i&&i.has(webpack.RuntimeGlobals.requireScope)&&n.push(webpack.Template.indent(getRuntimeCDNBase(this.config,this.cdnResolver,this.requireFn))),webpack.Template.asString(n)})}),e.hooks.compilation.tap(this.pluginName,t=>{HtmlWebpackPlugin.getHooks(t).beforeAssetTagGeneration.tap(this.pluginName,e=>{const{assets:t,plugin:s,outputName:n}=e,i=s?.options?.chunks||[],r=Array.isArray(i)?i.find(e=>n.includes(ensureSlash(e,!0))):i,{userOptions:o}=e.plugin;if(!r)throw new Error("We must have current chunk!");const a=t.js.filter(e=>e.includes(ensureSlash(r,!0))),l=t.css.filter(e=>e.includes(ensureSlash(r,!0))),p=o.multiCdn,u=t.publicPath,c=a.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))}),m=l.map(e=>{if(p.disabled)return basename(e);const t=findEnvCdn(this.config,p.env);return httpUrlJoin(t,e.replace(u,""))});return e.assets.js=c,e.assets.css=m,e}),t.hooks.processAssets.tap({name:this.pluginName,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE},s=>{if(e.options.output.library)for(const e of Object.keys(s))e.endsWith(".html")&&delete t.assets[e]})})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {