@moneko/core 3.0.0-beta.105 → 3.0.0-beta.106

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/swcrc.js CHANGED
@@ -1 +1,105 @@
1
- import{merge as e}from"webpack-merge";import{CONFIG as o}from"./common.js";import{isReact as r,isSolid as s,jsxImportSource as t}from"./process-env.js";let n={env:{targets:["last 2 version","> 0.5%","ie 11","not dead"],mode:"entry",coreJs:"3"}};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((a=!1)=>{let c={module:{type:"es6",ignoreDynamic:!0,strict:!0,strictMode:!0,lazy:!0,noInterop:!0},jsc:{parser:{syntax:"typescript",decorators:!0,dynamicImport:!0,tsx:!0},loose:!0,target:"es2022",externalHelpers:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:"automatic",throwIfNamespace:!0,useBuiltins:!0,refresh:r&&a,development:a,importSource:t},optimizer:{simplify:!1}},experimental:{plugins:[["swc-plugin-another-transform-imports",function(e){for(let o=0,r=Object.keys(e),s=r.length;o<s;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||{})],s&&["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]].filter(Boolean)}},sourceMaps:!0,parseMap:!0},i=Object.assign(c,!a&&n);return o.swcrc&&(i=e(i,"function"==typeof o.swcrc?o.swcrc(a):o.swcrc)),i});
1
+ import { merge } from 'webpack-merge';
2
+ import { CONFIG } from './common.js';
3
+ import { isReact, isSolid, jsxImportSource } from './process-env.js';
4
+ const swcPolyfill = {
5
+ env: {
6
+ targets: [
7
+ 'last 2 version',
8
+ '> 0.5%',
9
+ 'ie 11',
10
+ 'not dead'
11
+ ],
12
+ mode: 'entry',
13
+ coreJs: '3'
14
+ }
15
+ };
16
+ export const swcMinifyOption = {
17
+ compress: {
18
+ top_retain: [],
19
+ keep_infinity: true,
20
+ global_defs: {
21
+ '@alert': 'console.log'
22
+ },
23
+ pure_funcs: [
24
+ 'console.log',
25
+ 'console.warn',
26
+ 'console.error',
27
+ 'console.info'
28
+ ],
29
+ toplevel: false,
30
+ drop_console: true,
31
+ drop_debugger: true,
32
+ module: false,
33
+ ecma: 2015,
34
+ ie8: false,
35
+ keep_classnames: undefined,
36
+ keep_fnames: false
37
+ },
38
+ mangle: true
39
+ };
40
+ function transformConfigs(config) {
41
+ for(let i = 0, ks = Object.keys(config), l = ks.length; i < l; i++){
42
+ config[ks[i]].transform = `${ks[i]}/${config[ks[i]].transform}`;
43
+ if (config[ks[i]].style) {
44
+ config[ks[i]].style = `${ks[i]}/${config[ks[i]].style}`;
45
+ }
46
+ }
47
+ return config;
48
+ }
49
+ export default ((isDev = false)=>{
50
+ const swcOption = {
51
+ module: {
52
+ type: 'es6',
53
+ ignoreDynamic: true,
54
+ strict: true,
55
+ strictMode: true,
56
+ lazy: true,
57
+ noInterop: true
58
+ },
59
+ jsc: {
60
+ parser: {
61
+ syntax: 'typescript',
62
+ decorators: true,
63
+ dynamicImport: true,
64
+ tsx: true
65
+ },
66
+ loose: true,
67
+ target: 'es2022',
68
+ externalHelpers: true,
69
+ transform: {
70
+ legacyDecorator: true,
71
+ decoratorMetadata: true,
72
+ react: {
73
+ runtime: 'automatic',
74
+ throwIfNamespace: true,
75
+ useBuiltins: true,
76
+ refresh: isReact && isDev,
77
+ development: isDev,
78
+ importSource: jsxImportSource
79
+ },
80
+ optimizer: {
81
+ simplify: false
82
+ }
83
+ },
84
+ experimental: {
85
+ plugins: [
86
+ [
87
+ 'swc-plugin-another-transform-imports',
88
+ transformConfigs(CONFIG.importOnDemand || {})
89
+ ],
90
+ isSolid && [
91
+ '@moneko/jsx-dom-expressions',
92
+ CONFIG.jsxDomExpressions || {}
93
+ ]
94
+ ].filter(Boolean)
95
+ }
96
+ },
97
+ sourceMaps: true,
98
+ parseMap: true
99
+ };
100
+ let swcrc = Object.assign(swcOption, !isDev && swcPolyfill);
101
+ if (CONFIG.swcrc) {
102
+ swcrc = merge(swcrc, typeof CONFIG.swcrc === 'function' ? CONFIG.swcrc(isDev) : CONFIG.swcrc);
103
+ }
104
+ return swcrc;
105
+ });
@@ -1 +1,25 @@
1
- import t from"fs";import r from"ts-import-plugin";import o from"webpack-merge";import{CONFIG as e}from"./common.js";import{isFunction as m,readConf as s,resolveProgramPath as a}from"./utils.js";let i=[];Array.isArray(e.importOnDemand)&&Object.assign(i,e.importOnDemand.map(t=>r(t)));let n=[...i],p={transpileOnly:!0,getCustomTransformers:()=>({before:n})};try{let r=a("tsloader.config.ts");t.accessSync(r,t.constants.R_OK);let e=(await s(r,"tsloader.config")).default;p=o(p,m(e)?e(process):e)}catch(t){}export default p;
1
+ import fs from 'fs';
2
+ import transformerFactory from 'ts-import-plugin';
3
+ import merge from 'webpack-merge';
4
+ import { CONFIG } from './common.js';
5
+ import { isFunction, readConf, resolveProgramPath } from './utils.js';
6
+ const importOnDemand = [];
7
+ if (Array.isArray(CONFIG.importOnDemand)) {
8
+ Object.assign(importOnDemand, CONFIG.importOnDemand.map((item)=>transformerFactory(item)));
9
+ }
10
+ const beforeTransformers = [
11
+ ...importOnDemand
12
+ ];
13
+ let tsLoaderConfig = {
14
+ transpileOnly: true,
15
+ getCustomTransformers: ()=>({
16
+ before: beforeTransformers
17
+ })
18
+ };
19
+ try {
20
+ const customTsloaderConfigPath = resolveProgramPath('tsloader.config.ts');
21
+ fs.accessSync(customTsloaderConfigPath, fs.constants.R_OK);
22
+ const customTsloaderConfig = (await readConf(customTsloaderConfigPath, 'tsloader.config')).default;
23
+ tsLoaderConfig = merge(tsLoaderConfig, isFunction(customTsloaderConfig) ? customTsloaderConfig(process) : customTsloaderConfig);
24
+ } catch (error) {}
25
+ export default tsLoaderConfig;
package/lib/utils.js CHANGED
@@ -1 +1,49 @@
1
- import{writeFileSync as e}from"fs";import o from"path";import{transformFileSync as t}from"@swc/core";import{cacheDir as r}from"./process-env.js";import n from"./resolver-sync.js";let c={inputSourceMap:!1,sourceMaps:!1,module:{type:"es6"},jsc:{parser:{syntax:"typescript"},loose:!1}};export function tfc(e){return t(e,c).code||"{}"}export function readConf(t,n){let c=o.join(r,`${n}.mjs`);return e(c,tfc(t),"utf-8"),import(c)}export function toUpperCaseString(e){return e?.replace(/\b\w/g,e=>e.toUpperCase()).replace(/\./g," ")}export function resolveProgramPath(e){return o.resolve(process.cwd(),`./${e}`)}export const resolveNodeModulesPath=e=>resolveProgramPath(`node_modules/${e}`);export const resolve=e=>n.resolveSync({},process.cwd(),e)||e;export function isObject(e){let o=typeof e;return null!==e&&("object"==o||"function"==o)}export function isFunction(e){if(!isObject(e))return!1;let o=Object.prototype.toString.call(e);return"[object Function]"==o||"[object AsyncFunction]"==o||"[object GeneratorFunction]"==o||"[object Proxy]"==o}
1
+ import { writeFileSync } from 'fs';
2
+ import path from 'path';
3
+ import { transformFileSync } from '@swc/core';
4
+ import { cacheDir } from './process-env.js';
5
+ import resolverSync from './resolver-sync.js';
6
+ const swcOption = {
7
+ inputSourceMap: false,
8
+ sourceMaps: false,
9
+ module: {
10
+ type: 'es6'
11
+ },
12
+ jsc: {
13
+ parser: {
14
+ syntax: 'typescript'
15
+ },
16
+ loose: false
17
+ }
18
+ };
19
+ export function tfc(filepath) {
20
+ return transformFileSync(filepath, swcOption).code || '{}';
21
+ }
22
+ export function readConf(src, name) {
23
+ const cacheFile = path.join(cacheDir, `${name}.mjs`);
24
+ writeFileSync(cacheFile, tfc(src), 'utf-8');
25
+ return import(cacheFile);
26
+ }
27
+ export function toUpperCaseString(string) {
28
+ return string?.replace(/\b\w/g, (th)=>th.toUpperCase()).replace(/\./g, ' ');
29
+ }
30
+ export function resolveProgramPath(src) {
31
+ return path.resolve(process.cwd(), `./${src}`);
32
+ }
33
+ export const resolveNodeModulesPath = (src)=>{
34
+ return resolveProgramPath(`node_modules/${src}`);
35
+ };
36
+ export const resolve = (url)=>resolverSync.resolveSync({}, process.cwd(), url) || url;
37
+ const funcTag = '[object Function]';
38
+ const asyncTag = '[object AsyncFunction]';
39
+ const genTag = '[object GeneratorFunction]';
40
+ const proxyTag = '[object Proxy]';
41
+ export function isObject(target) {
42
+ const type = typeof target;
43
+ return target !== null && (type == 'object' || type == 'function');
44
+ }
45
+ export function isFunction(target) {
46
+ if (!isObject(target)) return false;
47
+ const tagType = Object.prototype.toString.call(target);
48
+ return tagType == funcTag || tagType == asyncTag || tagType == genTag || tagType == proxyTag;
49
+ }
@@ -1 +1,54 @@
1
- import t from"webpack-virtual-modules";import{docs as o}from"./docs.js";import{example as e,route as r}from"./routes.js";import{resolveNodeModulesPath as a}from"./utils.js";export default class{constructor(t){this.options=t}apply(i){let l=new t({[a(r.data.name)]:r.data.data,[a(e.data.name)]:"export default []"});r.listener(t=>{t.data&&l.writeModule(a(t.name),t.data)}),e.listener(t=>{let o=t.data;for(let t in o)Object.prototype.hasOwnProperty.call(o,t)&&o[t]&&l.writeModule(a(t),o[t])}),o.listener(t=>{for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&t[o]&&l.writeModule(a(o),t[o])}),l.apply(i),i.hooks.compilation.tap("VirtualModulePlugin",()=>{for(let t in this.options)if(Object.prototype.hasOwnProperty.call(this.options,t)){let o=this.options[t];"string"==typeof o?l.writeModule(a(t),o):l.writeModule(a(t),`export default ${JSON.stringify(o)}`)}})}};
1
+ import VirtualModulesPlugin from 'webpack-virtual-modules';
2
+ import { docs } from './docs.js';
3
+ import { example, route } from './routes.js';
4
+ import { resolveNodeModulesPath } from './utils.js';
5
+ class VirtualModulePlugin {
6
+ options;
7
+ constructor(options){
8
+ this.options = options;
9
+ }
10
+ apply(compiler) {
11
+ const vm = new VirtualModulesPlugin({
12
+ [resolveNodeModulesPath(route.data.name)]: route.data.data,
13
+ [resolveNodeModulesPath(example.data.name)]: 'export default []'
14
+ });
15
+ route.listener((next)=>{
16
+ if (next.data) {
17
+ vm.writeModule(resolveNodeModulesPath(next.name), next.data);
18
+ }
19
+ });
20
+ example.listener((next)=>{
21
+ const obj = next.data;
22
+ for(const key in obj){
23
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
24
+ if (obj[key]) {
25
+ vm.writeModule(resolveNodeModulesPath(key), obj[key]);
26
+ }
27
+ }
28
+ }
29
+ });
30
+ docs.listener((obj)=>{
31
+ for(const key in obj){
32
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
33
+ if (obj[key]) {
34
+ vm.writeModule(resolveNodeModulesPath(key), obj[key]);
35
+ }
36
+ }
37
+ }
38
+ });
39
+ vm.apply(compiler);
40
+ compiler.hooks.compilation.tap('VirtualModulePlugin', ()=>{
41
+ for(const key in this.options){
42
+ if (Object.prototype.hasOwnProperty.call(this.options, key)) {
43
+ const data = this.options[key];
44
+ if (typeof data === 'string') {
45
+ vm.writeModule(resolveNodeModulesPath(key), data);
46
+ } else {
47
+ vm.writeModule(resolveNodeModulesPath(key), `export default ${JSON.stringify(data)}`);
48
+ }
49
+ }
50
+ }
51
+ });
52
+ }
53
+ }
54
+ export default VirtualModulePlugin;
@@ -1,3 +1,34 @@
1
- import{accessSync as o,constants as p}from"fs";import{join as m}from"path";import r from"./app.js";import t from"./common/rem.js";import{CONFIG as a}from"./common.js";import{coverage as e}from"./coverage.js";import{FRAMEWORK as l}from"./process-env.js";import{resolveProgramPath as s}from"./utils.js";let i={...a.virtualModule,"@app":r,"@app/fallback":"export default null","@app/coverage":e,"@app/entry":`${a.normalizeCss?`import "@moneko/${l}/lib/normalize.css";`:""}
2
- ${a.rem?.designSize?t:""}
3
- await import('@moneko/${l}/lib/entry.js');`};a.fallbackCompPath&&Object.assign(i,{"@app/fallback":`import Fallback from "${a.fallbackCompPath}";export default Fallback;`});let c={};try{let r=m(s("site"),"./mdx-scope.ts");o(r,p.R_OK),c='import scope from "@/mdx-scope";export default scope;'}catch(o){c={}}Object.assign(i,{"@app/mdx-scope":c});export default i;
1
+ import { accessSync, constants } from 'fs';
2
+ import { join } from 'path';
3
+ import app from './app.js';
4
+ import rem from './common/rem.js';
5
+ import { CONFIG } from './common.js';
6
+ import { coverage } from './coverage.js';
7
+ import { FRAMEWORK } from './process-env.js';
8
+ import { resolveProgramPath } from './utils.js';
9
+ const virtualModules = {
10
+ ...CONFIG.virtualModule,
11
+ '@app': app,
12
+ '@app/fallback': 'export default null',
13
+ '@app/coverage': coverage,
14
+ '@app/entry': `${CONFIG.normalizeCss ? `import "@moneko/${FRAMEWORK}/lib/normalize.css";` : ''}
15
+ ${CONFIG.rem?.designSize ? rem : ''}
16
+ await import('@moneko/${FRAMEWORK}/lib/entry.js');`
17
+ };
18
+ if (CONFIG.fallbackCompPath) {
19
+ Object.assign(virtualModules, {
20
+ '@app/fallback': `import Fallback from "${CONFIG.fallbackCompPath}";export default Fallback;`
21
+ });
22
+ }
23
+ let mdxScope = {};
24
+ try {
25
+ const appEntryPath = join(resolveProgramPath('site'), './mdx-scope.ts');
26
+ accessSync(appEntryPath, constants.R_OK);
27
+ mdxScope = 'import scope from "@/mdx-scope";export default scope;';
28
+ } catch (error) {
29
+ mdxScope = {};
30
+ }
31
+ Object.assign(virtualModules, {
32
+ '@app/mdx-scope': mdxScope
33
+ });
34
+ export default virtualModules;
@@ -1,5 +1,4 @@
1
1
  import './cleanup.js';
2
2
  import type { WebpackConfiguration } from 'webpack-dev-server';
3
3
  export declare const outputConfig: WebpackConfiguration['output'];
4
- declare const config: WebpackConfiguration;
5
- export default config;
4
+ export declare const clientConfig: WebpackConfiguration;
@@ -1 +1,216 @@
1
- import e from"fs";import t from"add-asset-html-webpack-plugin";import s from"html-webpack-plugin";import n from"webpack";import o from"webpackbar";import"./cleanup.js";import{CONFIG as l,PUBLICPATH as i}from"./common.js";import r from"./define.js";import a from"./done.js";import p from"./html-add-entry-attr.js";import m from"./html-plugin-option.js";import{moduleFederation as u}from"./module-federation.js";import c from"./module.config.js";import{APPTYPE as d,DEV as f,PACKAGENAME as j,PROGRAMPATH as h,hasEslintConfig as g,hasStylelintConfig as y}from"./process-env.js";import{seo as b}from"./seo.js";import{resolveNodeModulesPath as w,resolveProgramPath as x}from"./utils.js";import k from"./virtual-module-plugin.js";import v from"./virtual-modules.js";let{AutomaticPrefetchPlugin:C,DefinePlugin:O,SourceMapDevToolPlugin:$,WatchIgnorePlugin:B}=n,A=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.json"],S=[".stylelintrc",".stylelintrc.json",".stylelintrc.yaml",".stylelintrc.yml",".stylelintrc.js","stylelint.config.js","stylelint.config.cjs"],T=e.readdirSync(h),K=!1,L=!1;for(let e=0,t=T.length;e<t;e++)S.includes(T[e])&&(L=!0),A.includes(T[e])&&(K=!0);K||(K=g),L||(L=y);let M=L?(await import("stylelint-webpack-plugin")).default:null,P=K?(await import("eslint-webpack-plugin")).default:null,F=l.assetHtml.map(e=>({publicPath:"",...e}));export const outputConfig={path:x("library"===d?"docs":"dist"),filename:"js/[name].bundle.js",chunkFilename:"js/[name].chunk.js",assetModuleFilename:"assets/[name][hash][ext][query]",library:{name:j,type:"window"},globalObject:"window",chunkLoadingGlobal:`webpackJsonp_${j}`,pathinfo:f,clean:!0,publicPath:i};let N=w("@app/entry");"single-component"===d&&(N=x(f?"example/index.ts":"src/index.ts"),outputConfig.path=x(f?"dist":"umd"),outputConfig.filename="index.js",outputConfig.globalObject="this",outputConfig.library={export:"default",name:j,type:"umd",umdNamedDefine:!0});let R={main:N};l.entry&&("string"==typeof l.entry?R=l.entry:Object.keys(l.entry)&&Object.assign(R,l.entry)),l.output&&("string"==typeof l.output?outputConfig.path=l.output:Object.keys(l.output)&&Object.assign(outputConfig,l.output));let W=l.routeBaseName.split("/").filter(Boolean).length,_=`${Array(W).fill("..").join("/")+(W?"/":"")}404.html`,{pathSegmentsToKeep:q=W,path:D=_}=l.fixBrowserRouter||{},G={entry:R,stats:"errors-only",infrastructureLogging:{level:"none"},target:"web",plugins:[new C,...u,P&&new P({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(m),l.fixBrowserRouter&&new s({filename:D,inject:!1,templateContent:()=>`<html html><head><title>${m.title}</title><script>var pathSegmentsToKeep = ${q||W};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(F),"single-spa"===d&&new p(e=>!!(e.match(/main\.(.*)\.bundle.js$/)||e.match("main.bundle.js"))),new O(r),new B({paths:[/\.d\.ts$/]}),l.sourceMap&&new $(l.sourceMap),l.bar&&new o(l.bar),new a({done:()=>{!f&&l.seo&&b(),l.done?.(),f||setTimeout(()=>{process.exit(0)},2e3)}}),new k(v),...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};export default G;
1
+ import fs from 'fs';
2
+ import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin';
3
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
4
+ import webpack from 'webpack';
5
+ import WebpackBar from 'webpackbar';
6
+ import './cleanup.js';
7
+ import { CONFIG, PUBLICPATH } from './common.js';
8
+ import define from './define.js';
9
+ import DoneWebpackPlugin from './done.js';
10
+ import AddEntryAttributeWebpackPlugin from './html-add-entry-attr.js';
11
+ import htmlPluginOption from './html-plugin-option.js';
12
+ import { moduleFederation } from './module-federation.js';
13
+ import moduleConfig from './module.config.js';
14
+ import { APPTYPE, DEV, PACKAGENAME, PROGRAMPATH, hasEslintConfig, hasStylelintConfig } from './process-env.js';
15
+ import { seo } from './seo.js';
16
+ import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
17
+ import VirtualModulePlugin from './virtual-module-plugin.js';
18
+ import virtualModules from './virtual-modules.js';
19
+ const { AutomaticPrefetchPlugin , DefinePlugin , SourceMapDevToolPlugin , WatchIgnorePlugin } = webpack;
20
+ const eslintrc = [
21
+ '.eslintrc.js',
22
+ '.eslintrc.json',
23
+ '.eslintrc.yaml',
24
+ '.eslintrc.json'
25
+ ];
26
+ const stylelintrc = [
27
+ '.stylelintrc',
28
+ '.stylelintrc.json',
29
+ '.stylelintrc.yaml',
30
+ '.stylelintrc.yml',
31
+ '.stylelintrc.js',
32
+ 'stylelint.config.js',
33
+ 'stylelint.config.cjs'
34
+ ];
35
+ const rootFiles = fs.readdirSync(PROGRAMPATH);
36
+ let hasEslint = false, hasStylelint = false;
37
+ for(let i = 0, len = rootFiles.length; i < len; i++){
38
+ if (stylelintrc.includes(rootFiles[i])) {
39
+ hasStylelint = true;
40
+ }
41
+ if (eslintrc.includes(rootFiles[i])) {
42
+ hasEslint = true;
43
+ }
44
+ }
45
+ if (!hasEslint) {
46
+ hasEslint = hasEslintConfig;
47
+ }
48
+ if (!hasStylelint) {
49
+ hasStylelint = hasStylelintConfig;
50
+ }
51
+ const StylelintPlugin = hasStylelint ? (await import('stylelint-webpack-plugin')).default : null;
52
+ const ESLintPlugin = hasEslint ? (await import('eslint-webpack-plugin')).default : null;
53
+ const assetHtmlOption = CONFIG.assetHtml.map((item)=>{
54
+ return {
55
+ publicPath: '',
56
+ ...item
57
+ };
58
+ });
59
+ export const outputConfig = {
60
+ path: resolveProgramPath(APPTYPE === 'library' ? 'docs' : 'dist'),
61
+ filename: 'js/[name].bundle.js',
62
+ chunkFilename: 'js/[name].chunk.js',
63
+ assetModuleFilename: 'assets/[name][hash][ext][query]',
64
+ library: {
65
+ name: PACKAGENAME,
66
+ type: 'window'
67
+ },
68
+ globalObject: 'window',
69
+ chunkLoadingGlobal: `webpackJsonp_${PACKAGENAME}`,
70
+ pathinfo: DEV,
71
+ clean: true,
72
+ publicPath: PUBLICPATH
73
+ };
74
+ let mainEntry = resolveNodeModulesPath('@app/entry');
75
+ if (APPTYPE === 'single-component') {
76
+ mainEntry = resolveProgramPath(DEV ? 'example/index.ts' : 'src/index.ts');
77
+ outputConfig.path = resolveProgramPath(DEV ? 'dist' : 'umd');
78
+ outputConfig.filename = 'index.js';
79
+ outputConfig.globalObject = 'this';
80
+ outputConfig.library = {
81
+ export: 'default',
82
+ name: PACKAGENAME,
83
+ type: 'umd',
84
+ umdNamedDefine: true
85
+ };
86
+ }
87
+ let entryMap = {
88
+ main: mainEntry
89
+ };
90
+ if (CONFIG.entry) {
91
+ if (typeof CONFIG.entry === 'string') {
92
+ entryMap = CONFIG.entry;
93
+ } else if (Object.keys(CONFIG.entry)) {
94
+ Object.assign(entryMap, CONFIG.entry);
95
+ }
96
+ }
97
+ if (CONFIG.output) {
98
+ if (typeof CONFIG.output === 'string') {
99
+ outputConfig.path = CONFIG.output;
100
+ } else if (Object.keys(CONFIG.output)) {
101
+ Object.assign(outputConfig, CONFIG.output);
102
+ }
103
+ }
104
+ const dirDeep = CONFIG.routeBaseName.split('/').filter(Boolean).length;
105
+ const page404 = `${Array(dirDeep).fill('..').join('/') + (dirDeep ? '/' : '')}404.html`;
106
+ const { pathSegmentsToKeep =dirDeep , path =page404 } = CONFIG.fixBrowserRouter || {};
107
+ export const clientConfig = {
108
+ entry: entryMap,
109
+ stats: 'errors-only',
110
+ infrastructureLogging: {
111
+ level: 'none'
112
+ },
113
+ target: 'web',
114
+ externalsPresets: CONFIG.externalsPresets,
115
+ plugins: [
116
+ new AutomaticPrefetchPlugin(),
117
+ ...moduleFederation,
118
+ ESLintPlugin && new ESLintPlugin({
119
+ fix: true,
120
+ threads: true,
121
+ extensions: [
122
+ 'js',
123
+ 'md',
124
+ 'mdx',
125
+ 'cjs',
126
+ 'ejs',
127
+ 'mjs',
128
+ 'jsx',
129
+ 'ts',
130
+ 'tsx',
131
+ 'json',
132
+ 'html',
133
+ 'coffee',
134
+ 'vue'
135
+ ]
136
+ }),
137
+ StylelintPlugin && new StylelintPlugin({
138
+ fix: true,
139
+ threads: true,
140
+ extensions: [
141
+ 'css',
142
+ 'scss',
143
+ 'sass',
144
+ 'less',
145
+ 'ts',
146
+ 'tsx',
147
+ 'js',
148
+ 'jsx'
149
+ ],
150
+ exclude: [
151
+ 'node_modules/',
152
+ 'es/',
153
+ 'lib/',
154
+ 'docs/',
155
+ 'coverage/',
156
+ 'dist/'
157
+ ]
158
+ }),
159
+ CONFIG.htmlPluginOption && new HtmlWebpackPlugin(htmlPluginOption),
160
+ CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
161
+ filename: path,
162
+ inject: false,
163
+ templateContent: ()=>`<html html><head><title>${htmlPluginOption.title}</title><script>var pathSegmentsToKeep = ${pathSegmentsToKeep || dirDeep};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>`
164
+ }),
165
+ new AddAssetHtmlPlugin(assetHtmlOption),
166
+ APPTYPE === 'single-spa' && new AddEntryAttributeWebpackPlugin((src)=>{
167
+ return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
168
+ }),
169
+ new DefinePlugin(define),
170
+ new WatchIgnorePlugin({
171
+ paths: [
172
+ /\.d\.ts$/
173
+ ]
174
+ }),
175
+ CONFIG.sourceMap && new SourceMapDevToolPlugin(CONFIG.sourceMap),
176
+ CONFIG.bar && new WebpackBar(CONFIG.bar),
177
+ new DoneWebpackPlugin({
178
+ done: ()=>{
179
+ if (!DEV && CONFIG.seo) {
180
+ seo();
181
+ }
182
+ CONFIG.done?.();
183
+ if (!DEV) {
184
+ setTimeout(()=>{
185
+ process.exit(0);
186
+ }, 2000);
187
+ }
188
+ }
189
+ }),
190
+ new VirtualModulePlugin(virtualModules),
191
+ ...CONFIG.plugins
192
+ ].filter(Boolean),
193
+ experiments: {
194
+ topLevelAwait: true,
195
+ syncWebAssembly: true,
196
+ asyncWebAssembly: true
197
+ },
198
+ resolve: {
199
+ extensions: [
200
+ '.tsx',
201
+ '.ts',
202
+ '.js',
203
+ '.jsx'
204
+ ],
205
+ alias: CONFIG.alias,
206
+ fallback: {
207
+ path: false,
208
+ fs: false,
209
+ crypto: false,
210
+ assert: false
211
+ }
212
+ },
213
+ module: moduleConfig,
214
+ externals: CONFIG.externals,
215
+ output: outputConfig
216
+ };
@@ -1,3 +1,3 @@
1
1
  import webpack from 'webpack';
2
- declare const _default: webpack.Configuration;
2
+ declare const _default: webpack.Configuration[];
3
3
  export default _default;
@@ -1,4 +1,97 @@
1
- import e from"@soda/friendly-errors-webpack-plugin";import o from"chalk";import r from"webpack";import{merge as t}from"webpack-merge";import{CONFIG as s}from"./common.js";import{hasPkg as a}from"./has-pkg.js";import{getIPv4 as p,getPort as i}from"./net.js";import{CUSTOMCONFIG as m,isReact as l}from"./process-env.js";import{isFunction as n,resolveProgramPath as c}from"./utils.js";import d from"./webpack.common.js";let{HotModuleReplacementPlugin:v}=r,{yellow:h,green:f}=o,w=p(),u=s.devServer.port||3e3,g=await i(u,65535,s.devServer.host),k=s.devServer.port!==g,y=a("@moneko/mock"),$=y&&await import("@moneko/mock"),S=l&&(await import("@pmmmwh/react-refresh-webpack-plugin")).default,b=!1;s.cacheDirectory&&(b={type:"filesystem",allowCollectingMemory:!0,cacheDirectory:s.cacheDirectory,name:`${m||"default"}-development`});let j=!1===s.devtool||s.devtool?s.devtool:"eval-cheap-module-source-map";s.devServer.port=g;let x="/"===s.routeBaseName,D=s.devServer.https?"https:":"http:",A=x?"":s.routeBaseName;export default t(d,{devtool:j,mode:"development",cache:b,devServer:{headers:{"Access-Control-Allow-Origin":"*"},compress:s.devServer.compress,host:"0.0.0.0",port:g,historyApiFallback:x||{index:A.endsWith("/")?A:`${A}/`,disableDotRule:!0},https:s.devServer.https,proxy:s.proxy,allowedHosts:s.devServer.allowedHosts,client:{progress:!1,logging:"info",overlay:!1},static:{watch:{ignored:e=>e.endsWith(".d.ts")||/\/node_modules\//.test(e)}},setupMiddlewares:(e,o)=>{if(!o)throw Error("webpack-dev-server is not defined");return o.app&&n($)&&$(o.app,c("mock/")),e},open:!1,hot:!0},plugins:[new v,S&&new S,new e({compilationSuccessInfo:{messages:[`You application is running here:
1
+ import FriendlyErrorsWebpackPlugin from '@soda/friendly-errors-webpack-plugin';
2
+ import chalk from 'chalk';
3
+ import webpack from 'webpack';
4
+ import { merge } from 'webpack-merge';
5
+ import { CONFIG } from './common.js';
6
+ import { hasPkg } from './has-pkg.js';
7
+ import { getIPv4, getPort } from './net.js';
8
+ import { CUSTOMCONFIG, isReact } from './process-env.js';
9
+ import { isFunction, resolveProgramPath } from './utils.js';
10
+ import { clientConfig } from './webpack.common.js';
11
+ const { HotModuleReplacementPlugin } = webpack;
12
+ const { yellow , green } = chalk;
13
+ const ip = getIPv4();
14
+ const oldPord = CONFIG.devServer.port || 3000;
15
+ const port = await getPort(oldPord, 65535, CONFIG.devServer.host);
16
+ const skipPort = CONFIG.devServer.port !== port;
17
+ const hasMockMiddlewares = hasPkg('@moneko/mock');
18
+ const mockMiddlewares = hasMockMiddlewares && await import('@moneko/mock');
19
+ const ReactRefresh = isReact && (await import('@pmmmwh/react-refresh-webpack-plugin')).default;
20
+ let cacheConfig = false;
21
+ if (CONFIG.cacheDirectory) {
22
+ cacheConfig = {
23
+ type: 'filesystem',
24
+ allowCollectingMemory: true,
25
+ cacheDirectory: CONFIG.cacheDirectory,
26
+ name: `${CUSTOMCONFIG || 'default'}-development`
27
+ };
28
+ }
29
+ const devtool = CONFIG.devtool === false || CONFIG.devtool ? CONFIG.devtool : 'eval-cheap-module-source-map';
30
+ CONFIG.devServer.port = port;
31
+ const initRouteBase = CONFIG.routeBaseName === '/';
32
+ const protocol = CONFIG.devServer.https ? 'https:' : 'http:';
33
+ const routeBase = initRouteBase ? '' : CONFIG.routeBaseName;
34
+ const client = merge(clientConfig, {
35
+ devtool: devtool,
36
+ mode: 'development',
37
+ cache: cacheConfig,
38
+ devServer: {
39
+ headers: {
40
+ 'Access-Control-Allow-Origin': '*'
41
+ },
42
+ compress: CONFIG.devServer.compress,
43
+ host: '0.0.0.0',
44
+ port: port,
45
+ historyApiFallback: initRouteBase || {
46
+ index: routeBase.endsWith('/') ? routeBase : `${routeBase}/`,
47
+ disableDotRule: true
48
+ },
49
+ https: CONFIG.devServer.https,
50
+ proxy: CONFIG.proxy,
51
+ allowedHosts: CONFIG.devServer.allowedHosts,
52
+ client: {
53
+ progress: false,
54
+ logging: 'info',
55
+ overlay: false
56
+ },
57
+ static: {
58
+ watch: {
59
+ ignored: (f)=>{
60
+ return f.endsWith('.d.ts') || /\/node_modules\//.test(f);
61
+ }
62
+ }
63
+ },
64
+ setupMiddlewares: (middlewares, devServer)=>{
65
+ if (!devServer) {
66
+ throw new Error('webpack-dev-server is not defined');
67
+ }
68
+ if (devServer.app && isFunction(mockMiddlewares)) {
69
+ mockMiddlewares(devServer.app, resolveProgramPath('mock/'));
70
+ }
71
+ return middlewares;
72
+ },
73
+ open: false,
74
+ hot: true
75
+ },
76
+ plugins: [
77
+ new HotModuleReplacementPlugin(),
78
+ ReactRefresh && new ReactRefresh(),
79
+ new FriendlyErrorsWebpackPlugin({
80
+ compilationSuccessInfo: {
81
+ messages: [
82
+ `You application is running here:
2
83
 
3
- Local: ${o.cyan(`${D}//${s.devServer.host}:${g}${A}`)}
4
- Network: ${o.cyan(`${D}//${w}:${g}${A}`)}`],notes:k?[`Port ${h(u)} is in use, trying ${f(g)} instead`]:[]},clearConsole:!0})].filter(Boolean)});
84
+ Local: ${chalk.cyan(`${protocol}//${CONFIG.devServer.host}:${port}${routeBase}`)}
85
+ Network: ${chalk.cyan(`${protocol}//${ip}:${port}${routeBase}`)}`
86
+ ],
87
+ notes: skipPort ? [
88
+ `Port ${yellow(oldPord)} is in use, trying ${green(port)} instead`
89
+ ] : []
90
+ },
91
+ clearConsole: true
92
+ })
93
+ ].filter(Boolean)
94
+ });
95
+ export default [
96
+ client
97
+ ];
@@ -1,3 +1,3 @@
1
1
  import webpack from 'webpack';
2
- declare const _default: webpack.Configuration;
2
+ declare const _default: webpack.Configuration[];
3
3
  export default _default;