@moneko/core 3.0.0-beta.103 → 3.0.0-beta.104
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/app.js +22 -1
- package/lib/cleanup.js +19 -1
- package/lib/common/rem.js +5 -4
- package/lib/common.d.ts +1 -0
- package/lib/common.js +241 -2
- package/lib/coverage.js +30 -1
- package/lib/define.js +9 -1
- package/lib/docs.js +113 -1
- package/lib/done.js +12 -1
- package/lib/esm.js +7 -1
- package/lib/generate-api.js +330 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +24 -1
- package/lib/html-plugin-option.js +44 -1
- package/lib/index.js +3 -1
- package/lib/minify.js +46 -1
- package/lib/modifyVars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +211 -1
- package/lib/net.js +33 -1
- package/lib/object-listener.js +28 -1
- package/lib/process-env.js +65 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.js +187 -1
- package/lib/seo.js +39 -1
- package/lib/swcrc.js +105 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +49 -1
- package/lib/virtual-module-plugin.js +54 -1
- package/lib/virtual-modules.js +34 -3
- package/lib/webpack.common.d.ts +0 -1
- package/lib/webpack.common.js +216 -1
- package/lib/webpack.dev.js +93 -3
- package/lib/webpack.prod.js +67 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +3 -3
package/lib/swcrc.js
CHANGED
|
@@ -1 +1,105 @@
|
|
|
1
|
-
import{
|
|
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
|
+
});
|
package/lib/tsloader.config.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import
|
|
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
|
|
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
|
|
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;
|
package/lib/virtual-modules.js
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
import{accessSync
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
package/lib/webpack.common.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import './cleanup.js';
|
|
2
2
|
import type { WebpackConfiguration } from 'webpack-dev-server';
|
|
3
|
-
export declare const alias: Record<string, string>;
|
|
4
3
|
export declare const outputConfig: WebpackConfiguration['output'];
|
|
5
4
|
declare const config: WebpackConfiguration;
|
|
6
5
|
export default config;
|
package/lib/webpack.common.js
CHANGED
|
@@ -1 +1,216 @@
|
|
|
1
|
-
import
|
|
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
|
+
const config = {
|
|
108
|
+
entry: entryMap,
|
|
109
|
+
stats: 'errors-only',
|
|
110
|
+
infrastructureLogging: {
|
|
111
|
+
level: 'none'
|
|
112
|
+
},
|
|
113
|
+
target: 'web',
|
|
114
|
+
plugins: [
|
|
115
|
+
new AutomaticPrefetchPlugin(),
|
|
116
|
+
...moduleFederation,
|
|
117
|
+
ESLintPlugin && new ESLintPlugin({
|
|
118
|
+
fix: true,
|
|
119
|
+
threads: true,
|
|
120
|
+
extensions: [
|
|
121
|
+
'js',
|
|
122
|
+
'md',
|
|
123
|
+
'mdx',
|
|
124
|
+
'cjs',
|
|
125
|
+
'ejs',
|
|
126
|
+
'mjs',
|
|
127
|
+
'jsx',
|
|
128
|
+
'ts',
|
|
129
|
+
'tsx',
|
|
130
|
+
'json',
|
|
131
|
+
'html',
|
|
132
|
+
'coffee',
|
|
133
|
+
'vue'
|
|
134
|
+
]
|
|
135
|
+
}),
|
|
136
|
+
StylelintPlugin && new StylelintPlugin({
|
|
137
|
+
fix: true,
|
|
138
|
+
threads: true,
|
|
139
|
+
extensions: [
|
|
140
|
+
'css',
|
|
141
|
+
'scss',
|
|
142
|
+
'sass',
|
|
143
|
+
'less',
|
|
144
|
+
'ts',
|
|
145
|
+
'tsx',
|
|
146
|
+
'js',
|
|
147
|
+
'jsx'
|
|
148
|
+
],
|
|
149
|
+
exclude: [
|
|
150
|
+
'node_modules/',
|
|
151
|
+
'es/',
|
|
152
|
+
'lib/',
|
|
153
|
+
'docs/',
|
|
154
|
+
'coverage/',
|
|
155
|
+
'dist/'
|
|
156
|
+
]
|
|
157
|
+
}),
|
|
158
|
+
CONFIG.htmlPluginOption && new HtmlWebpackPlugin(htmlPluginOption),
|
|
159
|
+
CONFIG.fixBrowserRouter && new HtmlWebpackPlugin({
|
|
160
|
+
filename: path,
|
|
161
|
+
inject: false,
|
|
162
|
+
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>`
|
|
163
|
+
}),
|
|
164
|
+
new AddAssetHtmlPlugin(assetHtmlOption),
|
|
165
|
+
APPTYPE === 'single-spa' && new AddEntryAttributeWebpackPlugin((src)=>{
|
|
166
|
+
return !!(src.match(/main\.(.*)\.bundle.js$/) || src.match('main.bundle.js'));
|
|
167
|
+
}),
|
|
168
|
+
new DefinePlugin(define),
|
|
169
|
+
new WatchIgnorePlugin({
|
|
170
|
+
paths: [
|
|
171
|
+
/\.d\.ts$/
|
|
172
|
+
]
|
|
173
|
+
}),
|
|
174
|
+
CONFIG.sourceMap && new SourceMapDevToolPlugin(CONFIG.sourceMap),
|
|
175
|
+
CONFIG.bar && new WebpackBar(CONFIG.bar),
|
|
176
|
+
new DoneWebpackPlugin({
|
|
177
|
+
done: ()=>{
|
|
178
|
+
if (!DEV && CONFIG.seo) {
|
|
179
|
+
seo();
|
|
180
|
+
}
|
|
181
|
+
CONFIG.done?.();
|
|
182
|
+
if (!DEV) {
|
|
183
|
+
setTimeout(()=>{
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}, 2000);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}),
|
|
189
|
+
new VirtualModulePlugin(virtualModules),
|
|
190
|
+
...CONFIG.plugins
|
|
191
|
+
].filter(Boolean),
|
|
192
|
+
experiments: {
|
|
193
|
+
topLevelAwait: true,
|
|
194
|
+
syncWebAssembly: true,
|
|
195
|
+
asyncWebAssembly: true
|
|
196
|
+
},
|
|
197
|
+
resolve: {
|
|
198
|
+
extensions: [
|
|
199
|
+
'.tsx',
|
|
200
|
+
'.ts',
|
|
201
|
+
'.js',
|
|
202
|
+
'.jsx'
|
|
203
|
+
],
|
|
204
|
+
alias: CONFIG.alias,
|
|
205
|
+
fallback: {
|
|
206
|
+
path: false,
|
|
207
|
+
fs: false,
|
|
208
|
+
crypto: false,
|
|
209
|
+
assert: false
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
module: moduleConfig,
|
|
213
|
+
externals: CONFIG.externals,
|
|
214
|
+
output: outputConfig
|
|
215
|
+
};
|
|
216
|
+
export default config;
|
package/lib/webpack.dev.js
CHANGED
|
@@ -1,4 +1,94 @@
|
|
|
1
|
-
import
|
|
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 common 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
|
+
export default merge(common, {
|
|
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: ${
|
|
4
|
-
Network: ${
|
|
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
|
+
});
|