@flatjs/evolve 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- import{join}from"node:path";import{ensureSlash}from"@flatjs/common";import{getBundleFileName}from"../helpers/get-bundle-file-name.js";export const createOutput=async(e,t,o)=>{const{projectCwd:n,webpack:a}=t;let u="auto";const i=o[1];a?.publicPath&&"auto"!==a.publicPath&&(u=ensureSlash(a.publicPath,!0));const p="function"==typeof a?.outputDir?await a.outputDir():a?.outputDir||"public";return{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${join(e,t)}`,environment:{},pathinfo:!1,path:join(n,p),publicPath:u,filename:`[name]/${getBundleFileName("js",e,a?.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].js",...i.options?.output}};
1
+ import{join}from"node:path";import{getBundleFileName}from"../helpers/get-bundle-file-name.js";import{resolvePublicPath}from"./resolve-public-path.js";export const createOutput=async(e,t,o)=>{const{projectCwd:n,webpack:a}=t,i=o[1],p=resolvePublicPath(t),u="function"==typeof a?.outputDir?await a.outputDir():a?.outputDir||"public";return{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${join(e,t)}`,environment:{},pathinfo:!1,path:join(n,u),publicPath:p,filename:`[name]/${getBundleFileName("js",e,a?.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].js",...i.options?.output}};
@@ -0,0 +1,7 @@
1
+ import { type FlatEvolveOptions } from '../types/types-options.js';
2
+ /**
3
+ * Try to normalize publicPath, if we have customized publicPath, should be converted to `https://cdn.example.com/assets/`, `/assets/`
4
+ * @param evolveOptions
5
+ * @returns `auto` or customizd publicPath
6
+ */
7
+ export declare const resolvePublicPath: (evolveOptions: FlatEvolveOptions) => string;
@@ -0,0 +1 @@
1
+ import{ensureSlash}from"@flatjs/common";export const resolvePublicPath=t=>{const{webpack:a}=t;let e="auto";return a?.publicPath&&"auto"!==a.publicPath&&(e=ensureSlash(a.publicPath,!0)),e};
@@ -1 +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[s,n]=t,{projectCwd:a,projectVirtualPath:o}=r;let i=dirname(join(o,e.replace(/^src/,"")));const l=n.entry.map((e=>dirname(join(a,e)))),m=resolve(a,e),c=l.find((e=>m.startsWith(e)));return c&&(i=dirname(join(s,relative(c,m)))),`${i}/[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:t.loaderOptions.assetDataUrlMaxSize}}});
1
+ import{dirname,join,relative,resolve}from"node:path";import{resolvePublicPath}from"../resolve-public-path.js";import{FONT_PATH_REGEX,IMAGE_PATH_REGEX}from"./constants.js";import{isIconSvg}from"./rule-utils.js";const getEntryAssetFileName=(e,t,r)=>{const[s,o]=t,{projectCwd:a,projectVirtualPath:i}=r;let n=dirname(join(i,e.replace(/^src/,"")));const l=o.entry.map((e=>dirname(join(a,e)))),m=resolve(a,e),c=l.find((e=>m.startsWith(e)));return c&&(n=dirname(join(s,relative(c,m)))),`${n}/[name]-[contenthash:8][ext]`};export const ruleAssets=(e,t)=>{const r=resolvePublicPath(t);return{type:"asset",test:e=>FONT_PATH_REGEX.test(e)||IMAGE_PATH_REGEX.test(e)&&!isIconSvg(e),generator:{filename:({filename:r})=>getEntryAssetFileName(r,e,t),publicPath:"auto"===r?void 0:r},parser:{dataUrlCondition:{maxSize:t.loaderOptions.assetDataUrlMaxSize}}}};
@@ -63,11 +63,14 @@ export interface FlatEvolveOptions {
63
63
  /**
64
64
  * Allow us customized to resolve current runtime environment.
65
65
  * ignore resolver if return undefined, otherwise use it to match environment.
66
- * NOTE: Don't using arrow function, because we will inject `envResolver` string to html.
66
+ * NOTE:
67
+ * 1. Don't using arrow function, because we will inject `envResolver` string to html.
68
+ * 2. Don't use multiHtmlCdnEnvResolver(url) {} directly
69
+ * 3. Always use `function` keyword to define `envResolver` function.
67
70
  * @example
68
71
  * ```ts
69
72
  * //
70
- * function envResolver(url) {
73
+ * multiHtmlCdnEnvResolver: function envResolver(url) {
71
74
  * const env = /.*\.(qa|t)\.*\/.exec('//fex.qa.tcshuke.com/')[1];
72
75
  * switch(env) {
73
76
  * case 't':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {