@moneko/core 3.13.1 → 3.14.0

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/config.mjs CHANGED
@@ -1 +1 @@
1
- import{fileExists as e}from"@moneko/mdx";import{merge as o}from"webpack-merge";import t from"./options/jsx-dom-expressions.mjs";import s from"./options/split-chunk.mjs";import a,{CUSTOMCONFIG as i}from"./paths.mjs";import{APPTYPE as r,FRAMEWORK as l,NODE_ENV as n,PACKAGENAME as m,isDev as p,isLibrary as c,isMobile as u,jsxImportSource as d,mainDirectory as h}from"./process-env.mjs";import{isFunction as f,resolveProgram as g}from"./utils/index.mjs";import x from"./utils/log.mjs";import P from"./utils/read-conf.mjs";import v from"./utils/setup-env.mjs";let C=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],j={devtool:p?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:v(n,r,l),basename:"/",publicPath:"/",rem:{designSize:u?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":g(h)},moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:{},cacheDirectory:a.webpackCachePath,devServer:{host:"localhost",port:3e3},htmlPluginOption:{},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:s,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:C,js:C,media:C,font:C,wasm:[]},mdx:{jsx:!1,development:p,jsxImportSource:d,providerImportSource:`@moneko/${l}/mdx`},jsxDomExpressions:t,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${a.httpCachePath}/http.lock`,cacheLocation:`${a.httpCachePath}/data`,upgrade:!0},virtualModule:{},cssExtract:{}};c&&(j.alias=Object.assign(j.alias,{"@pkg":a.componentsPath,[m]:a.componentsPath}));let k=j,w={},b={};if(e(a.configPath)){let e=(await P(a.configPath,"index")).default;w=f(e)?e(process):e}if(i&&e(a.customConfigPath)){let e=(await P(a.customConfigPath,i)).default;b=f(e)?e(process):e}(!1===(k=o(k,w,b)).devtool||!1===k.sourceMap)&&(k.sourceMap=!1,k.devtool=!1),k.fixBrowserRouter&&k.htmlPluginOption&&(k.htmlPluginOption.tags||(k.htmlPluginOption.tags=[]),k.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=k;export const PUBLICPATH=CONFIG.publicPath||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:i,log:x};
1
+ import{fileExists as e}from"@moneko/mdx";import{merge as o}from"webpack-merge";import t from"./options/jsx-dom-expressions.mjs";import s from"./options/split-chunk.mjs";import a,{CUSTOMCONFIG as i}from"./paths.mjs";import{APPTYPE as r,FRAMEWORK as l,NODE_ENV as n,PACKAGENAME as m,isDev as p,isLibrary as c,isMobile as u,jsxImportSource as d,mainDirectory as h}from"./process-env.mjs";import{isFunction as f,resolveProgram as g}from"./utils/index.mjs";import x from"./utils/log.mjs";import P from"./utils/read-conf.mjs";import v from"./utils/setup-env.mjs";let C=["@moneko","neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app",".cache/http/data"],j={devtool:p?"eval-cheap-module-source-map":"cheap-module-source-map",seo:!1,mode:"csr",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{},sourceMap:{filename:"[file].map",publicPath:""},env:v(n,r,l),basename:"/",publicPath:"/",rem:{designSize:u?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:{"@":g(h)},moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:{},cacheDirectory:a.webpackCachePath,devServer:{host:"localhost",port:3e3},htmlPluginOption:{},copy:{},routerMode:"browser",fixBrowserRouter:!1,plugins:[],resolvePlugins:[],overrideResolve:!1,splitChunk:s,runtimeChunk:"single",moduleFederation:[],rulesInclude:{css:C,js:C,media:C,font:C,wasm:[]},mdx:{jsx:!1,development:p,jsxImportSource:d,providerImportSource:`@moneko/${l}/mdx`},jsxDomExpressions:t,bar:{name:"Client",color:"#6f42c1"},normalizeCss:!0,externalsPresets:{},buildHttp:{allowedUris:[],lockfileLocation:`${a.httpCachePath}/http.lock`,cacheLocation:`${a.httpCachePath}/data`,upgrade:!0},virtualModule:{},cssExtract:{}};c&&(j.alias=Object.assign(j.alias,{"@pkg":a.componentsPath,[m]:a.componentsPath}));let k=j,w={},b={};if(e(a.configPath)){let e=(await P(a.configPath,"index")).default;w=f(e)?e(process):e}if(i&&e(a.customConfigPath)){let e=(await P(a.customConfigPath,i)).default;b=f(e)?e(process):e}(!1===(k=o(k,w,b)).devtool||!1===k.sourceMap)&&(k.sourceMap=!1,k.devtool=!1),k.fixBrowserRouter&&k.htmlPluginOption&&(k.htmlPluginOption.tags||(k.htmlPluginOption.tags=[]),k.htmlPluginOption.tags.push({textContent:"(function(l) {if (l.search[1] === '/' ) {var decoded = l.search.slice(1).split('&').map(function(s) {return s.replace(/~and~/g, '&')}).join('?');window.history.replaceState(null, null,l.pathname.slice(0, -1) + decoded + l.hash);}}(window.location))"}));export const CONFIG=k;export const PUBLICPATH=CONFIG.publicPath||"/";global.NEKOCLICONFIG={CONFIG,CUSTOMCONFIG:i,log:x};
@@ -0,0 +1,26 @@
1
+ import { Compiler } from 'webpack';
2
+ /** 需要拷贝的文件列表
3
+ * @example
4
+ * ```ts
5
+ * export default {
6
+ * copy: {
7
+ * // 将 public 下的 a.json 和 s.txt 添加到资源
8
+ * files: ['public/a.json', 'public/s.txt'],
9
+ * // 将 static 文件夹添加到资源
10
+ * dirs: ['static']
11
+ * }
12
+ * }
13
+ * ```
14
+ */
15
+ export interface CopyPluginOption {
16
+ /** 需要拷贝的文件列表 */
17
+ files?: string[];
18
+ /** 需要拷贝的文件夹 */
19
+ dirs?: string[];
20
+ }
21
+ export declare class CopyPlugin {
22
+ private option;
23
+ constructor(option: CopyPluginOption);
24
+ private writeFile;
25
+ apply(compiler: Compiler): void;
26
+ }
@@ -0,0 +1 @@
1
+ import{loadFile as t,scanFolder as i}from"@moneko/mdx";import{basename as o,resolve as p}from"path";import e from"../utils/log.mjs";export class CopyPlugin{constructor(t){this.option=t}async writeFile(i,r){let l=r.compiler.outputFileSystem;if(l){let s=o(i),a=await t(p(i));l.writeFile(p(r.outputOptions.path,s),a,t=>{t&&e(`Error copying file ${s} to output directory: ${t}`)})}}apply(t){t.hooks.afterEmit.tapPromise({name:"CopyPlugin",stage:t.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT},async t=>{if(this.option&&t.compiler.outputFileSystem){let o=[...this.option.files||[],...this.option.dirs?.flatMap(t=>i(t))||[]];await Promise.all(o.map(i=>this.writeFile(i,t)))}})}}
@@ -1 +1 @@
1
- import e from"add-asset-html-webpack-plugin";import t from"html-webpack-plugin";import l from"webpack";import{CONFIG as o}from"./config.mjs";import i from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as r}from"./plugin/add-entry-attribute.mjs";import p from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as n}from"./plugin/virtual-module.mjs";import{isMicro as a}from"./process-env.mjs";let{DefinePlugin:m,SourceMapDevToolPlugin:s,IgnorePlugin:c}=l,u=o.basename.split("/").filter(Boolean).length,h=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,{pathSegmentsToKeep:f=u,path:d=h}=o.fixBrowserRouter||{},g=o.assetHtml.map(e=>({publicPath:"",...e})),w=[...p,new n(o.virtualModule),o.htmlPluginOption&&new t(i),o.fixBrowserRouter&&new t({filename:d,inject:!1,templateContent:()=>`<html lang="en"><head><title>${i.title}</title><script>const pathKeep = ${f||u};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 e(g),a&&new r({test:/main\.bundle\.js$/}),new m({"process.env":JSON.stringify(o.env)}),new c({resourceRegExp:/\/__tests__\//}),o.sourceMap&&new s(o.sourceMap),...o.plugins].filter(e=>!!e);export default w;
1
+ import e from"html-webpack-plugin";import t from"webpack";import{CONFIG as o}from"./config.mjs";import l from"./options/html-plugin-option.mjs";import{AddEntryAttributePlugin as i}from"./plugin/add-entry-attribute.mjs";import r from"./plugin/module-federation.mjs";import{VirtualModuleWebpackPlugin as n}from"./plugin/virtual-module.mjs";import{isMicro as p}from"./process-env.mjs";import{CopyPlugin as m}from"./plugin/copy-plugin.mjs";let{DefinePlugin:s,SourceMapDevToolPlugin:a,IgnorePlugin:c}=t,u=o.basename.split("/").filter(Boolean).length,f=`${Array(u).fill("..").join("/")+(u?"/":"")}404.html`,{pathSegmentsToKeep:h=u,path:g=f}=o.fixBrowserRouter||{},d=[...r,new n(o.virtualModule),o.htmlPluginOption&&new e(l),o.fixBrowserRouter&&new e({filename:g,inject:!1,templateContent:()=>`<html lang="en"><head><title>${l.title}</title><script>const pathKeep = ${h||u};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 m(o.copy),p&&new i({test:/main\.bundle\.js$/}),new s({"process.env":JSON.stringify(o.env)}),new c({resourceRegExp:/\/__tests__\//}),o.sourceMap&&new a(o.sourceMap),...o.plugins].filter(e=>!!e);export default d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.13.1",
3
+ "version": "3.14.0",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",
@@ -15,7 +15,6 @@
15
15
  "@moneko/transform-imports": "0.5.1",
16
16
  "@swc/core": "1.5.0",
17
17
  "@typescript/vfs": "1.5.0",
18
- "add-asset-html-webpack-plugin": "6.0.0",
19
18
  "browserslist": "4.23.0",
20
19
  "chalk": "5.3.0",
21
20
  "chokidar": "3.6.0",
@@ -10,7 +10,6 @@ import type {
10
10
  import type { DonePluginOption } from '../lib/plugin/done';
11
11
  import type { MdxOptions } from '@moneko/mdx';
12
12
  import type { Config as SwcConfig, JsMinifyOptions as SwcMinifyOptions } from '@swc/core';
13
- import type { Options as AssetHtmlOptions } from 'add-asset-html-webpack-plugin';
14
13
  import type { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
15
14
  import type { MinifyOptions as TerserMinifyOptions } from 'terser';
16
15
  import type {
@@ -21,6 +20,7 @@ import type {
21
20
  WebpackPluginInstance,
22
21
  } from 'webpack';
23
22
  import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin';
23
+ import type { CopyPluginOption } from '../lib/plugin/copy-plugin.mjs';
24
24
 
25
25
  export type { TerserMinifyOptions, SwcMinifyOptions, MiniCssExtractPluginOptions };
26
26
  export type MinifierType = 'swc' | 'terser';
@@ -220,22 +220,8 @@ export declare type ConfigType = {
220
220
  };
221
221
  /** HtmlWebpackPlugin Option */
222
222
  htmlPluginOption: HtmlWebpackOption | false;
223
- /** 自定义插入 html 的 js 和 css
224
- * @example
225
- * const conf = {
226
- * assetHtml: [
227
- * {
228
- * glob: './public/*.entry.css',
229
- * typeOfAsset: 'css',
230
- * },
231
- * {
232
- * glob: './public/*.entry.js',
233
- * typeOfAsset: 'js',
234
- * },
235
- * ]
236
- * }
237
- * */
238
- assetHtml: AssetHtmlOptions[];
223
+
224
+ copy: CopyPluginOption,
239
225
  /** 路由模式
240
226
  * @description
241
227
  * 当在不支持 browserRouter 的环境(GitHub pages)使用 browserRouter,