@flatjs/evolve 2.1.0-next.5 → 2.1.0-next.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/constants.js +1 -26
- package/dist/create-webpack/create-externals.js +1 -6
- package/dist/create-webpack/create-optimization.js +1 -41
- package/dist/create-webpack/create-output.js +1 -35
- package/dist/create-webpack/create-performance.js +1 -7
- package/dist/create-webpack/create-plugins.js +1 -77
- package/dist/create-webpack/create-resolve.js +1 -37
- package/dist/create-webpack/create-rule-sets.js +1 -19
- package/dist/create-webpack/load-webpack-config.js +1 -56
- package/dist/create-webpack/resolve-public-path.js +1 -15
- package/dist/create-webpack/rule-sets/constants.js +1 -3
- package/dist/create-webpack/rule-sets/rule-assets.js +1 -50
- package/dist/create-webpack/rule-sets/rule-css.js +1 -101
- package/dist/create-webpack/rule-sets/rule-less.js +1 -44
- package/dist/create-webpack/rule-sets/rule-scripts.js +1 -34
- package/dist/create-webpack/rule-sets/rule-svg-icon.js +1 -25
- package/dist/create-webpack/rule-sets/rule-utils.js +1 -10
- package/dist/create-webpack/types.js +1 -1
- package/dist/default-options.js +1 -84
- package/dist/define-config/define-config.js +1 -4
- package/dist/define-config/index.js +1 -1
- package/dist/dev-server/add-compiler-to-dev-server.js +1 -58
- package/dist/dev-server/create-app-page-route.js +1 -13
- package/dist/dev-server/create-dev-server-compiler-tasks.js +1 -52
- package/dist/dev-server/create-dev-server-entries.js +1 -27
- package/dist/dev-server/create-dev-server.js +1 -24
- package/dist/dev-server/index.js +1 -6
- package/dist/dev-server/middlewares/create-page-middleware.js +1 -33
- package/dist/dev-server/middlewares/create-public-assets-middleware.js +1 -25
- package/dist/dev-server/middlewares/get-all-sorted-modules.js +1 -24
- package/dist/dev-server/middlewares/get-bundle-asset.js +1 -7
- package/dist/dev-server/middlewares/get-dev-server-host-uri.js +1 -5
- package/dist/dev-server/middlewares/get-hmr-runtime-chunks.js +1 -14
- package/dist/dev-server/middlewares/get-normalized-entry-name.js +1 -14
- package/dist/dev-server/middlewares/get-page-main-html.js +1 -42
- package/dist/dev-server/middlewares/get-page-module-html.js +1 -120
- package/dist/dev-server/middlewares/get-project-virtual-path.js +1 -3
- package/dist/dev-server/middlewares/get-runtime-manifest.js +1 -25
- package/dist/dev-server/middlewares/index.js +1 -2
- package/dist/dev-server/middlewares/types.js +1 -1
- package/dist/errors/evolve-build-error.js +1 -10
- package/dist/helpers/allow-px2rem-for-module.js +1 -6
- package/dist/helpers/assert-only-single-entry-item.js +1 -23
- package/dist/helpers/chunk-entry-map.js +1 -21
- package/dist/helpers/enable-bundle-hashname-for-module.js +1 -6
- package/dist/helpers/filter-actived-entries.js +1 -42
- package/dist/helpers/get-bundle-file-name.js +1 -23
- package/dist/helpers/get-git-root.js +1 -4
- package/dist/helpers/get-html-plugin-config.js +1 -47
- package/dist/helpers/get-max-process-tasks.js +1 -7
- package/dist/helpers/get-pacakge-dir.js +1 -13
- package/dist/helpers/index.js +1 -17
- package/dist/helpers/json-serializer.js +1 -52
- package/dist/helpers/merge-babel-options.js +1 -45
- package/dist/helpers/normalize-entry-map.js +1 -38
- package/dist/helpers/normalize-page-proxy.js +1 -9
- package/dist/helpers/normalize-resolve-alias.js +1 -7
- package/dist/helpers/open-page.js +1 -15
- package/dist/helpers/print-log.js +1 -49
- package/dist/helpers/refresh-evolve-mock-options.js +1 -34
- package/dist/helpers/resolve-entry-map-input-files.js +1 -20
- package/dist/helpers/script-injects.js +1 -39
- package/dist/helpers/should-enable-react-fast-refresh.js +1 -10
- package/dist/helpers/split-to-multi-compiler.js +1 -32
- package/dist/index.js +1 -5
- package/dist/load-config/index.js +1 -1
- package/dist/load-config/load-evolve-config.js +1 -41
- package/dist/load-config/types.js +1 -1
- package/dist/main/create-thread-worker.js +1 -42
- package/dist/main/env-verify.js +1 -21
- package/dist/main/get-worker-path.js +1 -5
- package/dist/main/index.js +1 -4
- package/dist/main/prepare-build.js +1 -38
- package/dist/main/prepare-serve.js +1 -45
- package/dist/main/prepare-static.js +1 -30
- package/dist/main/start-build-dynamic.js +1 -157
- package/dist/main/start-build-worker.js +1 -46
- package/dist/main/start-build.js +1 -53
- package/dist/main/start-one-entry-build.js +1 -35
- package/dist/main/start-serve.js +1 -34
- package/dist/main/start-static.js +1 -19
- package/dist/minimizer/create-minimizers.js +1 -25
- package/dist/minimizer/default-options.js +1 -14
- package/dist/minimizer/image-minimizer.js +1 -65
- package/dist/minimizer/index.js +1 -1
- package/dist/minimizer/terser-minimizer.js +3 -15
- package/dist/minimizer/types.js +1 -1
- package/dist/plugins/circular-dependency/circular-dependency-plugin.js +1 -119
- package/dist/plugins/circular-dependency/index.js +1 -15
- package/dist/plugins/clean-webpack/clean-webpack-plugin.js +1 -173
- package/dist/plugins/clean-webpack/index.js +1 -22
- package/dist/plugins/define-variable/define-variable-plugin.js +1 -28
- package/dist/plugins/define-variable/index.js +1 -1
- package/dist/plugins/html-inject-scripts/plugin-html-inject-script.js +1 -27
- package/dist/plugins/module-federation/external-template-remotes.js +1 -92
- package/dist/plugins/module-federation/index.js +1 -1
- package/dist/plugins/module-federation/module-federation.js +1 -98
- package/dist/plugins/multi-html/index.js +1 -15
- package/dist/plugins/multi-html/multi-html-cdn-plugin.js +1 -84
- package/dist/plugins/multi-html/multi-html-plugin.js +1 -70
- package/dist/plugins/ts-checker/index.js +1 -1
- package/dist/plugins/ts-checker/ts-checker-plugin.js +1 -18
- package/dist/types/index.js +1 -8
- package/dist/types/types-ci.js +1 -1
- package/dist/types/types-dev-server.js +1 -1
- package/dist/types/types-entry-map.d.ts +2 -2
- package/dist/types/types-entry-map.js +1 -1
- package/dist/types/types-federation.js +1 -1
- package/dist/types/types-loader-options.js +1 -1
- package/dist/types/types-modular-import.js +1 -1
- package/dist/types/types-multi-html.js +1 -1
- package/dist/types/types-options.js +1 -1
- package/dist/types/types-plugin-options.js +1 -1
- package/dist/types/types-webpack.js +1 -1
- package/package.json +2 -2
@@ -1,10 +1 @@
|
|
1
|
-
import
|
2
|
-
/**
|
3
|
-
* Causeof we expose a component <Icon /> from `@wove/react` it can be optimized via icon-loader.
|
4
|
-
* limitation assets match `svg-icons/**\/*.svg` to icon loader resolver.
|
5
|
-
* @param resource
|
6
|
-
* @returns
|
7
|
-
*/
|
8
|
-
export const isIconSvg = (resource) => {
|
9
|
-
return ICON_PATH_REGEX.test(resource) && resource.endsWith('.svg');
|
10
|
-
};
|
1
|
+
import{ICON_PATH_REGEX}from"./constants.js";export const isIconSvg=s=>ICON_PATH_REGEX.test(s)&&s.endsWith(".svg");
|
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export{};
|
package/dist/default-options.js
CHANGED
@@ -1,84 +1 @@
|
|
1
|
-
export const defaultEvolveOptions
|
2
|
-
projectCwd: process.cwd(),
|
3
|
-
projectVirtualPath: 'flatjs/evolve',
|
4
|
-
rejectWarnings: false,
|
5
|
-
devServer: {
|
6
|
-
autoOpen: true,
|
7
|
-
pageProxy: '/pages',
|
8
|
-
mockOptions: {
|
9
|
-
mockBaseDir: 'mocks',
|
10
|
-
},
|
11
|
-
clientOverlay: {
|
12
|
-
errors: true,
|
13
|
-
warnings: false,
|
14
|
-
},
|
15
|
-
webSocketURL: 'localIp',
|
16
|
-
middlewares: [],
|
17
|
-
watchOptions: {
|
18
|
-
poll: 1000,
|
19
|
-
// Use array here, easy can add a new ignore dynamic at runtime.
|
20
|
-
ignored: ['**/node_modules', '**/mocks'],
|
21
|
-
aggregateTimeout: 500,
|
22
|
-
},
|
23
|
-
defaultServeGlobalData: () => Promise.resolve({}),
|
24
|
-
bundleDirResolver: (dir) => dir,
|
25
|
-
},
|
26
|
-
webpack: {
|
27
|
-
// The default is es5
|
28
|
-
target: ['web', 'es5'],
|
29
|
-
plugins: [],
|
30
|
-
ruleSets: [],
|
31
|
-
publicPath: 'auto',
|
32
|
-
resolve: {},
|
33
|
-
externals: {
|
34
|
-
vue: 'Vue',
|
35
|
-
react: 'React',
|
36
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
37
|
-
'react-dom': 'ReactDOM',
|
38
|
-
},
|
39
|
-
outputDir: 'public',
|
40
|
-
enableBundleHashName: true,
|
41
|
-
},
|
42
|
-
pluginOptions: {},
|
43
|
-
loaderOptions: {
|
44
|
-
assetDataUrlMaxSize: 4 * 1024,
|
45
|
-
babelOptions: {
|
46
|
-
// 默认值的必须使用object类型, 如果使用函数, 会导致merge默认值失败.
|
47
|
-
usePreset: 'react',
|
48
|
-
plugins: [],
|
49
|
-
presets: [],
|
50
|
-
},
|
51
|
-
runTsChecker: true,
|
52
|
-
lessOptions: {},
|
53
|
-
postcssOptions: {
|
54
|
-
cssnanoOptions: {},
|
55
|
-
},
|
56
|
-
pixelOptions: {
|
57
|
-
rootValue: { px: 100, rpx: 1 },
|
58
|
-
outputUnit: 'rem',
|
59
|
-
},
|
60
|
-
// Always defined in evolve.config.js
|
61
|
-
modularImports: [],
|
62
|
-
},
|
63
|
-
entryMap: {},
|
64
|
-
// The configurations for plugin `@flatjs/evolve`, `multi-cdn-plugin`
|
65
|
-
multiHtmlCdn: {},
|
66
|
-
// Do not use arrow function here.
|
67
|
-
multiHtmlCdnEnvResolver: function cdnResolver() {
|
68
|
-
return undefined;
|
69
|
-
},
|
70
|
-
needVerifyPackages: {},
|
71
|
-
packageInstallChecker: {
|
72
|
-
enabled: false,
|
73
|
-
detectModules: ['@dimjs/*'],
|
74
|
-
throwError: false,
|
75
|
-
showAllInstalledGraph: true,
|
76
|
-
},
|
77
|
-
maxProcesses: 5,
|
78
|
-
/**
|
79
|
-
* CI default configurations.
|
80
|
-
*/
|
81
|
-
ci: {
|
82
|
-
basedBranch: 'origin/master',
|
83
|
-
},
|
84
|
-
};
|
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({}),bundleDirResolver:e=>e},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:5,ci:{basedBranch:"origin/master"}};
|
@@ -1,4 +1 @@
|
|
1
|
-
import
|
2
|
-
export const defineConfig = (userConfig) => {
|
3
|
-
return myDefineConfig(userConfig);
|
4
|
-
};
|
1
|
+
import{defineConfig as myDefineConfig}from"@armit/config-loader";export const defineConfig=i=>myDefineConfig(i);
|
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export*from"./define-config.js";
|
@@ -1,58 +1 @@
|
|
1
|
-
import { join }
|
2
|
-
import WebpackDevServer from 'webpack-dev-server';
|
3
|
-
/**
|
4
|
-
* Integrated webpack-dev-server with `mock` server together
|
5
|
-
* @param compiler Webpack compiler(s)
|
6
|
-
* @param enabledHmr Value indicates if we need to liveReload or `HMR`
|
7
|
-
* @param devPort The port number of `@flatjs/mock`
|
8
|
-
* @param publicIp The public ip address of local server
|
9
|
-
* @param evolveOptions The configuration of `@flatjs/evolve` (FlatEvolveOptions)
|
10
|
-
*/
|
11
|
-
export const addCompilerToDevServer = (compiler, enabledHmr, devPort, publicIp, evolveOptions) => {
|
12
|
-
const { projectCwd, devServer } = evolveOptions;
|
13
|
-
const server = new WebpackDevServer({
|
14
|
-
server: {
|
15
|
-
type: devServer?.https ? 'https' : 'http',
|
16
|
-
options: {
|
17
|
-
// Load https
|
18
|
-
...devServer?.https,
|
19
|
-
},
|
20
|
-
},
|
21
|
-
open: false,
|
22
|
-
compress: true,
|
23
|
-
port: devPort,
|
24
|
-
hot: enabledHmr,
|
25
|
-
liveReload: !enabledHmr,
|
26
|
-
// Enable firewall or set hosts that are allowed to access the dev server.
|
27
|
-
allowedHosts: 'all',
|
28
|
-
static: {
|
29
|
-
directory: `${join(projectCwd, '/public')}`,
|
30
|
-
},
|
31
|
-
headers: {
|
32
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
33
|
-
'Access-Control-Allow-Origin': '*',
|
34
|
-
},
|
35
|
-
client: {
|
36
|
-
progress: true,
|
37
|
-
overlay: devServer?.clientOverlay,
|
38
|
-
webSocketURL: devServer?.webSocketURL === 'localIp'
|
39
|
-
? {
|
40
|
-
hostname: publicIp || undefined,
|
41
|
-
}
|
42
|
-
: {
|
43
|
-
// always use public ip address cause of charles proxy to mobile devices don't work on `ws://${domain host}:port`
|
44
|
-
// if we use https, we don't need to specify the hostname or specify the https domain address
|
45
|
-
hostname: '0.0.0.0',
|
46
|
-
...devServer?.webSocketURL,
|
47
|
-
},
|
48
|
-
},
|
49
|
-
}, compiler);
|
50
|
-
return new Promise((resolve, reject) => {
|
51
|
-
server.startCallback((err) => {
|
52
|
-
if (err) {
|
53
|
-
return reject(err);
|
54
|
-
}
|
55
|
-
resolve(true);
|
56
|
-
});
|
57
|
-
});
|
58
|
-
};
|
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,13 +1 @@
|
|
1
|
-
import
|
2
|
-
import { createPageMiddleware, createPublicAssetsMiddleware, } from './middlewares/index.js';
|
3
|
-
/**
|
4
|
-
* Add route `/pages`, `*` to main web-server
|
5
|
-
*/
|
6
|
-
export const createAppPageRoute = (projectCwd, app, devHostUri, servedDevServerEntries, evolveOptions) => {
|
7
|
-
const { devServer } = evolveOptions;
|
8
|
-
const pageProxy = normalizePageProxy(devServer?.pageProxy || '/pages');
|
9
|
-
// Attach request handlers for context `/page/*`
|
10
|
-
app.use(pageProxy, ...createPageMiddleware(devHostUri, devServer?.mockOptions?.apiContext || 'api', servedDevServerEntries, evolveOptions));
|
11
|
-
// handle all no-matched page request.
|
12
|
-
app.use('*', createPublicAssetsMiddleware(projectCwd, pageProxy));
|
13
|
-
};
|
1
|
+
import{normalizePageProxy}from"../helpers/normalize-page-proxy.js";import{createPageMiddleware,createPublicAssetsMiddleware}from"./middlewares/index.js";export const createAppPageRoute=(e,r,a,o,i)=>{const{devServer:s}=i,t=normalizePageProxy(s?.pageProxy||"/pages");r.use(t,...createPageMiddleware(a,s?.mockOptions?.apiContext||"api",o,i)),r.use("*",createPublicAssetsMiddleware(e,t))};
|
@@ -1,52 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { chalk, logger, mergeOptions, urlJoin } from '@flatjs/common';
|
3
|
-
import webpack from 'webpack';
|
4
|
-
import { loadWebpackConfig } from '../create-webpack/load-webpack-config.js';
|
5
|
-
import { shouldEnableReactFastRefresh } from '../helpers/should-enable-react-fast-refresh.js';
|
6
|
-
import { splitToMultiCompilerConfigs } from '../helpers/split-to-multi-compiler.js';
|
7
|
-
import { addCompilerToDevServer } from './add-compiler-to-dev-server.js';
|
8
|
-
export const createDevServerCompilerTasks = async (projectCwd, mainPage, publicIp, servedDevServerEntries, evolveOptions) => {
|
9
|
-
const serveTaks = [];
|
10
|
-
for (const [entryName, servedDevServerEntry] of Object.entries(servedDevServerEntries)) {
|
11
|
-
const itemEntryConfig = servedDevServerEntry.entryConfig;
|
12
|
-
const moduleFederation = itemEntryConfig.options?.moduleFederation;
|
13
|
-
const moduleFederationRemotes = moduleFederation?.remotes || [];
|
14
|
-
moduleFederationRemotes.forEach((remote) => {
|
15
|
-
// Dynamic construct remote endpoint as hostUri
|
16
|
-
remote.endpoint = (shortName) => {
|
17
|
-
const servedDevServerEntry = servedDevServerEntries[shortName];
|
18
|
-
if (!servedDevServerEntry) {
|
19
|
-
throw new Error(`No servedDevServerEntry found via "${shortName}"`);
|
20
|
-
}
|
21
|
-
return urlJoin(servedDevServerEntry?.devServerHostUri, ['/public']);
|
22
|
-
};
|
23
|
-
});
|
24
|
-
const { devServerPort, devServerHostUri } = servedDevServerEntries[entryName];
|
25
|
-
const singleEvolveEntryMap = {
|
26
|
-
// e.g. `home`
|
27
|
-
[entryName]: itemEntryConfig,
|
28
|
-
};
|
29
|
-
// e.g. `http://dev.flatjs.com:3002/public/`
|
30
|
-
const servePublicPath = urlJoin(devServerHostUri, ['public']);
|
31
|
-
const webpackConfig = await loadWebpackConfig('development', singleEvolveEntryMap, mergeOptions(evolveOptions, {
|
32
|
-
webpack: {
|
33
|
-
publicPath: servePublicPath,
|
34
|
-
},
|
35
|
-
}));
|
36
|
-
const enabledHmr = shouldEnableReactFastRefresh(true, [entryName, itemEntryConfig], evolveOptions);
|
37
|
-
const compiler = webpack(splitToMultiCompilerConfigs(singleEvolveEntryMap, webpackConfig, evolveOptions, enabledHmr)[0]);
|
38
|
-
// '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
|
39
|
-
serveTaks.push(
|
40
|
-
// create webpack dev server instance.
|
41
|
-
addCompilerToDevServer(compiler, enabledHmr, devServerPort, publicIp, evolveOptions));
|
42
|
-
const title = compiler.name || '';
|
43
|
-
compiler.hooks.invalid.tap('fileChange', (fileName) => {
|
44
|
-
const relativeFileName = relative(projectCwd, fileName || '');
|
45
|
-
logger.info(`file change ➩ ${chalk(['cyan'])(relativeFileName)}`, title);
|
46
|
-
});
|
47
|
-
compiler.hooks.done.tap('compileDone', () => {
|
48
|
-
logger.info(`debug page ➩ ${chalk(['cyan'])(mainPage)}`, title);
|
49
|
-
});
|
50
|
-
}
|
51
|
-
return serveTaks;
|
52
|
-
};
|
1
|
+
import{relative}from"node:path";import{chalk,logger,mergeOptions,urlJoin}from"@flatjs/common";import webpack from"webpack";import{loadWebpackConfig}from"../create-webpack/load-webpack-config.js";import{shouldEnableReactFastRefresh}from"../helpers/should-enable-react-fast-refresh.js";import{splitToMultiCompilerConfigs}from"../helpers/split-to-multi-compiler.js";import{addCompilerToDevServer}from"./add-compiler-to-dev-server.js";export const createDevServerCompilerTasks=async(e,o,r,t,i)=>{const a=[];for(const[n,l]of Object.entries(t)){const s=l.entryConfig,p=s.options?.moduleFederation;(p?.remotes||[]).forEach((e=>{e.endpoint=e=>{const o=t[e];if(!o)throw new Error(`No servedDevServerEntry found via "${e}"`);return urlJoin(o?.devServerHostUri,["/public"])}}));const{devServerPort:c,devServerHostUri:m}=t[n],f={[n]:s},d=urlJoin(m,["public"]),v=await loadWebpackConfig("development",f,mergeOptions(i,{webpack:{publicPath:d}})),h=shouldEnableReactFastRefresh(!0,[n,s],i),g=webpack(splitToMultiCompilerConfigs(f,v,i,h)[0]);a.push(addCompilerToDevServer(g,h,c,r,i));const u=g.name||"";g.hooks.invalid.tap("fileChange",(o=>{const r=relative(e,o||"");logger.info(`file change ➩ ${chalk(["cyan"])(r)}`,u)})),g.hooks.done.tap("compileDone",(()=>{logger.info(`debug page ➩ ${chalk(["cyan"])(o)}`,u)}))}return a};
|
@@ -1,27 +1 @@
|
|
1
|
-
import
|
2
|
-
import { prepareMockDomain } from '@flatjs/mock';
|
3
|
-
import { normalizeEvolveEntryName } from '../helpers/normalize-entry-map.js';
|
4
|
-
export const createDevServerEntries = async (startPort, servedEntries, evolveOptions) => {
|
5
|
-
const { devServer, projectVirtualPath } = evolveOptions;
|
6
|
-
const servedDevServerEntries = {};
|
7
|
-
// https://github.com/webpack/webpack-dev-server/issues/2692
|
8
|
-
// For `webpack-dev-server@4.0.0` we should run dev server on each compiler
|
9
|
-
let makeLastestPort = startPort;
|
10
|
-
// Prepare devServer ports for each served entry.
|
11
|
-
for (const [entryName, entryConfig] of Object.entries(servedEntries)) {
|
12
|
-
makeLastestPort = makeLastestPort + 1;
|
13
|
-
// Create individual devPort for each compiler here.
|
14
|
-
const { mockPort: devServerPort, hostUri: devServerHostUri } = await prepareMockDomain(mergeOptions(devServer?.mockOptions || {}, {
|
15
|
-
port: makeLastestPort,
|
16
|
-
}));
|
17
|
-
// entryName: `home` should be normallized to ${`projectVirtualPath`}/home
|
18
|
-
const normalizedEntryName = normalizeEvolveEntryName(entryName, projectVirtualPath);
|
19
|
-
servedDevServerEntries[entryName] = {
|
20
|
-
entryConfig,
|
21
|
-
devServerPort,
|
22
|
-
devServerHostUri,
|
23
|
-
normalizedEntryName,
|
24
|
-
};
|
25
|
-
}
|
26
|
-
return servedDevServerEntries;
|
27
|
-
};
|
1
|
+
import{mergeOptions}from"@flatjs/common";import{prepareMockDomain}from"@flatjs/mock";import{normalizeEvolveEntryName}from"../helpers/normalize-entry-map.js";export const createDevServerEntries=async(r,e,o)=>{const{devServer:t,projectVirtualPath:n}=o,m={};let a=r;for(const[r,o]of Object.entries(e)){a+=1;const{mockPort:e,hostUri:i}=await prepareMockDomain(mergeOptions(t?.mockOptions||{},{port:a})),s=normalizeEvolveEntryName(r,n);m[r]={entryConfig:o,devServerPort:e,devServerHostUri:i,normalizedEntryName:s}}return m};
|
@@ -1,24 +1 @@
|
|
1
|
-
import https from
|
2
|
-
import { prepareMockDomain } from '@flatjs/mock';
|
3
|
-
import express from 'express';
|
4
|
-
export const createDevServer = async (evolveOptions) => {
|
5
|
-
const app = express();
|
6
|
-
const mockOptions = evolveOptions.devServer?.mockOptions;
|
7
|
-
const { mockPort, hostUri, publicIp } = await prepareMockDomain(mockOptions || {});
|
8
|
-
return new Promise((resolve) => {
|
9
|
-
// Https
|
10
|
-
const httpsServer = evolveOptions.devServer?.https
|
11
|
-
? https.createServer(evolveOptions.devServer?.https, app)
|
12
|
-
: app;
|
13
|
-
// Attach hostUri to application instance without last slash `/`.
|
14
|
-
app.set('hostUri', hostUri);
|
15
|
-
httpsServer.listen(mockPort, () => {
|
16
|
-
resolve({
|
17
|
-
app,
|
18
|
-
publicIp,
|
19
|
-
devHostUri: hostUri,
|
20
|
-
devPort: mockPort,
|
21
|
-
});
|
22
|
-
});
|
23
|
-
});
|
24
|
-
};
|
1
|
+
import https from"node:https";import{prepareMockDomain}from"@flatjs/mock";import express from"express";export const createDevServer=async e=>{const r=express(),t=e.devServer?.mockOptions,{mockPort:o,hostUri:p,publicIp:s}=await prepareMockDomain(t||{});return new Promise((t=>{const i=e.devServer?.https?https.createServer(e.devServer?.https,r):r;r.set("hostUri",p),i.listen(o,(()=>{t({app:r,publicIp:s,devHostUri:p,devPort:o})}))}))};
|
package/dist/dev-server/index.js
CHANGED
@@ -1,6 +1 @@
|
|
1
|
-
export
|
2
|
-
export * from './add-compiler-to-dev-server.js';
|
3
|
-
export * from './create-dev-server.js';
|
4
|
-
export * from './create-app-page-route.js';
|
5
|
-
export * from './create-dev-server-entries.js';
|
6
|
-
export * from './create-dev-server-compiler-tasks.js';
|
1
|
+
export*from"./middlewares/index.js";export*from"./add-compiler-to-dev-server.js";export*from"./create-dev-server.js";export*from"./create-app-page-route.js";export*from"./create-dev-server-entries.js";export*from"./create-dev-server-compiler-tasks.js";
|
@@ -1,33 +1 @@
|
|
1
|
-
import
|
2
|
-
import { getPageModuleHtml } from './get-page-module-html.js';
|
3
|
-
import { getRuntimeManifest } from './get-runtime-manifest.js';
|
4
|
-
/**
|
5
|
-
* A middleware to proxy the page modules template.
|
6
|
-
* @example `http://dev.flatjs.com:3001/pages`
|
7
|
-
* @param mode The mode of this dev server instance.
|
8
|
-
* @param hostUri The main host base url.
|
9
|
-
* @param apiContext apiBase e.g. `api`
|
10
|
-
* @param servedDevServerEntries The served webpack entries
|
11
|
-
* @param forPageMiddlewares Allow us provider customized middlewares for `page`, `modules`
|
12
|
-
* @param evolveOptions The evolve config options
|
13
|
-
*/
|
14
|
-
export const createPageMiddleware = (devHostUri, apiContext, servedDevServerEntries, evolveOptions) => {
|
15
|
-
const handler = async (req, res) => {
|
16
|
-
let html;
|
17
|
-
// Expose a special runtime manifest.json for other system to intergration
|
18
|
-
if (req.path === '/runtime/manifest.json') {
|
19
|
-
const jsonManifest = await getRuntimeManifest(servedDevServerEntries, devHostUri, evolveOptions);
|
20
|
-
return res.json(jsonManifest);
|
21
|
-
}
|
22
|
-
// For root main page
|
23
|
-
if (req.path === '/') {
|
24
|
-
html = await getPageMainHtml(servedDevServerEntries, devHostUri, evolveOptions);
|
25
|
-
}
|
26
|
-
else {
|
27
|
-
// For serve page modules
|
28
|
-
html = await getPageModuleHtml(servedDevServerEntries, req, devHostUri, apiContext, evolveOptions);
|
29
|
-
}
|
30
|
-
res.send(html);
|
31
|
-
};
|
32
|
-
return (evolveOptions.devServer?.middlewares || []).concat(handler);
|
33
|
-
};
|
1
|
+
import{getPageMainHtml}from"./get-page-main-html.js";import{getPageModuleHtml}from"./get-page-module-html.js";import{getRuntimeManifest}from"./get-runtime-manifest.js";export const createPageMiddleware=(e,t,a,m)=>(m.devServer?.middlewares||[]).concat((async(i,n)=>{let g;if("/runtime/manifest.json"===i.path){const t=await getRuntimeManifest(a,e,m);return n.json(t)}g="/"===i.path?await getPageMainHtml(a,e,m):await getPageModuleHtml(a,i,e,t,m),n.send(g)}));
|
@@ -1,25 +1 @@
|
|
1
|
-
import
|
2
|
-
import { fileWalk } from '@armit/file-utility';
|
3
|
-
export const createPublicAssetsMiddleware = (projectCwd, pageProxy) => async (req, res) => {
|
4
|
-
const baseUrl = req.baseUrl;
|
5
|
-
// exclude `/public` leave it fallback into webpack hot server
|
6
|
-
if (!baseUrl.startsWith('/public')) {
|
7
|
-
res.redirect(pageProxy);
|
8
|
-
}
|
9
|
-
else {
|
10
|
-
const publicFiles = await fileWalk(join('public/', '**/*.{js,css}'), {
|
11
|
-
cwd: projectCwd,
|
12
|
-
});
|
13
|
-
const extension = extname(baseUrl);
|
14
|
-
const matchedBundleFile = publicFiles.find((file) => {
|
15
|
-
return (extname(file) === extension &&
|
16
|
-
file.indexOf(baseUrl.replace(/\.(?:js|css)$/, '')) !== -1);
|
17
|
-
});
|
18
|
-
if (matchedBundleFile) {
|
19
|
-
res.sendFile(matchedBundleFile);
|
20
|
-
}
|
21
|
-
else {
|
22
|
-
res.sendFile(join(projectCwd, baseUrl));
|
23
|
-
}
|
24
|
-
}
|
25
|
-
};
|
1
|
+
import{extname,join}from"node:path";import{fileWalk}from"@armit/file-utility";export const createPublicAssetsMiddleware=(e,i)=>async(t,s)=>{const a=t.baseUrl;if(a.startsWith("/public")){const i=await fileWalk(join("public/","**/*.{js,css}"),{cwd:e}),t=extname(a),l=i.find((e=>extname(e)===t&&-1!==e.indexOf(a.replace(/\.(?:js|css)$/,""))));l?s.sendFile(l):s.sendFile(join(e,a))}else s.redirect(i)};
|
@@ -1,24 +1 @@
|
|
1
|
-
import
|
2
|
-
import { getNormalizedEntryName } from './get-normalized-entry-name.js';
|
3
|
-
import { getProjectVirtualPath } from './get-project-virtual-path.js';
|
4
|
-
export function getSortedModules(evolveOptions, servedDevServerEntries, devHostUri) {
|
5
|
-
const sortedModules = [];
|
6
|
-
const projectVirtualPath = getProjectVirtualPath(evolveOptions);
|
7
|
-
for (const [entryName, entryContent] of Object.entries(evolveOptions.entryMap)) {
|
8
|
-
// `home`, servedDevServerEntries[key] => `home`
|
9
|
-
const isServedEntry = Object.keys(servedDevServerEntries).includes(entryName);
|
10
|
-
const devServerHostUri = getDevServerHostUri(servedDevServerEntries, entryName, devHostUri);
|
11
|
-
// `flatjs/evolve/home`
|
12
|
-
const normalizedEntryName = getNormalizedEntryName(entryName, projectVirtualPath, servedDevServerEntries, evolveOptions.devServer);
|
13
|
-
sortedModules.push({
|
14
|
-
entryName,
|
15
|
-
entryContent,
|
16
|
-
devHostUri,
|
17
|
-
devServerHostUri,
|
18
|
-
normalizedEntryName,
|
19
|
-
projectVirtualPath,
|
20
|
-
isServedEntry,
|
21
|
-
});
|
22
|
-
}
|
23
|
-
return sortedModules;
|
24
|
-
}
|
1
|
+
import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";import{getProjectVirtualPath}from"./get-project-virtual-path.js";export function getSortedModules(e,t,r){const o=[],n=getProjectVirtualPath(e);for(const[i,a]of Object.entries(e.entryMap)){const s=Object.keys(t).includes(i),m=getDevServerHostUri(t,i,r),v=getNormalizedEntryName(i,n,t,e.devServer);o.push({entryName:i,entryContent:a,devHostUri:r,devServerHostUri:m,normalizedEntryName:v,projectVirtualPath:n,isServedEntry:s})}return o}
|
@@ -1,7 +1 @@
|
|
1
|
-
import
|
2
|
-
import { urlJoin } from '@flatjs/common';
|
3
|
-
export const getBundleAsset = (devServerHostUri, normalizedCurrEntry, extension) => {
|
4
|
-
return urlJoin(devServerHostUri, [
|
5
|
-
join('public', normalizedCurrEntry, `bundle${extension}`),
|
6
|
-
]);
|
7
|
-
};
|
1
|
+
import{join}from"node:path/posix";import{urlJoin}from"@flatjs/common";export const getBundleAsset=(o,n,i)=>urlJoin(o,[join("public",n,`bundle${i}`)]);
|
@@ -1,5 +1 @@
|
|
1
|
-
export function getDevServerHostUri(
|
2
|
-
const currDevServerEntry = servedDevServerEntries[currEntry];
|
3
|
-
// Maybe No currEntry found in servedDevServerEntries, use default `hostUri`, e.g. `static` mode.
|
4
|
-
return currDevServerEntry?.devServerHostUri || devHostUri;
|
5
|
-
}
|
1
|
+
export function getDevServerHostUri(e,r,t){const o=e[r];return o?.devServerHostUri||t}
|
@@ -1,14 +1 @@
|
|
1
|
-
import
|
2
|
-
import { devReactFastRefresh } from '../../constants.js';
|
3
|
-
import { shouldEnableReactFastRefresh } from '../../helpers/should-enable-react-fast-refresh.js';
|
4
|
-
import { getBundleAsset } from './get-bundle-asset.js';
|
5
|
-
export function getHmrRuntimeChunks(servedDevServerEntries, entryName, normalizedCurrEntry, currEntryItem, evolveOptions, devServerHostUri) {
|
6
|
-
const enabledHmr = servedDevServerEntries[entryName] &&
|
7
|
-
shouldEnableReactFastRefresh(true, [normalizedCurrEntry, currEntryItem], evolveOptions);
|
8
|
-
if (enabledHmr) {
|
9
|
-
const runtimeAsset = getBundleAsset(devServerHostUri, join(normalizedCurrEntry, devReactFastRefresh.runtime), '.js');
|
10
|
-
const reactRefreshSetup = getBundleAsset(devServerHostUri, join(normalizedCurrEntry, devReactFastRefresh.reactRefreshSetup), '.js');
|
11
|
-
return [runtimeAsset, reactRefreshSetup];
|
12
|
-
}
|
13
|
-
return [];
|
14
|
-
}
|
1
|
+
import{join}from"node:path";import{devReactFastRefresh}from"../../constants.js";import{shouldEnableReactFastRefresh}from"../../helpers/should-enable-react-fast-refresh.js";import{getBundleAsset}from"./get-bundle-asset.js";export function getHmrRuntimeChunks(e,t,s,r,n,a){if(e[t]&&shouldEnableReactFastRefresh(!0,[s,r],n)){return[getBundleAsset(a,join(s,devReactFastRefresh.runtime),".js"),getBundleAsset(a,join(s,devReactFastRefresh.reactRefreshSetup),".js")]}return[]}
|
@@ -1,14 +1 @@
|
|
1
|
-
import
|
2
|
-
export function getNormalizedEntryName(entryName, projectVirtualPath, servedDevServerEntries, devServer) {
|
3
|
-
let normalizedEntryName = normalizeEvolveEntryName(entryName, projectVirtualPath);
|
4
|
-
// Check if we have customized dir resolver
|
5
|
-
if (devServer?.bundleDirResolver) {
|
6
|
-
const isServedEntry = Object.keys(servedDevServerEntries).includes(entryName);
|
7
|
-
normalizedEntryName = devServer?.bundleDirResolver(normalizedEntryName, {
|
8
|
-
currEntry: entryName,
|
9
|
-
projectVirtualPath,
|
10
|
-
isServedModule: isServedEntry,
|
11
|
-
});
|
12
|
-
}
|
13
|
-
return normalizedEntryName;
|
14
|
-
}
|
1
|
+
import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";export function getNormalizedEntryName(e,r,t,l){let n=normalizeEvolveEntryName(e,r);if(l?.bundleDirResolver){const o=Object.keys(t).includes(e);n=l?.bundleDirResolver(n,{currEntry:e,projectVirtualPath:r,isServedModule:o})}return n}
|
@@ -1,42 +1 @@
|
|
1
|
-
import { readFileSync }
|
2
|
-
import { join } from 'node:path';
|
3
|
-
import { urlJoin } from '@flatjs/common';
|
4
|
-
import _ from 'lodash';
|
5
|
-
import { getPackageDir } from '../../helpers/get-pacakge-dir.js';
|
6
|
-
import { normalizePageProxy } from '../../helpers/normalize-page-proxy.js';
|
7
|
-
import { getSortedModules, } from './get-all-sorted-modules.js';
|
8
|
-
export const getPageMainHtml = async (servedDevServerEntries, devHostUri, evolveOptions) => {
|
9
|
-
const evolveCwd = getPackageDir();
|
10
|
-
const templateStr = readFileSync(join(evolveCwd, './templates/main.html'), 'utf-8');
|
11
|
-
const sortedModules = getSortedModules(evolveOptions, servedDevServerEntries, devHostUri);
|
12
|
-
const pageProxy = normalizePageProxy(evolveOptions.devServer?.pageProxy || '/pages');
|
13
|
-
const templateModules = sortedModules.map((module) => {
|
14
|
-
const { entryName, entryContent, isServedEntry, projectVirtualPath, normalizedEntryName, } = module;
|
15
|
-
const linkHref = urlJoin(devHostUri, [pageProxy, normalizedEntryName], {
|
16
|
-
env: 'me',
|
17
|
-
});
|
18
|
-
// Allow customized page main link.
|
19
|
-
const servePageMainLinkFn = entryContent.options?.servePageMainLinkFn || ((link) => link);
|
20
|
-
const link = servePageMainLinkFn(linkHref, {
|
21
|
-
hostUri: devHostUri,
|
22
|
-
entryName,
|
23
|
-
virtualPath: projectVirtualPath,
|
24
|
-
});
|
25
|
-
const displayName = entryName
|
26
|
-
.replace(projectVirtualPath, '')
|
27
|
-
.replace(/^\//, '');
|
28
|
-
return {
|
29
|
-
link,
|
30
|
-
name: displayName,
|
31
|
-
flagText: isServedEntry ? 'serve' : 'static',
|
32
|
-
isServed: isServedEntry ? 1 : 0,
|
33
|
-
};
|
34
|
-
});
|
35
|
-
const templateData = {
|
36
|
-
title: '@flatjs/evolve',
|
37
|
-
modules: templateModules.sort((a, b) => {
|
38
|
-
return b.isServed - a.isServed;
|
39
|
-
}),
|
40
|
-
};
|
41
|
-
return _.template(templateStr)(templateData);
|
42
|
-
};
|
1
|
+
import{readFileSync}from"node:fs";import{join}from"node:path";import{urlJoin}from"@flatjs/common";import _ from"lodash";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{getSortedModules}from"./get-all-sorted-modules.js";export const getPageMainHtml=async(e,r,t)=>{const o=getPackageDir(),a=readFileSync(join(o,"./templates/main.html"),"utf-8"),n=getSortedModules(t,e,r),i=normalizePageProxy(t.devServer?.pageProxy||"/pages"),m=n.map((e=>{const{entryName:t,entryContent:o,isServedEntry:a,projectVirtualPath:n,normalizedEntryName:m}=e,s=urlJoin(r,[i,m],{env:"me"}),l=o.options?.servePageMainLinkFn||(e=>e);return{link:l(s,{hostUri:r,entryName:t,virtualPath:n}),name:t.replace(n,"").replace(/^\//,""),flagText:a?"serve":"static",isServed:a?1:0}}));m.push({flagText:"serve",isServed:1,link:urlJoin(r,[i,"/runtime/manifest.json"]),name:"Runtime Manifest"});const s={title:"@flatjs/evolve",modules:m.sort(((e,r)=>r.isServed-e.isServed))};return _.template(a)(s)};
|
@@ -1,120 +1 @@
|
|
1
|
-
import {
|
2
|
-
import { isAbsolute, join } from 'node:path';
|
3
|
-
import { ensureSlash, urlJoin } from '@flatjs/common';
|
4
|
-
import _ from 'lodash';
|
5
|
-
import { allowPx2remForModule } from '../../helpers/allow-px2rem-for-module.js';
|
6
|
-
import { getHtmlPluginConfig, } from '../../helpers/get-html-plugin-config.js';
|
7
|
-
import { getPackageDir } from '../../helpers/get-pacakge-dir.js';
|
8
|
-
import { normalizeEvolveEntryName } from '../../helpers/normalize-entry-map.js';
|
9
|
-
import { normalizePageProxy } from '../../helpers/normalize-page-proxy.js';
|
10
|
-
import { injectFederationScripts } from '../../helpers/script-injects.js';
|
11
|
-
import { getBundleAsset } from './get-bundle-asset.js';
|
12
|
-
import { getDevServerHostUri } from './get-dev-server-host-uri.js';
|
13
|
-
import { getHmrRuntimeChunks } from './get-hmr-runtime-chunks.js';
|
14
|
-
import { getNormalizedEntryName } from './get-normalized-entry-name.js';
|
15
|
-
export const getPageModuleHtml = async (servedDevServerEntries, req, devHostUri, apiContext, evolveOptions
|
16
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
17
|
-
) => {
|
18
|
-
const { entryMap, projectVirtualPath } = evolveOptions;
|
19
|
-
// normalize to ['a/b','a/b/c','inn/app/transfer_list','inn/app/transfer']
|
20
|
-
const entryNames = Object.keys(entryMap).sort((a, b) => b.length - a.length);
|
21
|
-
const evolveCwd = getPackageDir();
|
22
|
-
const currEntryName = entryNames.find((entryName) => {
|
23
|
-
const normalizedEntryName = normalizeEvolveEntryName(entryName, projectVirtualPath);
|
24
|
-
return ensureSlash(req.path.replace(/^\//, ''), true).startsWith(ensureSlash(normalizedEntryName, true));
|
25
|
-
});
|
26
|
-
if (!currEntryName) {
|
27
|
-
const notFoundTemplateStr = readFileSync(join(evolveCwd, `./templates/module-404.html`), 'utf-8');
|
28
|
-
return _.template(notFoundTemplateStr)({
|
29
|
-
title: '404 Not Found',
|
30
|
-
errorMeta: [
|
31
|
-
{
|
32
|
-
name: `@flatjs/evolve workspace`,
|
33
|
-
value: evolveCwd,
|
34
|
-
},
|
35
|
-
{
|
36
|
-
name: `served entry names`,
|
37
|
-
value: JSON.stringify(entryNames),
|
38
|
-
},
|
39
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
40
|
-
{ name: `module path`, value: `${req.path}` },
|
41
|
-
],
|
42
|
-
});
|
43
|
-
}
|
44
|
-
const currEntryItem = entryMap[currEntryName];
|
45
|
-
const currEntryOption = currEntryItem.options;
|
46
|
-
// currEntry: `home`
|
47
|
-
const devServerHostUri = getDevServerHostUri(servedDevServerEntries, currEntryName, devHostUri);
|
48
|
-
const moduleTemplate =
|
49
|
-
// eslint-disable-next-line sonarjs/no-duplicate-string
|
50
|
-
currEntryOption?.serveModuleTemplate || './templates/module.html';
|
51
|
-
const projectHostedModuleTemplate = join(evolveOptions.projectCwd, './templates/module.html');
|
52
|
-
const templateStr = readFileSync(isAbsolute(moduleTemplate)
|
53
|
-
? moduleTemplate
|
54
|
-
: existsSync(projectHostedModuleTemplate)
|
55
|
-
? projectHostedModuleTemplate
|
56
|
-
: join(evolveCwd, './templates/module.html'), 'utf-8');
|
57
|
-
const devServer = evolveOptions.devServer;
|
58
|
-
const defaultGlobalData = devServer?.defaultServeGlobalData
|
59
|
-
? await devServer.defaultServeGlobalData(currEntryItem, devHostUri)
|
60
|
-
: {};
|
61
|
-
const configData = {
|
62
|
-
mode: 'development',
|
63
|
-
// FIXME: always use `devHostUri` as served local `cdn`, if you want to serve `anther` module
|
64
|
-
// you need to generate cdn path manually.
|
65
|
-
envCdn: urlJoin(devHostUri, ['public']),
|
66
|
-
};
|
67
|
-
// Get normalized entry name
|
68
|
-
const normalizedEntryName = getNormalizedEntryName(currEntryName, projectVirtualPath, servedDevServerEntries, devServer);
|
69
|
-
const pageProxy = normalizePageProxy(devServer?.pageProxy || '/pages');
|
70
|
-
const templateData = {
|
71
|
-
// title
|
72
|
-
title: getHtmlPluginConfig('title', configData, currEntryOption?.title),
|
73
|
-
// favicon
|
74
|
-
favicon: getHtmlPluginConfig('favicon', configData, currEntryOption?.favicon),
|
75
|
-
// `allowPx2rem` default is true
|
76
|
-
viewport: allowPx2remForModule([currEntryName, currEntryItem], evolveOptions)
|
77
|
-
? getHtmlPluginConfig('viewport', configData, currEntryOption?.viewport)
|
78
|
-
: '',
|
79
|
-
// The customized html tags should be inject to <header />
|
80
|
-
headBeforeHtmlTags: getHtmlPluginConfig('headBeforeHtmlTags', configData, currEntryOption?.headBeforeHtmlTags),
|
81
|
-
// Allow us customized inline scripts into compiled html template.
|
82
|
-
inlineScripts: getHtmlPluginConfig('inlineScripts', configData, currEntryOption?.inlineScripts),
|
83
|
-
// The ordered styles will be injected start of html head.
|
84
|
-
headBeforeStyles: getHtmlPluginConfig('headBeforeStyles', configData, currEntryOption?.headBeforeStyles),
|
85
|
-
// The ordered scripts will be injected before html head.
|
86
|
-
headBeforeScripts: getHtmlPluginConfig('headBeforeScripts', configData, currEntryOption?.headBeforeScripts),
|
87
|
-
// The ordered scripts will be injected end of html body.
|
88
|
-
bodyAfterScripts: getHtmlPluginConfig('bodyAfterScripts', configData, currEntryOption?.bodyAfterScripts),
|
89
|
-
// Module Federation, Only for `static` mode, `serve` mode it will use entryItemConfig.endpoint()
|
90
|
-
moduleFederationScripts: injectFederationScripts({
|
91
|
-
me: [urlJoin(devHostUri, ['public'])],
|
92
|
-
}, evolveOptions.multiHtmlCdnEnvResolver),
|
93
|
-
// The global data.
|
94
|
-
global: {
|
95
|
-
hostUrl: devHostUri,
|
96
|
-
apiBase: urlJoin(devHostUri, [apiContext]),
|
97
|
-
virtualPath: join(pageProxy, projectVirtualPath),
|
98
|
-
moduleName: currEntryName
|
99
|
-
.replace(projectVirtualPath, '')
|
100
|
-
.replace(/^\//, ''),
|
101
|
-
...defaultGlobalData,
|
102
|
-
...(currEntryOption?.serveGlobalData || {}),
|
103
|
-
},
|
104
|
-
styles: [getBundleAsset(devServerHostUri, normalizedEntryName, '.css')],
|
105
|
-
scripts: [getBundleAsset(devServerHostUri, normalizedEntryName, '.js')],
|
106
|
-
};
|
107
|
-
if (!templateData.headBeforeHtmlTags) {
|
108
|
-
templateData.headBeforeHtmlTags = [];
|
109
|
-
}
|
110
|
-
else {
|
111
|
-
// Avoid deep object reference here.
|
112
|
-
templateData.headBeforeHtmlTags = templateData.headBeforeHtmlTags.slice(0);
|
113
|
-
}
|
114
|
-
// Indicates current we use `hot` mode for `webpack-dev-server` hot reload true.
|
115
|
-
const devRuntimeChunks = getHmrRuntimeChunks(servedDevServerEntries, currEntryName, normalizedEntryName, currEntryItem, evolveOptions, devServerHostUri);
|
116
|
-
devRuntimeChunks.forEach((runtimeChunk) => {
|
117
|
-
templateData.headBeforeHtmlTags?.push(`<script src="${runtimeChunk}"></script>`);
|
118
|
-
});
|
119
|
-
return _.template(templateStr)(templateData);
|
120
|
-
};
|
1
|
+
import{existsSync,readFileSync}from"node:fs";import{isAbsolute,join}from"node:path";import{ensureSlash,urlJoin}from"@flatjs/common";import _ from"lodash";import{allowPx2remForModule}from"../../helpers/allow-px2rem-for-module.js";import{getHtmlPluginConfig}from"../../helpers/get-html-plugin-config.js";import{getPackageDir}from"../../helpers/get-pacakge-dir.js";import{normalizeEvolveEntryName}from"../../helpers/normalize-entry-map.js";import{normalizePageProxy}from"../../helpers/normalize-page-proxy.js";import{injectFederationScripts}from"../../helpers/script-injects.js";import{getBundleAsset}from"./get-bundle-asset.js";import{getDevServerHostUri}from"./get-dev-server-host-uri.js";import{getHmrRuntimeChunks}from"./get-hmr-runtime-chunks.js";import{getNormalizedEntryName}from"./get-normalized-entry-name.js";export const getPageModuleHtml=async(e,t,r,o,l)=>{const{entryMap:i,projectVirtualPath:a}=l,s=Object.keys(i).sort(((e,t)=>t.length-e.length)),n=getPackageDir(),m=s.find((e=>{const r=normalizeEvolveEntryName(e,a);return ensureSlash(t.path.replace(/^\//,""),!0).startsWith(ensureSlash(r,!0))}));if(!m){const e=readFileSync(join(n,"./templates/module-404.html"),"utf-8");return _.template(e)({title:"404 Not Found",errorMeta:[{name:"@flatjs/evolve workspace",value:n},{name:"served entry names",value:JSON.stringify(s)},{name:"module path",value:`${t.path}`}]})}const p=i[m],g=p.options,u=getDevServerHostUri(e,m,r),d=g?.serveModuleTemplate||"./templates/module.html",f=join(l.projectCwd,"./templates/module.html"),c=readFileSync(isAbsolute(d)?d:existsSync(f)?f:join(n,"./templates/module.html"),"utf-8"),h=l.devServer,v=h?.defaultServeGlobalData?await h.defaultServeGlobalData(p,r):{},S={mode:"development",envCdn:urlJoin(r,["public"])},y=getNormalizedEntryName(m,a,e,h),j=normalizePageProxy(h?.pageProxy||"/pages"),H={title:getHtmlPluginConfig("title",S,g?.title),favicon:getHtmlPluginConfig("favicon",S,g?.favicon),viewport:allowPx2remForModule([m,p],l)?getHtmlPluginConfig("viewport",S,g?.viewport):"",headBeforeHtmlTags:getHtmlPluginConfig("headBeforeHtmlTags",S,g?.headBeforeHtmlTags),inlineScripts:getHtmlPluginConfig("inlineScripts",S,g?.inlineScripts),headBeforeStyles:getHtmlPluginConfig("headBeforeStyles",S,g?.headBeforeStyles),headBeforeScripts:getHtmlPluginConfig("headBeforeScripts",S,g?.headBeforeScripts),bodyAfterScripts:getHtmlPluginConfig("bodyAfterScripts",S,g?.bodyAfterScripts),moduleFederationScripts:injectFederationScripts({me:[urlJoin(r,["public"])]},l.multiHtmlCdnEnvResolver),global:{hostUrl:r,apiBase:urlJoin(r,[o]),virtualPath:join(j,a),moduleName:m.replace(a,"").replace(/^\//,""),...v,...g?.serveGlobalData||{}},styles:[getBundleAsset(u,y,".css")],scripts:[getBundleAsset(u,y,".js")]};H.headBeforeHtmlTags?H.headBeforeHtmlTags=H.headBeforeHtmlTags.slice(0):H.headBeforeHtmlTags=[];return getHmrRuntimeChunks(e,m,y,p,l,u).forEach((e=>{H.headBeforeHtmlTags?.push(`<script src="${e}"><\/script>`)})),_.template(c)(H)};
|