@moneko/core 3.0.0-beta.30 → 3.0.0-beta.32
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 +175 -2
- package/lib/coverage.js +30 -1
- package/lib/done.js +12 -1
- package/lib/envFlags.js +48 -1
- package/lib/esm.js +7 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +22 -1
- package/lib/html-plugin-option.js +41 -1
- package/lib/index.js +4 -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 +184 -1
- package/lib/process-env.js +63 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.d.ts +1 -0
- package/lib/routes.js +171 -0
- package/lib/seo.js +57 -1
- package/lib/swcrc.js +107 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +64 -1
- package/lib/webpack.common.d.ts +1 -0
- package/lib/webpack.common.js +218 -1
- package/lib/webpack.dev.js +97 -3
- package/lib/webpack.prod.js +64 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +3 -3
package/lib/module.config.js
CHANGED
|
@@ -1 +1,184 @@
|
|
|
1
|
-
import
|
|
1
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
|
+
import svgToMiniDataURI from 'mini-svg-data-uri';
|
|
3
|
+
import { CONFIG, PUBLICPATH } from './common.js';
|
|
4
|
+
import { hasPkg } from './has-pkg.js';
|
|
5
|
+
import modifyVars from './modifyVars.js';
|
|
6
|
+
import { APPTYPE, DEV, FRAMEWORK } from './process-env.js';
|
|
7
|
+
import swcOption from './swcrc.js';
|
|
8
|
+
import tsLoaderConfig from './tsloader.config.js';
|
|
9
|
+
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
10
|
+
const cssAssetsPublicPath = APPTYPE === 'single-spa' ? PUBLICPATH : '../';
|
|
11
|
+
let styleLoader = {
|
|
12
|
+
loader: MiniCssExtractPlugin.loader,
|
|
13
|
+
options: {
|
|
14
|
+
publicPath: cssAssetsPublicPath !== '/' ? cssAssetsPublicPath : '../'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const postcssLoader = hasPkg('@moneko/postcss') && {
|
|
18
|
+
loader: 'postcss-loader',
|
|
19
|
+
options: {
|
|
20
|
+
postcssOptions: await import('@moneko/postcss')
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
if (DEV) {
|
|
24
|
+
styleLoader = 'style-loader';
|
|
25
|
+
}
|
|
26
|
+
const customCssModules = [
|
|
27
|
+
...CONFIG.cssModules,
|
|
28
|
+
`@moneko/${FRAMEWORK}`,
|
|
29
|
+
'neko-ui'
|
|
30
|
+
].map(resolveNodeModulesPath);
|
|
31
|
+
const styleResources = [
|
|
32
|
+
...[
|
|
33
|
+
'src/styles/variables/*.less',
|
|
34
|
+
'src/styles/mixins/*.less',
|
|
35
|
+
'site/styles/variables/*.less',
|
|
36
|
+
'site/styles/mixins/*.less'
|
|
37
|
+
].map(resolveProgramPath)
|
|
38
|
+
];
|
|
39
|
+
const entryResolveProgramPath = [
|
|
40
|
+
'components',
|
|
41
|
+
'example',
|
|
42
|
+
'mock',
|
|
43
|
+
'site',
|
|
44
|
+
'src'
|
|
45
|
+
].map(resolveProgramPath);
|
|
46
|
+
const lessLoaderRule = [
|
|
47
|
+
styleLoader,
|
|
48
|
+
{
|
|
49
|
+
loader: 'css-loader',
|
|
50
|
+
options: {
|
|
51
|
+
modules: {
|
|
52
|
+
auto: (resourcePath)=>{
|
|
53
|
+
for(let i = 0, len = customCssModules.length; i < len; i++){
|
|
54
|
+
if (resourcePath && resourcePath?.includes(customCssModules[i])) {
|
|
55
|
+
return /(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return /(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
|
|
59
|
+
},
|
|
60
|
+
localIdentName: '[path][name]__[local]',
|
|
61
|
+
exportLocalsConvention: 'dashesOnly'
|
|
62
|
+
},
|
|
63
|
+
importLoaders: 2
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
postcssLoader,
|
|
67
|
+
'css-unicode-loader',
|
|
68
|
+
{
|
|
69
|
+
loader: 'less-loader',
|
|
70
|
+
options: {
|
|
71
|
+
sourceMap: !!CONFIG.sourceMap,
|
|
72
|
+
lessOptions: {
|
|
73
|
+
modifyVars: modifyVars,
|
|
74
|
+
javascriptEnabled: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
loader: 'style-resources-loader',
|
|
80
|
+
options: {
|
|
81
|
+
patterns: styleResources
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
].filter(Boolean);
|
|
85
|
+
const tsLoader = {
|
|
86
|
+
loader: CONFIG.compiler === 'tsc' ? 'ts-loader' : 'swc-loader',
|
|
87
|
+
options: CONFIG.compiler === 'tsc' ? tsLoaderConfig : swcOption(DEV)
|
|
88
|
+
};
|
|
89
|
+
const moduleOptions = {
|
|
90
|
+
rules: [
|
|
91
|
+
{
|
|
92
|
+
oneOf: [
|
|
93
|
+
{
|
|
94
|
+
resourceQuery: /raw/,
|
|
95
|
+
type: 'asset/source'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
resourceQuery: /\.wasm$/,
|
|
99
|
+
type: 'webassembly/async'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
test: /\.less$/,
|
|
103
|
+
use: lessLoaderRule,
|
|
104
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.less?.map(resolveNodeModulesPath) || [])
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
test: /\.css$/,
|
|
108
|
+
use: [
|
|
109
|
+
styleLoader,
|
|
110
|
+
'css-loader',
|
|
111
|
+
postcssLoader,
|
|
112
|
+
'css-unicode-loader'
|
|
113
|
+
].filter(Boolean),
|
|
114
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.css?.map(resolveNodeModulesPath) || [])
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
test: /\.(gif|png|jpe?g|ico|mp4)$/i,
|
|
118
|
+
type: 'asset',
|
|
119
|
+
generator: {
|
|
120
|
+
filename: 'assets/images/[name][ext][query]'
|
|
121
|
+
},
|
|
122
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.media?.map(resolveNodeModulesPath) || [])
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
test: /\.(eot|ttf|otf|woff(|2))$/,
|
|
126
|
+
type: 'asset',
|
|
127
|
+
generator: {
|
|
128
|
+
filename: 'assets/fonts/[name][ext][query]'
|
|
129
|
+
},
|
|
130
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.fonts?.map(resolveNodeModulesPath) || [])
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
test: /\.svg$/,
|
|
134
|
+
type: 'asset/inline',
|
|
135
|
+
generator: {
|
|
136
|
+
dataUrl: (content)=>svgToMiniDataURI(typeof content !== 'string' ? content.toString() : content)
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
test: /\.txt$/,
|
|
141
|
+
type: 'asset/source'
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
test: /\.(cj|mj|t|j)s(|x)$/,
|
|
145
|
+
use: [
|
|
146
|
+
...CONFIG.prefixJsLoader,
|
|
147
|
+
tsLoader
|
|
148
|
+
].filter(Boolean),
|
|
149
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.js?.map(resolveNodeModulesPath) || [])
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
test: /\.mdx?$/,
|
|
153
|
+
use: [
|
|
154
|
+
...CONFIG.prefixJsLoader,
|
|
155
|
+
tsLoader,
|
|
156
|
+
{
|
|
157
|
+
loader: '@mdx-js/loader',
|
|
158
|
+
options: CONFIG.mdx
|
|
159
|
+
}
|
|
160
|
+
].filter(Boolean),
|
|
161
|
+
include: entryResolveProgramPath,
|
|
162
|
+
exclude: [
|
|
163
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
test: /\.mdx?$/,
|
|
168
|
+
type: 'asset/source',
|
|
169
|
+
include: [
|
|
170
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: 'asset/source',
|
|
175
|
+
include: [
|
|
176
|
+
/(.+)\/examples\/(.+).*?$/i
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
...CONFIG.moduleRules
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
export default moduleOptions;
|
package/lib/process-env.js
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
-
import{readFileSync
|
|
1
|
+
import { readFileSync, existsSync, mkdirSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import { hasPkg } from './has-pkg.js';
|
|
5
|
+
import { resolveProgramPath } from './utils.js';
|
|
6
|
+
import yarnArgv from './yarn-argv.js';
|
|
7
|
+
export const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
export const APPTYPE = process.env.APPTYPE;
|
|
9
|
+
export const FRAMEWORK = process.env.FRAMEWORK;
|
|
10
|
+
export const jsxImportSource = {
|
|
11
|
+
react: 'react',
|
|
12
|
+
'solid-js': 'solid-js/h'
|
|
13
|
+
}[FRAMEWORK];
|
|
14
|
+
export const PROGRAMPATH = process.cwd();
|
|
15
|
+
export const PACKAGENAME = process.env.npm_package_name;
|
|
16
|
+
export const PACKAGEVERSION = process.env.npm_package_version;
|
|
17
|
+
const pkg = readFileSync(join(__dirname, '../package.json'), {
|
|
18
|
+
encoding: 'utf-8'
|
|
19
|
+
});
|
|
20
|
+
export const cacheDir = join(PROGRAMPATH, './node_modules/.cache/@moneko/cli/');
|
|
21
|
+
if (!existsSync(cacheDir)) {
|
|
22
|
+
mkdirSync(cacheDir, {
|
|
23
|
+
recursive: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export const pkgName = JSON.parse(pkg).name;
|
|
27
|
+
export const NODE_ENV = process.env.NODE_ENV;
|
|
28
|
+
export const CUSTOMCONFIG = process.env.npm_config_config || yarnArgv.config;
|
|
29
|
+
export const DEV = process.env.NODE_ENV === 'development';
|
|
30
|
+
export let hasEslintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_eslintConfig_')).length;
|
|
31
|
+
export let hasStylelintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_stylelint_')).length;
|
|
32
|
+
export const hasAntd = hasPkg('antd');
|
|
33
|
+
export const programInfo = {
|
|
34
|
+
name: PACKAGENAME,
|
|
35
|
+
version: PACKAGEVERSION,
|
|
36
|
+
type: APPTYPE,
|
|
37
|
+
description: process.env.npm_package_description,
|
|
38
|
+
author: {
|
|
39
|
+
name: process.env.npm_package_author_name,
|
|
40
|
+
email: process.env.npm_package_author_email,
|
|
41
|
+
url: process.env.npm_package_author_url
|
|
42
|
+
},
|
|
43
|
+
repository: {
|
|
44
|
+
type: process.env.npm_package_repository_type,
|
|
45
|
+
url: process.env.npm_package_repository_url,
|
|
46
|
+
directory: process.env.npm_package_repository_directory
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (parseInt(process.versions.node) > 14) {
|
|
50
|
+
const ikpg = readFileSync(resolveProgramPath('package.json'), {
|
|
51
|
+
encoding: 'utf-8'
|
|
52
|
+
});
|
|
53
|
+
const { description , author , repository , eslintConfig , stylelint } = JSON.parse(ikpg);
|
|
54
|
+
programInfo.author = typeof author === 'string' ? {
|
|
55
|
+
name: author
|
|
56
|
+
} : author;
|
|
57
|
+
programInfo.repository = typeof author === 'string' ? {
|
|
58
|
+
url: repository
|
|
59
|
+
} : repository;
|
|
60
|
+
programInfo.description = description;
|
|
61
|
+
hasEslintConfig = !!eslintConfig;
|
|
62
|
+
hasStylelintConfig = !!stylelint;
|
|
63
|
+
}
|
package/lib/resolver-sync.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import enhancedResolve from 'enhanced-resolve';
|
|
3
|
+
const { CachedInputFileSystem , ResolverFactory } = enhancedResolve;
|
|
4
|
+
const resolverSync = ResolverFactory.createResolver({
|
|
5
|
+
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
6
|
+
conditionNames: [
|
|
7
|
+
'node'
|
|
8
|
+
],
|
|
9
|
+
extensions: [
|
|
10
|
+
'.js',
|
|
11
|
+
'.json',
|
|
12
|
+
'.node'
|
|
13
|
+
],
|
|
14
|
+
useSyncFileSystemCalls: true,
|
|
15
|
+
mainFields: [
|
|
16
|
+
'esm',
|
|
17
|
+
'module',
|
|
18
|
+
'main'
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
export default resolverSync;
|
package/lib/routes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const frameworkCacheDir: "~/node_modules/@moneko/react/.cache/" | "~/node_modules/@moneko/solid-js/.cache/";
|
package/lib/routes.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { readdirSync, statSync, writeFile, readFileSync, existsSync, mkdirSync } from 'fs';
|
|
2
|
+
import { join, relative } from 'path';
|
|
3
|
+
import { watch } from 'chokidar';
|
|
4
|
+
import { load } from 'js-yaml';
|
|
5
|
+
import { PROGRAMPATH, APPTYPE, FRAMEWORK, DEV } from './process-env.js';
|
|
6
|
+
import { resolveNodeModulesPath } from './utils.js';
|
|
7
|
+
const frontmatterRegex = /^---\n([\s\S]+?)\n---\n/;
|
|
8
|
+
function extractFrontmatter(md) {
|
|
9
|
+
const matches = md.match(frontmatterRegex);
|
|
10
|
+
return matches && matches[1] ? matches[1].trim() : null;
|
|
11
|
+
}
|
|
12
|
+
function extractCode(codeStr) {
|
|
13
|
+
const codes = {};
|
|
14
|
+
const regex = /```(.+?)\n([\s\S]*?)\n```/g;
|
|
15
|
+
let match;
|
|
16
|
+
while((match = regex.exec(codeStr)) !== null){
|
|
17
|
+
const [, language = 'jsx', source] = match;
|
|
18
|
+
const lang = language.split(' ').pop() || 'jsx';
|
|
19
|
+
codes[lang] = source.trim();
|
|
20
|
+
}
|
|
21
|
+
return Object.keys(codes).length ? codes : {
|
|
22
|
+
jsx: codeStr
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getTree(directory, option) {
|
|
26
|
+
const { regex , alia , base =directory , outputSource } = option;
|
|
27
|
+
const files = readdirSync(directory);
|
|
28
|
+
return files.reduce((tree, file)=>{
|
|
29
|
+
const filePath = join(directory, file);
|
|
30
|
+
const stats = statSync(filePath);
|
|
31
|
+
if (stats.isDirectory()) {
|
|
32
|
+
const children = getTree(filePath, {
|
|
33
|
+
...option,
|
|
34
|
+
base
|
|
35
|
+
});
|
|
36
|
+
if (children.length > 0) {
|
|
37
|
+
const item = {};
|
|
38
|
+
const baseItem = {
|
|
39
|
+
path: file,
|
|
40
|
+
key: relative(base, filePath)
|
|
41
|
+
};
|
|
42
|
+
if (outputSource) {
|
|
43
|
+
Object.assign(item, {
|
|
44
|
+
children
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
const frist = children.splice(0, 1)[0];
|
|
48
|
+
if (children.length) {
|
|
49
|
+
Object.assign(item, {
|
|
50
|
+
children: [
|
|
51
|
+
{
|
|
52
|
+
...frist,
|
|
53
|
+
path: '/',
|
|
54
|
+
key: baseItem.key
|
|
55
|
+
},
|
|
56
|
+
...children
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
Object.assign(item, frist);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
tree.push(Object.assign(item, baseItem));
|
|
64
|
+
}
|
|
65
|
+
} else if (regex.test(filePath)) {
|
|
66
|
+
const source = readFileSync(filePath, {
|
|
67
|
+
encoding: 'utf-8'
|
|
68
|
+
});
|
|
69
|
+
const frontmatter = extractFrontmatter(source);
|
|
70
|
+
const meta = frontmatter ? load(frontmatter) : {};
|
|
71
|
+
const reslove = relative(base, filePath);
|
|
72
|
+
tree.push(Object.assign({
|
|
73
|
+
path: file,
|
|
74
|
+
key: reslove,
|
|
75
|
+
meta: {
|
|
76
|
+
...meta
|
|
77
|
+
}
|
|
78
|
+
}, alia && {
|
|
79
|
+
element: `rr(() => import(/* webpackChunkName: '${reslove}' */'${join(alia, reslove)}'))rr`
|
|
80
|
+
}, outputSource && {
|
|
81
|
+
codes: extractCode(source.replace(frontmatterRegex, '').replace(/^\n+|\n+$/g, ''))
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return tree;
|
|
85
|
+
}, []);
|
|
86
|
+
}
|
|
87
|
+
const compPath = join(PROGRAMPATH, './components');
|
|
88
|
+
export const frameworkCacheDir = resolveNodeModulesPath(`@moneko/${FRAMEWORK}/.cache/`);
|
|
89
|
+
let genLibRouteTimer;
|
|
90
|
+
function fallback(err) {
|
|
91
|
+
if (err) {
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function generatorLibraryRouter() {
|
|
96
|
+
if (genLibRouteTimer) {
|
|
97
|
+
clearTimeout(genLibRouteTimer);
|
|
98
|
+
}
|
|
99
|
+
genLibRouteTimer = setTimeout(()=>{
|
|
100
|
+
let replaceStr = 'lazy($1)';
|
|
101
|
+
let prefixStr = `import { lazy } from "${FRAMEWORK}";`;
|
|
102
|
+
if (![
|
|
103
|
+
'react',
|
|
104
|
+
'solid-js'
|
|
105
|
+
].includes(FRAMEWORK)) {
|
|
106
|
+
replaceStr = '$1';
|
|
107
|
+
prefixStr = '';
|
|
108
|
+
}
|
|
109
|
+
const tree = JSON.stringify(getTree(compPath, {
|
|
110
|
+
regex: /README\.mdx?$/,
|
|
111
|
+
alia: '@pkg'
|
|
112
|
+
})).replace(/"rr\((.+?)\)rr"/g, replaceStr);
|
|
113
|
+
if (!existsSync(frameworkCacheDir)) {
|
|
114
|
+
mkdirSync(frameworkCacheDir);
|
|
115
|
+
}
|
|
116
|
+
writeFile(join(frameworkCacheDir, 'router.js'), `${prefixStr}export default ${tree}`, 'utf-8', fallback);
|
|
117
|
+
}, 100);
|
|
118
|
+
}
|
|
119
|
+
let genLibDemoTimer;
|
|
120
|
+
function generatorLibraryDemo() {
|
|
121
|
+
if (genLibDemoTimer) {
|
|
122
|
+
clearTimeout(genLibDemoTimer);
|
|
123
|
+
}
|
|
124
|
+
genLibDemoTimer = setTimeout(()=>{
|
|
125
|
+
const tree = Object.fromEntries(getTree(compPath, {
|
|
126
|
+
regex: /\/examples\/(.+)\.mdx$/,
|
|
127
|
+
outputSource: true
|
|
128
|
+
}).map((item)=>[
|
|
129
|
+
item.key,
|
|
130
|
+
item.children?.[0].children?.map((e)=>({
|
|
131
|
+
title: e.path,
|
|
132
|
+
...e.meta,
|
|
133
|
+
codes: e.codes
|
|
134
|
+
}))
|
|
135
|
+
]));
|
|
136
|
+
if (!existsSync(frameworkCacheDir)) {
|
|
137
|
+
mkdirSync(frameworkCacheDir);
|
|
138
|
+
}
|
|
139
|
+
writeFile(join(frameworkCacheDir, 'examples.js'), `export default ${JSON.stringify(tree)}`, 'utf-8', fallback);
|
|
140
|
+
}, 100);
|
|
141
|
+
}
|
|
142
|
+
function watchFiles(root, ignored, call) {
|
|
143
|
+
const ignoredRouter = (src, stats)=>{
|
|
144
|
+
if (stats) {
|
|
145
|
+
if (stats?.isDirectory()) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return ignored.test(src);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const watcher = watch(root, {
|
|
152
|
+
ignored: ignoredRouter,
|
|
153
|
+
persistent: true
|
|
154
|
+
});
|
|
155
|
+
watcher.on('add', ()=>{
|
|
156
|
+
call();
|
|
157
|
+
}).on('change', ()=>{
|
|
158
|
+
call();
|
|
159
|
+
}).on('unlink', ()=>{
|
|
160
|
+
call();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (APPTYPE === 'library') {
|
|
164
|
+
if (DEV) {
|
|
165
|
+
watchFiles(compPath, /(?<!README\.mdx?)$/, generatorLibraryRouter);
|
|
166
|
+
watchFiles(compPath, /(?<!\/examples\/(.+)\.mdx)$/, generatorLibraryDemo);
|
|
167
|
+
} else {
|
|
168
|
+
generatorLibraryRouter();
|
|
169
|
+
generatorLibraryDemo();
|
|
170
|
+
}
|
|
171
|
+
}
|
package/lib/seo.js
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, mkdirSync, writeFile, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { CONFIG } from './common.js';
|
|
4
|
+
import { APPTYPE, PROGRAMPATH } from './process-env.js';
|
|
5
|
+
import { resolveProgramPath } from './utils.js';
|
|
6
|
+
import { outputConfig } from './webpack.common.js';
|
|
7
|
+
function getLibDocsPages(dir, domain, basename) {
|
|
8
|
+
let results = [];
|
|
9
|
+
const list = readdirSync(dir);
|
|
10
|
+
list.forEach(function(_file) {
|
|
11
|
+
if (_file === 'static') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const file = dir + '/' + _file;
|
|
15
|
+
const stat = statSync(file);
|
|
16
|
+
if (stat && stat.isDirectory()) {
|
|
17
|
+
results = results.concat(getLibDocsPages(file, domain, basename));
|
|
18
|
+
} else if (file.endsWith('README.mdx')) {
|
|
19
|
+
results.push('https://' + domain + basename + file.replace(PROGRAMPATH + '/components/', '').replace('/README.mdx', ''));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
export const seo = ()=>{
|
|
25
|
+
const { domain , nojekyll , path } = CONFIG.seo || {};
|
|
26
|
+
if (!domain) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const baseDir = path && resolveProgramPath(path) || outputConfig?.path || process.cwd();
|
|
30
|
+
const call = (err)=>{
|
|
31
|
+
if (err) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
if (!existsSync(baseDir)) {
|
|
36
|
+
mkdirSync(baseDir);
|
|
37
|
+
}
|
|
38
|
+
writeFile(join(baseDir, 'CNAME'), domain, 'utf-8', call);
|
|
39
|
+
writeFile(join(baseDir, 'robots'), `Sitemap: https://${domain}${CONFIG.routeBaseName}sitemap.txt`, 'utf-8', call);
|
|
40
|
+
let sitemap = '';
|
|
41
|
+
switch(APPTYPE){
|
|
42
|
+
case 'library':
|
|
43
|
+
sitemap = getLibDocsPages(join(PROGRAMPATH, './components'), domain, CONFIG.routeBaseName).join('\n');
|
|
44
|
+
break;
|
|
45
|
+
case 'single-component':
|
|
46
|
+
case 'mobile':
|
|
47
|
+
case 'site':
|
|
48
|
+
case 'back-stage':
|
|
49
|
+
case 'single-spa':
|
|
50
|
+
default:
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
writeFile(join(baseDir, 'sitemap.txt'), sitemap, 'utf-8', call);
|
|
54
|
+
if (nojekyll) {
|
|
55
|
+
writeFile(join(baseDir, '.nojekyll'), '', 'utf-8', call);
|
|
56
|
+
}
|
|
57
|
+
};
|
package/lib/swcrc.js
CHANGED
|
@@ -1 +1,107 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { merge } from 'webpack-merge';
|
|
2
|
+
import { CONFIG } from './common.js';
|
|
3
|
+
import envFlags from './envFlags.js';
|
|
4
|
+
import { FRAMEWORK, jsxImportSource } from './process-env.js';
|
|
5
|
+
const swcPolyfill = {
|
|
6
|
+
env: {
|
|
7
|
+
targets: [
|
|
8
|
+
'last 2 version',
|
|
9
|
+
'> 0.5%',
|
|
10
|
+
'ie 11',
|
|
11
|
+
'not dead'
|
|
12
|
+
],
|
|
13
|
+
mode: 'entry',
|
|
14
|
+
coreJs: '3'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const swcMinifyOption = {
|
|
18
|
+
compress: {
|
|
19
|
+
top_retain: [],
|
|
20
|
+
keep_infinity: true,
|
|
21
|
+
global_defs: {
|
|
22
|
+
'@alert': 'console.log'
|
|
23
|
+
},
|
|
24
|
+
pure_funcs: [
|
|
25
|
+
'console.log',
|
|
26
|
+
'console.warn',
|
|
27
|
+
'console.error',
|
|
28
|
+
'console.info'
|
|
29
|
+
],
|
|
30
|
+
toplevel: false,
|
|
31
|
+
drop_console: true,
|
|
32
|
+
drop_debugger: true,
|
|
33
|
+
module: false,
|
|
34
|
+
ecma: 2015,
|
|
35
|
+
ie8: false,
|
|
36
|
+
keep_classnames: undefined,
|
|
37
|
+
keep_fnames: false
|
|
38
|
+
},
|
|
39
|
+
mangle: true
|
|
40
|
+
};
|
|
41
|
+
function transformConfigs(config) {
|
|
42
|
+
for(let i = 0, ks = Object.keys(config), l = ks.length; i < l; i++){
|
|
43
|
+
config[ks[i]].transform = `${ks[i]}/${config[ks[i]].transform}`;
|
|
44
|
+
if (config[ks[i]].style) {
|
|
45
|
+
config[ks[i]].style = `${ks[i]}/${config[ks[i]].style}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
export default ((isDev = false)=>{
|
|
51
|
+
const swcOption = {
|
|
52
|
+
module: {
|
|
53
|
+
type: 'es6',
|
|
54
|
+
ignoreDynamic: true,
|
|
55
|
+
strict: true,
|
|
56
|
+
strictMode: true,
|
|
57
|
+
lazy: true,
|
|
58
|
+
noInterop: true
|
|
59
|
+
},
|
|
60
|
+
jsc: {
|
|
61
|
+
parser: {
|
|
62
|
+
syntax: 'typescript',
|
|
63
|
+
decorators: true,
|
|
64
|
+
dynamicImport: true,
|
|
65
|
+
tsx: true
|
|
66
|
+
},
|
|
67
|
+
loose: true,
|
|
68
|
+
target: 'es2022',
|
|
69
|
+
externalHelpers: true,
|
|
70
|
+
transform: {
|
|
71
|
+
legacyDecorator: true,
|
|
72
|
+
decoratorMetadata: true,
|
|
73
|
+
react: {
|
|
74
|
+
runtime: 'automatic',
|
|
75
|
+
throwIfNamespace: true,
|
|
76
|
+
useBuiltins: true,
|
|
77
|
+
refresh: FRAMEWORK === 'react' && isDev,
|
|
78
|
+
development: isDev,
|
|
79
|
+
importSource: jsxImportSource
|
|
80
|
+
},
|
|
81
|
+
constModules: {
|
|
82
|
+
globals: {
|
|
83
|
+
'env-flags': envFlags
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
optimizer: {
|
|
87
|
+
simplify: false
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
experimental: {
|
|
91
|
+
plugins: [
|
|
92
|
+
[
|
|
93
|
+
'swc-plugin-another-transform-imports',
|
|
94
|
+
transformConfigs(CONFIG.importOnDemand || {})
|
|
95
|
+
]
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
sourceMaps: true,
|
|
100
|
+
parseMap: true
|
|
101
|
+
};
|
|
102
|
+
let swcrc = Object.assign(swcOption, !isDev && swcPolyfill);
|
|
103
|
+
if (CONFIG.swcrc) {
|
|
104
|
+
swcrc = merge(swcrc, typeof CONFIG.swcrc === 'function' ? CONFIG.swcrc(isDev) : CONFIG.swcrc);
|
|
105
|
+
}
|
|
106
|
+
return swcrc;
|
|
107
|
+
});
|
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, resolveProgramPath, readConf } 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;
|