@moneko/core 3.26.12-beta.2 → 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.
@@ -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';
@@ -1 +1 @@
1
- import e from"mini-css-extract-plugin";import i from"terser-webpack-plugin";import n from"webpack";import{BundleAnalyzerPlugin as m}from"webpack-bundle-analyzer";import{merge as r}from"webpack-merge";import{commonConfig as t}from"../common.mjs";import{CONFIG as o}from"../config.mjs";import{getMinifyOption as s}from"../options/js-minify.mjs";import{LightningCssMinifyPlugin as l}from"../plugin/lightningcss-plugin.mjs";import{getLightningCssTargets as p}from"../polyfills/targets.mjs";let a=[];o.minifier&&(a.push(new i(s(o.minifier.type,o.minifier.options))),a.push(new l({targets:p()})));let u={maxAssetSize:256e3,maxEntrypointSize:256e3,assetFilter:e=>!e.endsWith(".map")&&!e.endsWith("ce28377f3a428346.js"),...o.performance},c=r(t,{performance:o.performance&&u,plugins:[new e({filename:"style/[name].bundle.css",chunkFilename:"style/[name].chunk.css",ignoreOrder:!0}),o.splitChunk&&new n.optimize.MinChunkSizePlugin({minChunkSize:51200}),o.bundleAnalyzer&&new m({analyzerMode:"static",reportFilename:"report.html",openAnalyzer:!1,defaultSizes:"gzip",logLevel:"silent",...o.bundleAnalyzer})].filter(Boolean),optimization:{splitChunks:o.splitChunk,runtimeChunk:o.runtimeChunk,chunkIds:"deterministic",moduleIds:"deterministic",concatenateModules:!0,emitOnErrors:!1,removeAvailableModules:!0,removeEmptyChunks:!0,mergeDuplicateChunks:!0,minimize:!0,minimizer:a}});export default c;
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/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 r,PACKAGENAME as a}from"../process-env.mjs";import{resolveProgram as n}from"../utils/index.mjs";let l=t.htmlPluginOption||{},p=l.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(r)?r.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||a.toLocaleUpperCase()||"Title",filename:"index.html",hash:!1,minify:{minifyJS:!0,minifyCSS:!0,collapseWhitespace:!0,removeComments:!0,removeRedundantAttributes:!1,removeScriptTypeAttributes:!1,removeStyleLinkTypeAttributes:!1,removeAttributeQuotes:!0,useShortDoctype:!0},meta:s,tags:[]},l,{favicon:p?n(p):p},l.template?{template:n(l.template)}:{templateContent:function({htmlWebpackPlugin:{options:e}}){let t=e.tags,i="",o="";return t&&t.map(function(e){let{tag:t="script",textContent:r="",inject:a="head",...n}=e,l="";for(let e in n)Object.prototype.hasOwnProperty.call(n,e)&&(l+=`${e}="${n[e]}" `);let p=`<${t} ${l}>${r}</${t}>`;"body"===a?o+=p:i+=p}),`<!DOCTYPE html>
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}}
@@ -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';
@@ -1 +1 @@
1
- import e from"html-webpack-plugin";import t from"webpack";import o from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as l}from"./plugin/add-entry-attribute.mjs";import{CopyPlugin as i}from"./plugin/copy.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=t.DefinePlugin,a=t.SourceMapDevToolPlugin,c=t.IgnorePlugin,u=r.basename.split("/").filter(Boolean).length,h=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,f=r.fixBrowserRouter||{},g=f.pathSegmentsToKeep??u,d=f.path??h,w=[...n,new p(r.virtualModule),r.htmlPluginOption&&new e(o),r.fixBrowserRouter&&new e({filename:d,inject:!1,templateContent:()=>`<html lang="en"><head><title>${o.title}</title><script>const pathKeep = ${g};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 i(r.copy),s&&new l({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;
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.2",
3
+ "version": "3.26.12-beta.3",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -29,7 +29,6 @@
29
29
  "core-js": "3.39.0",
30
30
  "core-js-compat": "3.39.0",
31
31
  "fastify": "4.29.0",
32
- "html-webpack-plugin": "5.6.3",
33
32
  "less": "4.2.1",
34
33
  "less-loader": "12.2.0",
35
34
  "lightningcss": "1.28.2",
@@ -40,7 +39,6 @@
40
39
  "terser-webpack-plugin": "5.3.11",
41
40
  "typescript": "5.5.4",
42
41
  "webpack": "5.97.1",
43
- "webpack-bundle-analyzer": "4.10.2",
44
42
  "webpack-dev-middleware": "7.4.2",
45
43
  "webpack-hot-middleware": "2.26.1",
46
44
  "webpack-merge": "6.0.1",
@@ -55,7 +53,8 @@
55
53
  "sass": "1.83.0",
56
54
  "sass-loader": "16.0.4",
57
55
  "solid-refresh": "0.7.5",
58
- "stylelint": "^16.11.0"
56
+ "stylelint": "16.11.0",
57
+ "webpack-bundle-analyzer": "4.10.2"
59
58
  },
60
59
  "files": [
61
60
  "lib",
@@ -1,6 +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
3
  import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin';
5
4
  import type { MinifyOptions as TerserMinifyOptions } from 'terser';
6
5
  import type {
@@ -15,6 +14,7 @@ import type {
15
14
  } from 'webpack';
16
15
 
17
16
  import type {
17
+ HtmlWebpackOption,
18
18
  JsxDomExpressions,
19
19
  OptimizationSplitChunksOptions,
20
20
  OverrideResolverOption,
@@ -31,53 +31,6 @@ 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
33
 
34
- export type HtmlWebpackOption = HtmlWebpackPluginOptions & {
35
- /**
36
- * 自定义额外的 tags, 当需要添加远程cdn时很有用
37
- * @description
38
- * 如果你配置了自定义的 template, 那么默认情况下 tags 将不生效, 请在你的 template 中按照下方案例进行修改
39
- * @example
40
- * ```html
41
- * <!DOCTYPE html>
42
- <html lang="en">
43
- <head>
44
- <title><%= htmlWebpackPlugin.options.title %></title>
45
- <%
46
- var customTag="";
47
- if (htmlWebpackPlugin.options.tags) {
48
- htmlWebpackPlugin.options.tags.forEach(function(item){
49
- var { tag = "script", textContent = "", ...attrs } = item;
50
- var _attrs = "";
51
- for (const key in attrs) {
52
- if (attrs.hasOwnProperty(key)) {
53
- _attrs += `${key}="${attrs[key]}" `;
54
- }
55
- }
56
- customTag += `<${tag} ${_attrs}>${textContent}</${tag}>`;
57
- });
58
- }
59
- %>
60
- <%= customTag %>
61
- </head>
62
- <body>
63
- <div id="root"></div>
64
- </body>
65
- </html>
66
- * ```
67
- */
68
- tags?: {
69
- /**
70
- * 标签内容
71
- */
72
- textContent?: string;
73
- /** 标签
74
- * @default script
75
- */
76
- tag?: string;
77
- inject?: 'body' | 'head';
78
- [key: string]: string | null | boolean | number;
79
- }[];
80
- };
81
34
  export type DevtoolOption =
82
35
  | 'eval'
83
36
  | 'eval-cheap-source-map'