@moneko/core 3.1.0-beta.5 → 3.1.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/common.js +2 -2
- package/lib/config.js +1 -1
- package/lib/polyfills.js +3 -4
- package/lib/swcrc.js +2 -3
- package/package.json +1 -1
- package/typings/global.d.ts +4 -0
package/lib/common.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import n from"webpackbar";import"./cleanup.js";import{CONFIG as l,PUBLICPATH as r}from"./config.js";import i from"./done.js";import a from"./html-add-entry-attr.js";import p from"./html-plugin-option.js";import{moduleFederation as m}from"./module-federation.js";import c from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as
|
|
2
|
-
NODE_ENV:process.env.NODE_ENV})}),new D({paths:[/\.d\.ts$/]}),l.sourceMap&&new P(l.sourceMap),l.bar&&new n(l.bar),new i({done:()=>{!y&&l.seo&&w(),l.done?.(),y||setTimeout(()=>{process.exit(0)},2e3)}}),new
|
|
1
|
+
import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import o from"webpack";import n from"webpackbar";import"./cleanup.js";import{CONFIG as l,PUBLICPATH as r}from"./config.js";import i from"./done.js";import a from"./html-add-entry-attr.js";import p from"./html-plugin-option.js";import{moduleFederation as m}from"./module-federation.js";import c from"./module.config.js";import u from"./paths.js";import{CUSTOMCONFIG as f,PACKAGENAME as h,hasEslintConfig as d,hasStylelintConfig as j,isDev as y,isLibrary as g,isMicro as b}from"./process-env.js";import{seo as w}from"./seo.js";import{resolveNodeModulesPath as x,resolveProgramPath as k}from"./utils.js";import v from"./virtual-module-plugin.js";import C from"./virtual-modules.js";let{AutomaticPrefetchPlugin:O,DefinePlugin:$,SourceMapDevToolPlugin:P,WatchIgnorePlugin:D}=o,N=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],S=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],A=e.readdirSync(u.programPath),B=!1,E=!1;for(let e=0,t=A.length;e<t;e++)S.includes(A[e])&&(E=!0),N.includes(A[e])&&(B=!0);B||(B=d),E||(E=j);let M=E?(await import("stylelint-webpack-plugin")).default:null,T=B?(await import("eslint-webpack-plugin")).default:null,_=l.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:k(g?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:"js/[chunkhash].js",assetModuleFilename:"assets/[hash][ext][query]",library:{name:h,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${h}`,pathinfo:y,clean:!0,publicPath:r,asyncChunks:!0};let K={main:x("@app/entry")};l.entry&&("string"==typeof l.entry?K=l.entry:Object.keys(l.entry)&&Object.assign(K,l.entry)),l.output&&("string"==typeof l.output?outputConfig.path=l.output:Object.keys(l.output)&&Object.assign(outputConfig,l.output));let L=l.basename.split("/").filter(Boolean).length,F=`${Array(L).fill("..").join("/")+(L?"/":"")}404.html`,{pathSegmentsToKeep:J=L,path:R=F}=l.fixBrowserRouter||{},V=!1;l.cacheDirectory&&(V={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:l.cacheDirectory,memoryCacheUnaffected:!0,name:`${f||"default"}-${y?"development":"production"}`});export const clientConfig={entry:K,stats:"errors-only",cache:V,infrastructureLogging:{level:"none"},target:"web",externalsPresets:l.externalsPresets,plugins:[new O,...m,T&&new T({fix:!0,threads:!0,extensions:["js","md","mdx","cjs","ejs","mjs","jsx","ts","tsx","json","html","coffee","vue"]}),M&&new M({fix:!0,threads:!0,extensions:["css","scss","sass","less","ts","tsx","js","jsx"],exclude:["node_modules/","es/","lib/","docs/","coverage/","dist/"]}),l.htmlPluginOption&&new s(p),l.fixBrowserRouter&&new s({filename:R,inject:!1,templateContent:()=>`<html html><head><title>${p.title}</title><script>var pathSegmentsToKeep = ${J||L};var l = window.location;l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' + l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash);</script></head><body></body></html>`}),new t(_),b&&new a(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new $({"process.env":JSON.stringify({...l.env,// mf 需要 isDev
|
|
2
|
+
NODE_ENV:process.env.NODE_ENV})}),new D({paths:[/\.d\.ts$/]}),l.sourceMap&&new P(l.sourceMap),l.bar&&new n(l.bar),new i({done:()=>{!y&&l.seo&&w(),l.done?.(),y||setTimeout(()=>{process.exit(0)},2e3)}}),new v(C),...l.plugins].filter(Boolean),experiments:{topLevelAwait:!0,syncWebAssembly:!0,asyncWebAssembly:!0},resolve:{extensions:[".tsx",".ts",".js",".jsx"],alias:l.alias,fallback:{path:!1,fs:!1,crypto:!1,assert:!1}},module:c,externals:l.externals,output:outputConfig};
|
package/lib/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as
|
|
1
|
+
import{accessSync as e,constants as t}from"fs";import o from"readline";import s from"chalk";import{merge as r}from"webpack-merge";import i from"./paths.js";import{APPTYPE as a,CUSTOMCONFIG as l,FRAMEWORK as n,PACKAGENAME as c,jsxImportSource as m,pkgName as p}from"./process-env.js";import{isFunction as u,readConf as d,resolveProgramPath as h}from"./utils.js";export const ENTRYPATH={mobile:"mobile",site:"site",backstage:"backstage",micro:"micro",library:"library"};let f=["@moneko/core",`@moneko/${n}`,"neko-ui","antd","@antv","katex","font-pingfang-sc","font-pingfang-tc","react-photo-view","react-markdown-editor-lite","schema-design","@app"],g={library:{"@":h("site"),"@pkg":h("components"),[c]:h("components")},mobile:{},site:{},backstage:{},micro:{}},b={seo:!1,mode:"csr",compiler:"swc",bundleAnalyzer:!1,polyfill:!1,entry:{},minifier:{js:{},css:{}},sourceMap:{filename:"[file].map",publicPath:""},env:{},basename:"/",publicPath:"/",rem:{designSize:"mobile"===a?375:1680},fallbackCompPath:null,modifyVars:{},prefixCls:"n",alias:Object.assign({"@":h("src")},g[a]),moduleRules:[],prefixJsLoader:[],cssModules:[],importOnDemand:{},proxy:[],cacheDirectory:i.webpackCachePath,devServer:{allowedHosts:[".baidu.com"],host:"localhost",port:3e3,https:!1,compress:!1},htmlPluginOption:{template:`node_modules/${p}/template/index.html`,favicon:`node_modules/${p}/template/favicon.ico`,tags:[]},assetHtml:[],routerMode:"browser",fixBrowserRouter:!1,plugins:[],splitChunk:{chunks:"all",minSize:1024,minChunks:1,cacheGroups:{route:{test:/[\\/].git[\\/]router/,priority:-10,reuseExistingChunk:!0,name:"route"},example:{test:/[\\/].git[\\/]example/,priority:-10,reuseExistingChunk:!0,name:"example"}}},runtimeChunk:"single",moduleFederation:[],rulesInclude:{less:f,css:f,js:f,media:f,fonts:f},mdx:{jsxImportSource:m,useDynamicImport:!0,remarkPlugins:[],rehypePlugins:[]},jsxDomExpressions:{moduleName:"solid-js/web",builtIns:["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"],contextToCustomElements:!0,wrapConditionals:!0,generate:"dom",hydratable:!1},bar:{name:"编译中",color:"#6f42c1"},virtualModule:{},normalizeCss:!0,externalsPresets:{}};export const log=e=>{o.cursorTo(process.stdout,0),process.stdout.write(e)};let x=b,y=null,C={},w={};try{y=i.defaultConfigPath,e(y,t.R_OK)}catch(e){y=null}if(y)try{let e=(await d(y,"index")).default;C=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}if(l){let o=null;try{o=`${i.programPath}/config/${l}.ts`,e(o,t.R_OK)}catch(e){o=null}if(null!==o)try{let e=(await d(o,l)).default;w=u(e)?e(process):e}catch(e){process.stdout.write(s.red(e))}}"tsc"===(x=r(x,C,w)).compiler&&x.minifier&&(x.minifier.js||Object.assign(x.minifier,{js:{type:"terser"}}),x.minifier.css||Object.assign(x.minifier,{css:{type:"cssnano"}})),!1===x.devtool&&(x.sourceMap=!1),!1===x.sourceMap&&(x.devtool=!1),x.fixBrowserRouter&&x.htmlPluginOption&&(x.htmlPluginOption.tags||(x.htmlPluginOption.tags=[]),x.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=x;export const PUBLICPATH=CONFIG.publicPath||"/";export let hasCustomRouter=!1;try{e(`${CONFIG.alias["@"]}/router/index.ts`,t.R_OK),hasCustomRouter=!0}catch(e){hasCustomRouter=!1}global.NEKOCLICONFIG={CONFIG,log};
|
package/lib/polyfills.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import r from"browserslist";import
|
|
2
|
-
|
|
3
|
-
version:"3.32"})
|
|
4
|
-
return e}
|
|
1
|
+
import r from"browserslist";import t from"core-js-compat";import o from"./paths.js";export default function(){return t({// 从项目的根目录自动寻找 browserslistrc 配置
|
|
2
|
+
targets:r(void 0,{path:o.programPath,env:process.env.NODE_ENV}).filter(r=>!r.endsWith(" TP")),// 须指定 core-js 前两位具体版本,如 `3.20`,否则 polyfill 会不全
|
|
3
|
+
version:"3.32.2"}).list}
|
package/lib/swcrc.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import{merge as e}from"webpack-merge";import{CONFIG as o}from"./config.js";import r from"./paths.js";import
|
|
2
|
-
|
|
3
|
-
env:{include:s(),mode:"entry",coreJs:"3.32.2"}});return o.swcrc&&(i=e(i,"function"==typeof o.swcrc?o.swcrc(p):o.swcrc)),i});
|
|
1
|
+
import{merge as e}from"webpack-merge";import{CONFIG as o}from"./config.js";import r from"./paths.js";import t from"./polyfills.js";import{isReact as s,isSolid as n,jsxImportSource as l}from"./process-env.js";export const swcMinifyOption={compress:{top_retain:[],keep_infinity:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"],toplevel:!1,drop_console:!0,drop_debugger:!0,module:!1,ecma:2015,ie8:!1,keep_classnames:void 0,keep_fnames:!1},mangle:!0};export default((p=!1)=>{let a={module:{type:"es6",resolveFully:!0},jsc:{parser:{syntax:"typescript",decorators:!0,dynamicImport:!0,tsx:!0,topLevelAwait:!0,importMeta:!0},loose:!0,target:"es2017",externalHelpers:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:"automatic",throwIfNamespace:!0,useBuiltins:!0,refresh:s&&p,development:p,importSource:l},optimizer:{simplify:!1}},experimental:{emitAssertForImportAttributes:!0,cacheRoot:r.swcCachePath,plugins:[["swc-plugin-another-transform-imports",function(e){for(let o=0,r=Object.keys(e),t=r.length;o<t;o++)e[r[o]].transform=`${r[o]}/${e[r[o]].transform}`,e[r[o]].style&&(e[r[o]].style=`${r[o]}/${e[r[o]].style}`);return e}(o.importOnDemand||{})],n&&["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]].filter(Boolean)}},sourceMaps:!0,parseMap:!0};return(o.polyfill&&(a.jsc.target=void 0,// swc polyfill,会复用 babel 链路,但效率比 babel 低
|
|
2
|
+
a.env={include:t(),mode:"entry",coreJs:"3.32.2"}),o.swcrc)?e(a,"function"==typeof o.swcrc?o.swcrc(p):o.swcrc):a});
|
package/package.json
CHANGED
package/typings/global.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ export interface Theme {
|
|
|
38
38
|
warningColor?: string;
|
|
39
39
|
}
|
|
40
40
|
export declare type ConfigType<T extends 'tsc' | 'swc' = 'swc'> = {
|
|
41
|
+
/** 启用 polyfill; 当设置为 `true` 时, 则根据 `browserslist` 设置自动polyfill
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
polyfill?: boolean;
|
|
41
45
|
/** 渲染模式
|
|
42
46
|
* @default 'csr'
|
|
43
47
|
*/
|