@flatjs/evolve 2.0.9 → 2.0.10
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 +1 @@
|
|
|
1
|
-
import{join}from"node:path";import{
|
|
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,
|
|
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:
|
|
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':
|