lvyjs 0.2.19 → 0.2.21
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.js +3 -0
- package/lib/index.js +3 -70
- package/lib/rullup/index.js +8 -4
- package/lib/start.js +69 -0
- package/lib/store.d.ts +3 -0
- package/lib/store.js +6 -0
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -7,6 +7,9 @@ const stylesRegExp = /\.(css|scss|less|sass|less)$/;
|
|
|
7
7
|
*/
|
|
8
8
|
const createAlias = val => {
|
|
9
9
|
const alias = {};
|
|
10
|
+
if (!Array.isArray(val.entries)) {
|
|
11
|
+
return alias;
|
|
12
|
+
}
|
|
10
13
|
// 遍历 entries 数组
|
|
11
14
|
val.entries.forEach(entry => {
|
|
12
15
|
alias[entry.find] = entry.replacement;
|
package/lib/index.js
CHANGED
|
@@ -1,73 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export { defineConfig, getOptions } from './store.js';
|
|
1
|
+
import { main } from './start.js';
|
|
2
|
+
export { defineConfig, getOptions, initConfig } from './store.js';
|
|
3
|
+
export { buildAndRun, buildJS } from './rullup/index.js';
|
|
5
4
|
export { assetsRegExp, convertPath, createAlias, isWin32, stylesRegExp } from './config.js';
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* @param input
|
|
9
|
-
*/
|
|
10
|
-
const onDev = async () => {
|
|
11
|
-
const apps = [];
|
|
12
|
-
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
13
|
-
// 修改config
|
|
14
|
-
for (const plugin of global.lvyConfig.plugins) {
|
|
15
|
-
if (!plugin) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
await apps.push(plugin(global.lvyConfig));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// 执行loader
|
|
22
|
-
await import('./main.js');
|
|
23
|
-
//
|
|
24
|
-
for (const app of apps) {
|
|
25
|
-
if (!app) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (typeof app == 'function') {
|
|
29
|
-
await app(global.lvyConfig);
|
|
30
|
-
}
|
|
31
|
-
else if (typeof app.load == 'function') {
|
|
32
|
-
app.load(global.lvyConfig);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* @param input
|
|
38
|
-
*/
|
|
39
|
-
const onBuild = async () => {
|
|
40
|
-
const apps = [];
|
|
41
|
-
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
42
|
-
// 修改config
|
|
43
|
-
for (const plugin of global.lvyConfig.plugins) {
|
|
44
|
-
if (!plugin) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
await apps.push(plugin(global.lvyConfig));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//
|
|
51
|
-
for (const app of apps) {
|
|
52
|
-
if (!app) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (typeof app != 'function' && typeof app.build == 'function') {
|
|
56
|
-
await app.build(global.lvyConfig);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const main = async () => {
|
|
61
|
-
if (process.argv.includes('--lvy-dev')) {
|
|
62
|
-
await initConfig();
|
|
63
|
-
await onDev();
|
|
64
|
-
}
|
|
65
|
-
else if (process.argv.includes('--lvy-build')) {
|
|
66
|
-
await initConfig();
|
|
67
|
-
await onBuild();
|
|
68
|
-
buildAndRun();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
6
|
main();
|
|
72
|
-
|
|
73
|
-
export { buildAndRun, initConfig };
|
package/lib/rullup/index.js
CHANGED
|
@@ -54,6 +54,9 @@ const buildJS = async (inputs) => {
|
|
|
54
54
|
plugins.push(rollupStylesCSSImport(global.lvyConfig.styles));
|
|
55
55
|
}
|
|
56
56
|
plugins.push(json());
|
|
57
|
+
const OutputOptions = global.lvyConfig?.build?.OutputOptions ?? [];
|
|
58
|
+
// 获取 dir 的值
|
|
59
|
+
const outputDir = OutputOptions['dir'] || 'lib';
|
|
57
60
|
if (typeof global.lvyConfig.build != 'boolean') {
|
|
58
61
|
//
|
|
59
62
|
for (const key in global.lvyConfig.build) {
|
|
@@ -64,7 +67,11 @@ const buildJS = async (inputs) => {
|
|
|
64
67
|
plugins.push(commonjs(global.lvyConfig.build[key]));
|
|
65
68
|
}
|
|
66
69
|
else if (key == 'typescript' && !global.lvyConfig.build['@rollup/plugin-typescript']) {
|
|
67
|
-
|
|
70
|
+
const config = global.lvyConfig.build[key] || {};
|
|
71
|
+
if (config.declarationDir === undefined) {
|
|
72
|
+
config.declarationDir = outputDir;
|
|
73
|
+
}
|
|
74
|
+
plugins.push(typescript(config));
|
|
68
75
|
}
|
|
69
76
|
else if (key == 'OutputOptions') {
|
|
70
77
|
continue;
|
|
@@ -103,9 +110,6 @@ const buildJS = async (inputs) => {
|
|
|
103
110
|
...RollupOptions,
|
|
104
111
|
plugins: Array.isArray(pl) ? [...plugins, ...pl] : pl
|
|
105
112
|
});
|
|
106
|
-
const OutputOptions = global.lvyConfig?.build?.OutputOptions ?? [];
|
|
107
|
-
// 获取 dir 的值
|
|
108
|
-
const outputDir = OutputOptions['dir'] || 'lib';
|
|
109
113
|
// 写入输出文件
|
|
110
114
|
const { output } = await bundle.write({
|
|
111
115
|
dir: outputDir,
|
package/lib/start.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { buildAndRun } from './rullup/index.js';
|
|
2
|
+
import { initConfig } from './store.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param input
|
|
6
|
+
*/
|
|
7
|
+
const onDev = async () => {
|
|
8
|
+
const apps = [];
|
|
9
|
+
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
10
|
+
// 修改config
|
|
11
|
+
for (const plugin of global.lvyConfig.plugins) {
|
|
12
|
+
if (!plugin) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
await apps.push(plugin(global.lvyConfig));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// 执行loader
|
|
19
|
+
await import('./main.js');
|
|
20
|
+
//
|
|
21
|
+
for (const app of apps) {
|
|
22
|
+
if (!app) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (typeof app == 'function') {
|
|
26
|
+
await app(global.lvyConfig);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof app.load == 'function') {
|
|
29
|
+
app.load(global.lvyConfig);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @param input
|
|
35
|
+
*/
|
|
36
|
+
const onBuild = async () => {
|
|
37
|
+
const apps = [];
|
|
38
|
+
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
39
|
+
// 修改config
|
|
40
|
+
for (const plugin of global.lvyConfig.plugins) {
|
|
41
|
+
if (!plugin) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
await apps.push(plugin(global.lvyConfig));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//
|
|
48
|
+
for (const app of apps) {
|
|
49
|
+
if (!app) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (typeof app != 'function' && typeof app.build == 'function') {
|
|
53
|
+
await app.build(global.lvyConfig);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const main = async () => {
|
|
58
|
+
if (process.argv.includes('--lvy-dev')) {
|
|
59
|
+
await initConfig();
|
|
60
|
+
await onDev();
|
|
61
|
+
}
|
|
62
|
+
else if (process.argv.includes('--lvy-build')) {
|
|
63
|
+
await initConfig();
|
|
64
|
+
await onBuild();
|
|
65
|
+
buildAndRun();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { main };
|
package/lib/store.d.ts
CHANGED
package/lib/store.js
CHANGED
|
@@ -25,6 +25,12 @@ const initConfig = async () => {
|
|
|
25
25
|
const v = await import(`file://${join(process.cwd(), configDir)}`);
|
|
26
26
|
if (v?.default) {
|
|
27
27
|
global.lvyConfig = v.default;
|
|
28
|
+
if (global.lvyConfig?.env) {
|
|
29
|
+
for (const key in global.lvyConfig.env) {
|
|
30
|
+
process.env[key] = String(global.lvyConfig.env[key]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
process.env.NODE_ENV = process.env?.NODE_ENV || 'development';
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
};
|