@moneko/core 3.26.12-beta.0 → 3.26.12-beta.3
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.
- package/lib/build/common.d.mts +0 -1
- package/lib/build/common.mjs +1 -1
- package/lib/dev/mock.d.mts +18 -7
- package/lib/dev/mock.mjs +1 -1
- package/lib/dev/proxy.d.mts +15 -8
- package/lib/dev/proxy.mjs +1 -1
- package/lib/dev.d.mts +17 -14
- package/lib/dev.mjs +1 -1
- package/lib/index.d.mts +1 -0
- package/lib/options/html-plugin-option.d.mts +1 -2
- package/lib/options/html-plugin-option.mjs +1 -11
- package/lib/plugin/html-webpack-plugin.d.mts +41 -0
- package/lib/plugin/html-webpack-plugin.mjs +23 -0
- package/lib/plugins.config.d.mts +1 -1
- package/lib/plugins.config.mjs +1 -1
- package/package.json +7 -9
- package/typings/global.d.ts +2 -52
package/lib/build/common.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
2
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
3
3
|
import webpack, { type Configuration } from 'webpack';
|
|
4
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
5
4
|
import { merge } from 'webpack-merge';
|
|
6
5
|
import { commonConfig } from '../common.mjs';
|
|
7
6
|
import { CONFIG } from '../config.mjs';
|
package/lib/build/common.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"mini-css-extract-plugin";import i from"terser-webpack-plugin";import n from"webpack";import{
|
|
1
|
+
import e from"mini-css-extract-plugin";import i from"terser-webpack-plugin";import n from"webpack";import{merge as m}from"webpack-merge";import{commonConfig as r}from"../common.mjs";import{CONFIG as t}from"../config.mjs";import{getMinifyOption as s}from"../options/js-minify.mjs";import{LightningCssMinifyPlugin as l}from"../plugin/lightningcss-plugin.mjs";import{getLightningCssTargets as o}from"../polyfills/targets.mjs";let p=[];t.minifier&&(p.push(new i(s(t.minifier.type,t.minifier.options))),p.push(new l({targets:o()})));let a={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...t.performance},u=m(r,{performance:t.performance&&a,plugins:[new e({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",ignoreOrder:!0})],optimization:{splitChunks:t.splitChunk,runtimeChunk:t.runtimeChunk,chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,minimize:!0,minimizer:p}});if(t.splitChunk&&u.plugins?.push(new n.optimize.MinChunkSizePlugin({minChunkSize:51200})),t.bundleAnalyzer){let e=(await import("webpack-bundle-analyzer")).BundleAnalyzerPlugin;u.plugins?.push(new e({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...t.bundleAnalyzer}))}export default u;
|
package/lib/dev/mock.d.mts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { print } from '@moneko/utils';
|
|
2
|
+
import { directoryExists, print } from '@moneko/utils';
|
|
3
3
|
import { watch } from 'chokidar';
|
|
4
|
-
import
|
|
4
|
+
import type { FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify';
|
|
5
5
|
import { merge } from 'webpack-merge';
|
|
6
6
|
import log from '../commom/log.mjs';
|
|
7
7
|
import matchPath from '../commom/match-path.mjs';
|
|
8
8
|
import require from '../commom/require.mjs';
|
|
9
9
|
import { jsonSchema } from './json-schema.mjs';
|
|
10
|
-
export interface RequestFormData extends
|
|
11
|
-
files
|
|
10
|
+
export interface RequestFormData extends FastifyRequest {
|
|
11
|
+
files?: {
|
|
12
|
+
fieldname: string;
|
|
13
|
+
originalname: string;
|
|
14
|
+
encoding: string;
|
|
15
|
+
mimetype: string;
|
|
16
|
+
buffer: Buffer;
|
|
17
|
+
size: number;
|
|
18
|
+
}[];
|
|
19
|
+
params: Record<string, string>;
|
|
12
20
|
}
|
|
13
|
-
export type ProxyFuncType = (req:
|
|
21
|
+
export type ProxyFuncType = (req: FastifyRequest, reply: FastifyReply, done: () => void) => void | Promise<void>;
|
|
14
22
|
export type MockConfiguration = Record<string, ProxyFuncType | Record<string, any> | null>;
|
|
15
23
|
declare function clearProxy(iproxy: MockConfiguration, path: string, old: MockConfiguration);
|
|
16
24
|
export type YApiOptionBySchema = {
|
|
@@ -26,5 +34,8 @@ export type YApiOption = {
|
|
|
26
34
|
pathRewrite: string;
|
|
27
35
|
};
|
|
28
36
|
export declare const yApiMock: (req: RequestFormData, yapi: YApiOption) => Promise<Any>;
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
export interface MockPluginOptions {
|
|
38
|
+
directory: string;
|
|
39
|
+
}
|
|
40
|
+
declare const setupMock: FastifyPluginAsync<MockPluginOptions>;
|
|
41
|
+
export default setupMock;
|
package/lib/dev/mock.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:http";import{print as
|
|
1
|
+
import e from"node:http";import{directoryExists as t,print as o}from"@moneko/utils";import{watch as r}from"chokidar";import{merge as a}from"webpack-merge";import n from"../commom/log.mjs";import s from"../commom/match-path.mjs";import c from"../commom/require.mjs";import{jsonSchema as m}from"./json-schema.mjs";function i(e,t,o){if(delete c.cache[t],o[t]){for(let r in o[t])Object.prototype.hasOwnProperty.call(o[t],r)&&(e[r]=null,delete e[r]);o[t]=null,delete o[t]}}export const yApiSchemaMock=(t,o)=>new Promise(r=>{e.get(`${t.host}/api/interface/get?id=${t.id}&token=${t.token}`,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{let e=JSON.parse(t);if(e?.data?.res_body_is_json_schema){let t=JSON.parse(e.data.res_body),n=m(t);void 0!==o?r(a(n,o)):r(n)}}catch(e){n(e)}})})});export const yApiMock=(t,o)=>new Promise((r,a)=>{let s=new URL(o.host),c={hostname:s.hostname,port:s.port,path:t.url.replace(new RegExp(o.pathRewrite),`/mock/${o.projectId}/`),method:t.method,headers:t.headers,query:t.query},m=e.request(c,e=>{e.setEncoding("utf8");let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{try{r(JSON.parse(t))}catch(e){n(e)}})});m.on("error",e=>{a(e.message)}),m.write(JSON.stringify(t.body)),m.end()});let p=async(e,a)=>{if(!t(a.directory))return;let m={},p={};r(a.directory).on("all",async function(e,t){if("string"==typeof t){switch(o("Updating mock...",!0),e){case"add":case"change":try{i(p,t,m);let e=c(t).default;m[t]=e,p=Object.assign(p,e)}catch(e){n(e)}break;case"unlink":i(p,t,m)}o("Mock update successful",!0)}}),e.addHook("preHandler",(e,t,o)=>{let r=`${e.method} ${e.url}`,a=Object.keys(p).filter(function(e){return RegExp(`^${e.replace(/(:\w*)[^/]/g,"((?!/).)")}*$`).test(r)});if(p[r]||a&&a.length>0){let n=p[r]||p[a[0]];if("function"==typeof n){let r=s(a[0].split(" ")[1],e.url);r&&e.params&&"object"==typeof e.params&&Object.assign(e.params,r.params),n(e,t,o);return}t.send(n);return}o()})};export default p;
|
package/lib/dev/proxy.d.mts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
2
|
+
import httpProxy from '@fastify/http-proxy';
|
|
3
|
+
import type { FastifyInstance } from 'fastify';
|
|
4
|
+
import { empty } from '../utils/index.mjs';
|
|
5
|
+
type ProxyItem = {
|
|
6
|
+
target: string;
|
|
7
|
+
changeOrigin?: boolean;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
ws?: boolean;
|
|
10
|
+
pathRewrite?: Record<string, string>;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export type ProxyConfig = Record<string, string | ProxyItem>;
|
|
14
|
+
declare const registeredProxies: Set<string>;
|
|
15
|
+
export declare async function setupProxy(app: FastifyInstance, proxyConfig?: ProxyConfig);
|
package/lib/dev/proxy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"@fastify/http-proxy";import{empty as t}from"../utils/index.mjs";let r=new Set;export async function setupProxy(s,i){for(let e of r)s.all(`${e}*`,t);if(r.clear(),i)for(let[t,o]of Object.entries(i)){let i="string"==typeof o?{upstream:o}:{upstream:o.target,websocket:o.ws,rewritePrefix:Object.entries(o.pathRewrite||{}).reduce((e,[t,r])=>e.replace(new RegExp(t),r),t),replyOptions:{rewriteRequestHeaders:(e,t)=>({...t,...o.headers,host:new URL(o.target).host})}};s.register(e,{prefix:t,...i}),r.add(t)}}
|
package/lib/dev.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { exec, spawn } from 'node:child_process';
|
|
2
2
|
import { watchFile } from 'node:fs';
|
|
3
|
-
import type { IncomingMessage
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import multer, { type Multer } from 'multer';
|
|
3
|
+
import type { IncomingMessage } from 'node:http';
|
|
4
|
+
import compress from '@fastify/compress';
|
|
5
|
+
import { fastifyMiddie } from '@fastify/middie';
|
|
6
|
+
import { ink, loadFile, print, println, progressBar } from '@moneko/utils';
|
|
7
|
+
import fastify, { FastifyInstance } from 'fastify';
|
|
9
8
|
import webpack, { type WebpackPluginInstance } from 'webpack';
|
|
10
9
|
import middleware from 'webpack-dev-middleware';
|
|
11
10
|
import webpackHotMiddleware, { type ClientOptions } from 'webpack-hot-middleware';
|
|
@@ -13,10 +12,11 @@ import { merge } from 'webpack-merge';
|
|
|
13
12
|
import { diffObject } from './commom/diff-object.mjs';
|
|
14
13
|
import hasPkg from './commom/has-pkg.mjs';
|
|
15
14
|
import paths, { config_files } from './commom/paths.mjs';
|
|
15
|
+
import Rule from './commom/rule.mjs';
|
|
16
16
|
import sigintExit from './commom/sigint-exit.mjs';
|
|
17
17
|
import { devLog, PORT } from './dev/config.mjs';
|
|
18
|
-
import
|
|
19
|
-
import
|
|
18
|
+
import setupMock from './dev/mock.mjs';
|
|
19
|
+
import { type ProxyConfig, setupProxy } from './dev/proxy.mjs';
|
|
20
20
|
import reslove from './options/reslove.mjs';
|
|
21
21
|
import { empty, resolveProgram } from './utils/index.mjs';
|
|
22
22
|
import { commonConfig } from './common.mjs';
|
|
@@ -39,15 +39,18 @@ declare const bar: ConfigType['bar'];
|
|
|
39
39
|
declare const bar_name: string;
|
|
40
40
|
declare const clientOption: webpack.Configuration;
|
|
41
41
|
declare const compilers: webpack.Compiler;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
interface FastifyOptions {
|
|
43
|
+
http2?: boolean;
|
|
44
|
+
https?: {
|
|
45
|
+
key: string;
|
|
46
|
+
cert: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
declare const fastifyOptions: FastifyOptions;
|
|
45
50
|
declare const devMiddleware: middleware.API<IncomingMessage, middleware.ServerResponse>;
|
|
46
51
|
declare const hotMiddleware: ReturnType<typeof webpackHotMiddleware>;
|
|
52
|
+
declare const app: FastifyInstance;
|
|
47
53
|
declare const baseHtml: string;
|
|
48
|
-
declare let httpsServer: HttpsServer | undefined;
|
|
49
|
-
type Listen = HttpsServer<typeof IncomingMessage, typeof ServerResponse> | HttpServer<typeof IncomingMessage, typeof ServerResponse>;
|
|
50
|
-
declare const listen: Listen;
|
|
51
54
|
declare function exit();
|
|
52
55
|
declare const _prev: ConfigType[];
|
|
53
56
|
declare let prev: ConfigType;
|
package/lib/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{exec as e,spawn as t}from"node:child_process";import{watchFile as o}from"node:fs";import r from"@fastify/compress";import{fastifyMiddie as i}from"@fastify/middie";import{ink as s,loadFile as l,print as n,println as a,progressBar as m}from"@moneko/utils";import c from"fastify";import p from"webpack";import d from"webpack-dev-middleware";import u from"webpack-hot-middleware";import{merge as f}from"webpack-merge";import{diffObject as h}from"./commom/diff-object.mjs";import g from"./commom/has-pkg.mjs";import w,{config_files as y}from"./commom/paths.mjs";import x from"./commom/rule.mjs";import v from"./commom/sigint-exit.mjs";import{devLog as k,PORT as $}from"./dev/config.mjs";import j from"./dev/mock.mjs";import{setupProxy as b}from"./dev/proxy.mjs";import C from"./options/reslove.mjs";import{empty as P,resolveProgram as S}from"./utils/index.mjs";import{commonConfig as A}from"./common.mjs";import{CONFIG as E,getConfig as T,PUBLICPATH as M}from"./config.mjs";import I from"./module.config.mjs";import{isLibrary as _,isReact as O,refresh as R}from"./process-env.mjs";let H=!1!==E.stylelint&&g("stylelint-webpack-plugin")&&(await import("stylelint-webpack-plugin")).default,q=!1!==E.eslint&&g("eslint-webpack-plugin")&&(await import("eslint-webpack-plugin")).default,z=O&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,B=["js","jsx","ts","tsx","json","html","vue"],D=B.join(","),U=["css","scss","sass","less","ts","tsx","js","jsx"],G=U.join(","),L=["node_modules/","es/","lib/","umd/","docs/","coverage/","dist/"],W=`${M.endsWith("/")?"":"/"}__hmr__`,F=new URLSearchParams({name:"client",path:W,dynamicPublicPath:!0,timeout:2e3,reload:!R,quiet:!0,noInfo:!0,overlay:!0,autoConnect:!0}).toString(),N=A.output.path,K=E.bar.name||"Build",X=f(A,{entry:{main:[`${C.hotMiddlewareClient}?${F}`]},output:{path:N},module:I(!1),optimization:{minimize:!1,concatenateModules:!1,removeAvailableModules:!1,removeEmptyChunks:!0,providedExports:!0,usedExports:!1,sideEffects:!1,splitChunks:{chunks:"all",minChunks:1,minSize:30720,maxSize:0,maxAsyncRequests:60,maxInitialRequests:50,hidePathInfo:!1,cacheGroups:{vendors:{test:x.node_modules,priority:-10,reuseExistingChunk:!0},default:{minChunks:1,priority:-20,reuseExistingChunk:!0}}}},plugins:[new p.HotModuleReplacementPlugin,new p.WatchIgnorePlugin({paths:[/node_modules\/(?!(@app|@moneko)).+/,/\.d\.ts$/]}),z&&new z,q&&new q({fix:!0,threads:!0,files:[`${E.alias["@"]}/**/*.{${D}}`,_&&`${E.alias["@pkg"]}/**/*.{${D}}`].filter(Boolean),extensions:B,exclude:L,cache:!0,cacheLocation:`${w.lintCachePath}/.eslintcache`,lintDirtyModulesOnly:!0,overrideConfigFile:S("eslint.config.mjs"),configType:"flat"}),H&&new H({fix:!0,threads:!0,files:[`${E.alias["@"]}/**/*.{${G}}`,_&&`${E.alias["@pkg"]}/**/*.{${G}}`].filter(Boolean),extensions:U,exclude:L,cache:!0,cacheLocation:`${w.lintCachePath}/.stylelintcache`,lintDirtyModulesOnly:!0}),!!E.bar&&new p.ProgressPlugin({handler(e,t,...o){m(e||0,1,K,o.length?`[${t}] ${o.join(" ")}`:""),1===e&&process.stdout.write("\r\x1b[2K")}})].filter(Boolean)}),J=p(X);J.hooks.done.tap("client-log",e=>{k(null,e)});let Q={};if(E.devServer.https){let[e,t]=await Promise.all([l(E.devServer.https.key),l(E.devServer.https.cert)]);e||(a(s(`法加载私钥。请检查路径和文件是否存在,并确保路径正确:${E.devServer.https.key}`,"red")),process.exit(1)),t||(a(s(`无法加载证书。请检查路径和文件是否存在,并确保路径正确:${E.devServer.https.cert}`,"red")),process.exit(1)),Q.http2=!0,Q.https={key:e,cert:t}}let V=d(J,{writeToDisk:!1,index:"index.html",headers:e=>({"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization","Access-Control-Allow-Methods":"GET, POST, OPTIONS, DELETE, PATCH, PUT",...E.devServer.headers,"Access-Control-Allow-Origin":e.headers.origin||"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"}),serverSideRender:!1,lastModified:!0,publicPath:X.output?.publicPath,cacheControl:!1,cacheImmutable:!1}),Y=u(J,{log:!1,path:W,heartbeat:2e3}),Z=c({logger:!1,...Q});await Z.register(i),Z.use(V),Z.use(W,Y),j(Z,{directory:w.mockPath}),b(Z,E.proxy);let ee=`${X.output.path}/index.html`;function et(){process.exit(0)}Z.get("*",async(e,t)=>{if(e.headers.accept?.includes("text/html")){let e=V.context.outputFileSystem,o=e?.readFileSync?.(ee);if(!t.sent){t.type("text/html").send(o);return}}else if(e.url?.endsWith(W)&&"text/event-stream"===e.headers.accept){e.raw.url=W,Y(e.raw,t.raw,P);return}}),Z.addHook("onClose",()=>{V.close(P),Z.server.close(P)}),await Z.register(r,{global:!0}),Z.listen({port:$});let eo=await Promise.all(y.map(T)),er=f(eo[0]||{},eo[1]||{});y.forEach(function(t){o(t,async function(){let[o,r]=await Promise.all(y.map(T)),i=f(o||{},r||{}),l=h(er,i);1===Object.keys(l).length&&"proxy"in l?(n(s(`代理更新中...`,"yellow"),!0),await b(Z,i.proxy),n(s(`代理更新完成...`,"green"),!0),E.proxy=i.proxy,er.proxy=i.proxy,er=i):(er=i,a(s(`检测到工程配置${s(`[${t}]`,"blue")}变更, 程序即将重启...`,"yellow"),!0),e("win32"===process.platform?`netstat -ano | findstr :${$}`:`lsof -i :${$} -t`,(e,t)=>{if(e){a(s(`查找端口 ${$} 时发生错误: ${e.message}`,"red")),a(s("请尝试手动重启程序","yellow"));return}let o=t.trim().split("\n").filter(Boolean),r=ei?o[0]?.split(/\s+/).pop()?.trim():o[0]?.trim();if(!r){a(s(`未找到占用端口 ${$} 的进程, 请尝试手动重启程序`,"yellow"));return}try{process.kill(Number(r),"SIGHUP")}catch(e){a(s(`终止进程 ${r} 时发生错误: ${e.message}`,"red"))}}))})});let ei="win32"===process.platform;process.on("SIGHUP",function(){Z.close(P),function(){let e=t(process.argv[0],process.argv.slice(1),{detached:!1,stdio:"inherit"});e.unref(),e.on("close",et)}()}),process.on("exit",function(){Z.close(P)}),v(et);
|
package/lib/index.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ export { type MockConfiguration, type ProxyFuncType, type RequestFormData, yApiM
|
|
|
9
9
|
export type { ProxyConfig } from './dev/proxy.mjs';
|
|
10
10
|
export { type JsxDomExpressions, default as jsxDomExpressions } from './options/jsx-dom-expressions.mjs';
|
|
11
11
|
export { type OptimizationSplitChunksOptions, default as splitChunk } from './options/split-chunk.mjs';
|
|
12
|
+
export type { HtmlWebpackOption } from './plugin/html-webpack-plugin.mjs';
|
|
12
13
|
export type { OverrideResolverOption } from './plugin/override-resolve.mjs';
|
|
13
14
|
export type { VirtualModulePluginOption } from './plugin/virtual-module.mjs';
|
|
14
15
|
export { APPTYPE, coreName, FRAMEWORK, isDev, isLibrary, isMicro, mainDirectory, PACKAGENAME, PACKAGEVERSION } from './process-env.mjs';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { merge } from 'webpack-merge';
|
|
2
|
-
import type { HtmlWebpackOption } from '../../typings/global.js';
|
|
3
2
|
import { CONFIG } from '../config.mjs';
|
|
3
|
+
import type { HtmlWebpackOption } from '../plugin/html-webpack-plugin.mjs';
|
|
4
4
|
import { coreName, description, keywords, PACKAGENAME } from '../process-env.mjs';
|
|
5
5
|
import { resolveProgram } from '../utils/index.mjs';
|
|
6
6
|
declare const option: HtmlWebpackOption;
|
|
7
7
|
declare const favicon: string | false;
|
|
8
|
-
declare function templateContent({ htmlWebpackPlugin: { options } }: any);
|
|
9
8
|
declare const relCanonical: string | false;
|
|
10
9
|
declare const meta: HtmlWebpackOption['meta'];
|
|
11
10
|
declare const htmlPluginOption: HtmlWebpackOption;
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import{merge as e}from"webpack-merge";import{CONFIG as t}from"../config.mjs";import{coreName as i,description as o,keywords as
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>${e.title}</title>
|
|
5
|
-
${i}
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<div id="root"></div>
|
|
9
|
-
${o}
|
|
10
|
-
</body>
|
|
11
|
-
</html>`}});export default c;
|
|
1
|
+
import{merge as e}from"webpack-merge";import{CONFIG as t}from"../config.mjs";import{coreName as i,description as o,keywords as a,PACKAGENAME as r}from"../process-env.mjs";import{resolveProgram as n}from"../utils/index.mjs";let p=t.htmlPluginOption||{},l=p.favicon??`node_modules/${i}/lib/options/favicon.ico`,m=t.seo&&`https://${t.seo.domain}${t.basename}`,s={charset:"UTF-8","X-UA-Compatible":{"http-equiv":"X-UA-Compatible",content:"IE=edge,Chrome=1"},HandheldFriendly:"true",MobileOptimized:"320","screen-orientation":"portrait","x5-orientation":"portrait",browsermode:"application","x5-page-mode":"app","msapplication-tap-highlight":"no","mobile-web-app-capable":"yes",renderer:"webkit",description:o,keywords:Array.isArray(a)?a.toString():"","http-equiv":"refresh",viewport:"width=device-width, initial-scale=1"};m&&Object.assign(s,{relCanonical:{rel:"canonical",href:m}});let c=e({title:t.env?.PROJECTNAME||r.toLocaleUpperCase()||"Title",filename:"index.html",meta:s,tags:[]},p,{favicon:l?n(l):l},p.template?{template:n(p.template)}:{});export default c;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import webpack, { type Compilation, type Compiler } from 'webpack';
|
|
4
|
+
declare const sources: typeof webpack.sources;
|
|
5
|
+
interface HtmlMeta {
|
|
6
|
+
[key: string]: string | Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface HtmlWebpackOption {
|
|
9
|
+
favicon?: string | false;
|
|
10
|
+
title?: string;
|
|
11
|
+
template?: string;
|
|
12
|
+
filename?: string | ((entryName: string) => string);
|
|
13
|
+
inject?: boolean | 'head' | 'body';
|
|
14
|
+
templateContent?: (options: HtmlWebpackOption) => string;
|
|
15
|
+
tags?: {
|
|
16
|
+
textContent?: string;
|
|
17
|
+
tag?: string;
|
|
18
|
+
inject?: 'body' | 'head';
|
|
19
|
+
[key: string]: string | null | boolean | number | undefined;
|
|
20
|
+
}[];
|
|
21
|
+
meta?: HtmlMeta;
|
|
22
|
+
}
|
|
23
|
+
export declare class SimpleHtmlWebpackPlugin {
|
|
24
|
+
private options: HtmlWebpackOption;
|
|
25
|
+
constructor(options: HtmlWebpackOption = {});
|
|
26
|
+
apply(compiler: Compiler);
|
|
27
|
+
private generateDefaultTemplate(): string;
|
|
28
|
+
private generateMetaTags(): string;
|
|
29
|
+
private generateCustomTags(): {
|
|
30
|
+
head: string;
|
|
31
|
+
body: string;
|
|
32
|
+
};
|
|
33
|
+
private getAssets(compilation: Compilation): {
|
|
34
|
+
js: string[];
|
|
35
|
+
css: string[];
|
|
36
|
+
};
|
|
37
|
+
private injectAssets(templateHtml: string, assets: {
|
|
38
|
+
js: string[];
|
|
39
|
+
css: string[];
|
|
40
|
+
}, inject: boolean | 'head' | 'body'): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import t from"fs";import e from"path";import s from"webpack";let i=s.sources;export class SimpleHtmlWebpackPlugin{constructor(t={}){this.options={title:"Web App",filename:"index.html",inject:"body",...t}}apply(s){s.hooks.emit.tapAsync("SimpleHtmlWebpackPlugin",(o,n)=>{let a;if(this.options.templateContent)a=this.options.templateContent(this.options);else if(this.options.template){let i=e.resolve(s.context,this.options.template);a=t.readFileSync(i,"utf-8")}else a=this.generateDefaultTemplate();if(this.options.inject){let t=this.getAssets(o);a=this.injectAssets(a,t,this.options.inject)}let l="function"==typeof this.options.filename?this.options.filename("index"):this.options.filename||"index.html";o.emitAsset(l,new i.RawSource(a)),n()})}generateDefaultTemplate(){let t=this.generateMetaTags(),e=this.generateCustomTags(),s=this.options.favicon?`<link rel="icon" type="image/x-icon" href="${this.options.favicon}">`:"";return`
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
${t}
|
|
7
|
+
<title>${this.options.title}</title>
|
|
8
|
+
${s}
|
|
9
|
+
${e.head}
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
${e.body}
|
|
14
|
+
</body>
|
|
15
|
+
</html>`}generateMetaTags(){return this.options.meta?Object.entries(this.options.meta).map(([t,e])=>{if("string"==typeof e)return`<meta name="${t}" content="${e}">`;let s=Object.entries(e).map(([t,e])=>`${t}="${e}"`).join(" ");return`<meta ${s}>`}).join("\n"):""}generateCustomTags(){let t={head:"",body:""};return this.options.tags&&this.options.tags.forEach(e=>{let{tag:s="script",textContent:i="",inject:o="body",...n}=e,a=Object.entries(n).filter(([,t])=>null!==t&&!1!==t).map(([t,e])=>!0===e?t:`${t}="${e}"`).join(" "),l=`<${s} ${a}>${i}</${s}>`;"head"===o?t.head+=(t.head?"\n":"")+l:t.body+=(t.body?"\n":"")+l}),t}getAssets(t){let e={js:[],css:[]},s=t.outputOptions.publicPath||"";for(let i of t.entrypoints.values())i.getFiles().forEach(t=>{t.endsWith(".js")?e.js.push(s+t):t.endsWith(".css")&&e.css.push(s+t)});return e}injectAssets(t,e,s){let i=t,o=e.css.map(t=>`<link href="${t}" rel="stylesheet">`).join("\n"),n=e.js.map(t=>`<script src="${t}"></script>`).join("\n"),a=this.generateCustomTags();return"head"===s?(i=i.replace("</head>",`${o}
|
|
16
|
+
${n}
|
|
17
|
+
${a.head}
|
|
18
|
+
</head>`),a.body&&(i=i.replace("</body>",`${a.body}
|
|
19
|
+
</body>`))):(i=i.replace("</body>",`${o}
|
|
20
|
+
${n}
|
|
21
|
+
${a.body}
|
|
22
|
+
</body>`),a.head&&(i=i.replace("</head>",`${a.head}
|
|
23
|
+
</head>`))),i}}
|
package/lib/plugins.config.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
2
1
|
import webpack, { type WebpackPluginInstance } from 'webpack';
|
|
3
2
|
import htmlPluginOption from './options/html-plugin-option.mjs';
|
|
4
3
|
import { AddEntryAttributePlugin } from './plugin/add-entry-attribute.mjs';
|
|
5
4
|
import { CopyPlugin } from './plugin/copy.mjs';
|
|
5
|
+
import { SimpleHtmlWebpackPlugin } from './plugin/html-webpack-plugin.mjs';
|
|
6
6
|
import moduleFederation from './plugin/module-federation.mjs';
|
|
7
7
|
import { VirtualModuleWebpackPlugin } from './plugin/virtual-module.mjs';
|
|
8
8
|
import { CONFIG } from './config.mjs';
|
package/lib/plugins.config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"
|
|
1
|
+
import e from"webpack";import t from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as o}from"./plugin/add-entry-attribute.mjs";import{CopyPlugin as l}from"./plugin/copy.mjs";import{SimpleHtmlWebpackPlugin as i}from"./plugin/html-webpack-plugin.mjs";import n from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as p}from"./plugin/virtual-module.mjs";import{CONFIG as r}from"./config.mjs";import{isMicro as s}from"./process-env.mjs";let m=e.DefinePlugin,a=e.SourceMapDevToolPlugin,c=e.IgnorePlugin,u=r.basename.split("/").filter(Boolean).length,g=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,h=r.fixBrowserRouter||{},f=h.pathSegmentsToKeep??u,d=h.path??g,w=[...n,new p(r.virtualModule),r.htmlPluginOption&&new i(t),r.fixBrowserRouter&&new i({filename:d,inject:!1,templateContent:()=>`<html lang="en"><head><title>${t.title}</title><script>const pathKeep = ${f};const l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new l(r.copy),s&&new o({test:/main\.bundle\.js$/}),new m({"process.env":JSON.stringify(r.env)}),new c({resourceRegExp:/\/(__(tests|mocks)__|test|spec|e2e)\//}),r.sourceMap&&new a(r.sourceMap),...r.plugins].filter(e=>!!e);export default w;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.26.12-beta.
|
|
3
|
+
"version": "3.26.12-beta.3",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/core": "7.26.0",
|
|
19
|
+
"@fastify/compress": "7.0.3",
|
|
20
|
+
"@fastify/http-proxy": "9.5.0",
|
|
21
|
+
"@fastify/middie": "8.3.3",
|
|
19
22
|
"@moneko/mdx": "0.1.42",
|
|
20
23
|
"@moneko/transform-imports": "0.6.1",
|
|
21
24
|
"@moneko/utils": "0.1.19",
|
|
@@ -25,21 +28,17 @@
|
|
|
25
28
|
"chokidar": "4.0.2",
|
|
26
29
|
"core-js": "3.39.0",
|
|
27
30
|
"core-js-compat": "3.39.0",
|
|
28
|
-
"
|
|
29
|
-
"html-webpack-plugin": "5.6.3",
|
|
30
|
-
"http-proxy-middleware": "3.0.3",
|
|
31
|
+
"fastify": "4.29.0",
|
|
31
32
|
"less": "4.2.1",
|
|
32
33
|
"less-loader": "12.2.0",
|
|
33
34
|
"lightningcss": "1.28.2",
|
|
34
35
|
"marked-completed": "1.2.14",
|
|
35
36
|
"mini-css-extract-plugin": "2.9.2",
|
|
36
|
-
"multer": "1.4.5-lts.1",
|
|
37
37
|
"style-loader": "4.0.0",
|
|
38
38
|
"swc-loader": "0.2.6",
|
|
39
39
|
"terser-webpack-plugin": "5.3.11",
|
|
40
40
|
"typescript": "5.5.4",
|
|
41
41
|
"webpack": "5.97.1",
|
|
42
|
-
"webpack-bundle-analyzer": "4.10.2",
|
|
43
42
|
"webpack-dev-middleware": "7.4.2",
|
|
44
43
|
"webpack-hot-middleware": "2.26.1",
|
|
45
44
|
"webpack-merge": "6.0.1",
|
|
@@ -48,15 +47,14 @@
|
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@moneko/css": "1.1.5",
|
|
50
49
|
"@types/babel__core": "7.20.5",
|
|
51
|
-
"@types/express": "5.0.0",
|
|
52
|
-
"@types/multer": "1.4.12",
|
|
53
50
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
54
51
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
55
52
|
"eslint-config-neko": "3.0.2",
|
|
56
53
|
"sass": "1.83.0",
|
|
57
54
|
"sass-loader": "16.0.4",
|
|
58
55
|
"solid-refresh": "0.7.5",
|
|
59
|
-
"stylelint": "
|
|
56
|
+
"stylelint": "16.11.0",
|
|
57
|
+
"webpack-bundle-analyzer": "4.10.2"
|
|
60
58
|
},
|
|
61
59
|
"files": [
|
|
62
60
|
"lib",
|
package/typings/global.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { MdxOptions } from '@moneko/mdx';
|
|
2
2
|
import type { Config as SwcConfig, JsMinifyOptions as SwcMinifyOptions } from '@swc/core';
|
|
3
|
-
import type { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
|
|
4
|
-
import type { Options } from 'http-proxy-middleware';
|
|
5
3
|
import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin';
|
|
6
4
|
import type { MinifyOptions as TerserMinifyOptions } from 'terser';
|
|
7
5
|
import type {
|
|
@@ -16,9 +14,11 @@ import type {
|
|
|
16
14
|
} from 'webpack';
|
|
17
15
|
|
|
18
16
|
import type {
|
|
17
|
+
HtmlWebpackOption,
|
|
19
18
|
JsxDomExpressions,
|
|
20
19
|
OptimizationSplitChunksOptions,
|
|
21
20
|
OverrideResolverOption,
|
|
21
|
+
ProxyConfig,
|
|
22
22
|
VirtualModulePluginOption,
|
|
23
23
|
} from '../lib/index';
|
|
24
24
|
import type { CopyPluginOption } from '../lib/plugin/copy.mjs';
|
|
@@ -30,57 +30,7 @@ export type { MiniCssExtractPluginOptions, SwcMinifyOptions, TerserMinifyOptions
|
|
|
30
30
|
export type MinifierType = 'swc' | 'terser';
|
|
31
31
|
export declare type AppType = 'mobile' | 'site' | 'backstage' | 'micro' | 'library';
|
|
32
32
|
export declare type Framework = 'react' | 'solid';
|
|
33
|
-
export interface ProxyConfig {
|
|
34
|
-
[key: string]: Options;
|
|
35
|
-
}
|
|
36
33
|
|
|
37
|
-
export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
|
|
38
|
-
/**
|
|
39
|
-
* 自定义额外的 tags, 当需要添加远程cdn时很有用
|
|
40
|
-
* @description
|
|
41
|
-
* 如果你配置了自定义的 template, 那么默认情况下 tags 将不生效, 请在你的 template 中按照下方案例进行修改
|
|
42
|
-
* @example
|
|
43
|
-
* ```html
|
|
44
|
-
* <!DOCTYPE html>
|
|
45
|
-
<html lang="en">
|
|
46
|
-
<head>
|
|
47
|
-
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
48
|
-
<%
|
|
49
|
-
var customTag="";
|
|
50
|
-
if (htmlWebpackPlugin.options.tags) {
|
|
51
|
-
htmlWebpackPlugin.options.tags.forEach(function(item){
|
|
52
|
-
var { tag = "script", textContent = "", ...attrs } = item;
|
|
53
|
-
var _attrs = "";
|
|
54
|
-
for (const key in attrs) {
|
|
55
|
-
if (attrs.hasOwnProperty(key)) {
|
|
56
|
-
_attrs += `${key}="${attrs[key]}" `;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
customTag += `<${tag} ${_attrs}>${textContent}</${tag}>`;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
%>
|
|
63
|
-
<%= customTag %>
|
|
64
|
-
</head>
|
|
65
|
-
<body>
|
|
66
|
-
<div id="root"></div>
|
|
67
|
-
</body>
|
|
68
|
-
</html>
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
tags?: {
|
|
72
|
-
/**
|
|
73
|
-
* 标签内容
|
|
74
|
-
*/
|
|
75
|
-
textContent?: string;
|
|
76
|
-
/** 标签
|
|
77
|
-
* @default script
|
|
78
|
-
*/
|
|
79
|
-
tag?: string;
|
|
80
|
-
inject?: 'body' | 'head';
|
|
81
|
-
[key: string]: string | null | boolean | number;
|
|
82
|
-
}[];
|
|
83
|
-
};
|
|
84
34
|
export type DevtoolOption =
|
|
85
35
|
| 'eval'
|
|
86
36
|
| 'eval-cheap-source-map'
|