@flatjs/evolve 2.0.8 → 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}};
@@ -1 +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=async(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:await createPlugins(a,i,r),watchOptions:c,output:await createOutput(a,r,i),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:m},devtool:a?"eval-source-map":s?.sourceMap||!1,externals:createExternals(s?.externals,i),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,r,i),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
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=async(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:await createPlugins(a,i,r),watchOptions:c,output:await createOutput(a,r,i),context:o,target:s?.target??["web","es5"],resolve:createResolve(o,s),module:{rules:m},devtool:a?"eval-source-map":s?.sourceMap||!1,externalsType:s?.externalsType,externals:createExternals(s?.externals,i),performance:createPerformance(a,s?.performance),optimization:createOptimization(a,r,i),infrastructureLogging:s?.infrastructureLogging??{level:"warn"},stats:s?.stats??{preset:"minimal"},cache:{type:"memory"}}};
@@ -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':
@@ -27,6 +27,11 @@ export interface FlatEvolveWebpackOptions extends Pick<Configuration, 'performan
27
27
  */
28
28
  alias?: Record<string, string>;
29
29
  };
30
+ /**
31
+ * Specify the default type of externals.
32
+ * @example `externalsType: 'window'`
33
+ */
34
+ externalsType?: Configuration['externalsType'];
30
35
  /**
31
36
  * @default
32
37
  * ```json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {