@flatjs/evolve 2.0.3 → 2.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,3 +1,4 @@
1
1
  import { type Configuration } from 'webpack';
2
+ import { type EntryMapItem } from '../types/types-entry-map.js';
2
3
  import { type FlatEvolveOptions } from '../types/types-options.js';
3
- export declare const createOutput: (serveMode: boolean, evolveOptions: FlatEvolveOptions) => Promise<Configuration['output']>;
4
+ export declare const createOutput: (serveMode: boolean, evolveOptions: FlatEvolveOptions, entryItem: EntryMapItem) => Promise<Configuration['output']>;
@@ -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)=>{const{projectCwd:a,webpack:n}=t;let o="auto";n?.publicPath&&"auto"!==n.publicPath&&(o=ensureSlash(n.publicPath,!0));const u="function"==typeof n?.outputDir?await n.outputDir():n?.outputDir||"public";return{devtoolModuleFilenameTemplate:({namespace:e,resourcePath:t})=>`webpack:///${join(e,t)}`,environment:{},pathinfo:!1,path:join(a,u),publicPath:o,filename:`[name]/${getBundleFileName("js",e,n?.enableBundleHashName)}`,chunkFilename:"[id].[contenthash].js"}};
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 +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),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,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 +1 @@
1
- export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,pageProxy:"/pages",mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{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},maxProcesses:"50%",ci:{basedBranch:"origin/master"}};
1
+ export const defaultEvolveOptions={projectCwd:process.cwd(),projectVirtualPath:"flatjs/evolve",rejectWarnings:!1,devServer:{autoOpen:!0,pageProxy:"/pages",mockOptions:{mockBaseDir:"mocks"},clientOverlay:{errors:!0,warnings:!1},webSocketURL:"localIp",middlewares:[],watchOptions:{poll:1e3,ignored:["**/node_modules","**/mocks"],aggregateTimeout:500},defaultServeGlobalData:()=>Promise.resolve({})},webpack:{target:["web","es5"],plugins:[],ruleSets:[],publicPath:"auto",resolve:{},externals:{vue:"Vue",react:"React","react-dom":"ReactDOM"},outputDir:"public",enableBundleHashName:!0},pluginOptions:{},loaderOptions:{assetDataUrlMaxSize:4096,babelOptions:{usePreset:"react",plugins:[],presets:[]},runTsChecker:!0,lessOptions:{},postcssOptions:{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},maxProcesses:"50%",ci:{basedBranch:"origin/master"}};
@@ -1 +1 @@
1
- import{join}from"node:path";import WebpackDevServer from"webpack-dev-server";export const addCompilerToDevServer=(e,r,o,t,s)=>{const{projectCwd:p,devServer:i}=s,l=new WebpackDevServer({server:{type:i?.https?"https":"http",options:{...i?.https}},open:!1,compress:!0,port:o,hot:r,liveReload:!r,allowedHosts:"all",static:{directory:`${join(p,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:!0,overlay:i?.clientOverlay,webSocketURL:{hostname:t||void 0}}},e);return new Promise(((e,r)=>{l.startCallback((o=>{if(o)return r(o);e(!0)}))}))};
1
+ import{join}from"node:path";import WebpackDevServer from"webpack-dev-server";export const addCompilerToDevServer=(e,o,r,t,s)=>{const{projectCwd:p,devServer:c}=s,l=new WebpackDevServer({server:{type:c?.https?"https":"http",options:{...c?.https}},open:!1,compress:!0,port:r,hot:o,liveReload:!o,allowedHosts:"all",static:{directory:`${join(p,"/public")}`},headers:{"Access-Control-Allow-Origin":"*"},client:{progress:!0,overlay:c?.clientOverlay,webSocketURL:"localIp"===c?.webSocketURL?{hostname:t||void 0}:{hostname:"0.0.0.0",...c?.webSocketURL}}},e);return new Promise(((e,o)=>{l.startCallback((r=>{if(r)return o(r);e(!0)}))}))};
@@ -1 +1 @@
1
- import{FlatEvolveMultiCdnPlugin}from"./multi-html-cdn-plugin.js";import{createMultiHtmlWebpackPlugin}from"./multi-html-plugin.js";export const createHtmlPlugins=(t,l,u)=>{const i=[];if(t)return i;const n=Object.keys(u.multiHtmlCdn);return i.push(...createMultiHtmlWebpackPlugin(t,u,l,n)),i.push(new FlatEvolveMultiCdnPlugin(u)),i};
1
+ import{FlatEvolveMultiCdnPlugin}from"./multi-html-cdn-plugin.js";import{createMultiHtmlWebpackPlugin}from"./multi-html-plugin.js";export const createHtmlPlugins=(t,l,u)=>{const i=[];if(t||l[1]?.options?.output?.library)return i;const n=Object.keys(u.multiHtmlCdn);return i.push(...createMultiHtmlWebpackPlugin(t,u,l,n)),i.push(new FlatEvolveMultiCdnPlugin(u)),i};
@@ -1,7 +1,7 @@
1
1
  import { type SecureContextHttps, type FlatMockOptions } from '@flatjs/mock';
2
2
  import { type RequestHandler } from 'express';
3
3
  import { type Configuration } from 'webpack';
4
- import { type ClientConfiguration } from 'webpack-dev-server';
4
+ import { type WebSocketURL, type ClientConfiguration } from 'webpack-dev-server';
5
5
  import { type EvolveEntryMapContent } from './types-entry-map.js';
6
6
  export interface WebpackWatchOptions {
7
7
  /**
@@ -58,6 +58,12 @@ export type FlatEvolveDevServerOptions = {
58
58
  * }
59
59
  */
60
60
  clientOverlay?: ClientConfiguration['overlay'];
61
+ /**
62
+ * This option allows specifying URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
63
+ * @example use `localIp` for remote mobile devices HMR it will convert to local ip `ws://10.10.100.3/ws`
64
+ * @example use `{ hostname: '0.0.0.0' }`, will get 'auto://0.0.0.0:0/ws'
65
+ */
66
+ webSocketURL?: WebSocketURL | 'localIp';
61
67
  /**
62
68
  * The customized config options of `flatjs/mock`, it will override options `flatjs-mock.config.ts`
63
69
  */
@@ -1,3 +1,4 @@
1
+ import { type Configuration } from 'webpack';
1
2
  import { type ModuleFederationOptions } from './types-federation.js';
2
3
  import { type MultiHtmlCDNEntryItem } from './types-multi-html.js';
3
4
  /**
@@ -57,6 +58,27 @@ export interface EvolveEntryItemOption extends MultiHtmlCDNEntryItem {
57
58
  * @default undefined
58
59
  */
59
60
  mockFilters?: Array<string | RegExp>;
61
+ /**
62
+ * Extends the default `output` configuration for each entry item.
63
+ * normally we use `output.library` to define the global variable name.
64
+ * @example
65
+ * ```ts
66
+ *'plugin-chart': {
67
+ * entry: [`./src/plugin-chart/index`],
68
+ * options: {
69
+ * output: {
70
+ * library: {
71
+ * name: 'dashboardPluginChart',
72
+ * type: 'var',
73
+ * },
74
+ * libraryTarget: 'window',
75
+ * },
76
+ * },
77
+ * }
78
+ * ```
79
+ * @default undefined
80
+ */
81
+ output?: Configuration['output'];
60
82
  }
61
83
  export type EvolveEntryMapContent = {
62
84
  entry: [string, ...string[]];
@@ -10,7 +10,7 @@ export type EvolveMultiCDNEnvResolver = (url: string) => EvolveMultiCdnEnvType |
10
10
  /**
11
11
  * The html plugin configuration for each entry item
12
12
  */
13
- export declare type MultiHtmlCDNEntryItem = {
13
+ export type MultiHtmlCDNEntryItem = {
14
14
  /**
15
15
  * The title to use for the generated HTML document
16
16
  * @default ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatjs/evolve",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {