@varlet/cli 2.7.0-alpha.1673617166404 → 2.7.0-alpha.1673623558342
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/node/bin.js +2 -3
- package/lib/node/commands/compile.d.ts +1 -5
- package/lib/node/commands/compile.js +4 -5
- package/lib/node/compiler/compileModule.d.ts +1 -2
- package/lib/node/compiler/compileModule.js +30 -14
- package/lib/node/compiler/compileTypes.js +1 -0
- package/lib/node/config/vite.config.d.ts +7 -2
- package/lib/node/config/vite.config.js +14 -46
- package/package.json +7 -7
package/lib/node/bin.js
CHANGED
|
@@ -42,10 +42,9 @@ program
|
|
|
42
42
|
program
|
|
43
43
|
.command('compile')
|
|
44
44
|
.description('Compile varlet components library code')
|
|
45
|
-
.
|
|
46
|
-
.action(async (options) => {
|
|
45
|
+
.action(async () => {
|
|
47
46
|
const { compile } = await import('./commands/compile.js');
|
|
48
|
-
return compile(
|
|
47
|
+
return compile();
|
|
49
48
|
});
|
|
50
49
|
program
|
|
51
50
|
.command('lint')
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
export declare function removeDir(): Promise<[void, void, void, void]>;
|
|
2
2
|
export declare function runTask(taskName: string, task: () => any): Promise<void>;
|
|
3
|
-
|
|
4
|
-
noUmd?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function compile(options: CompileCommandOptions): Promise<void>;
|
|
7
|
-
export {};
|
|
3
|
+
export declare function compile(): Promise<void>;
|
|
@@ -20,18 +20,17 @@ export async function runTask(taskName, task) {
|
|
|
20
20
|
logger.error(e.toString());
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
export async function compile(
|
|
23
|
+
export async function compile() {
|
|
24
24
|
process.env.NODE_ENV = 'compile';
|
|
25
25
|
await removeDir();
|
|
26
26
|
await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
|
|
27
27
|
process.env.TARGET_MODULE = 'module';
|
|
28
28
|
process.env.BABEL_MODULE = 'module';
|
|
29
29
|
await runTask('module', compileModule);
|
|
30
|
-
process.env.TARGET_MODULE = 'esm-bundle';
|
|
31
|
-
await runTask('esm bundle', compileModule);
|
|
32
30
|
process.env.TARGET_MODULE = 'commonjs';
|
|
33
31
|
process.env.BABEL_MODULE = 'commonjs';
|
|
34
32
|
await runTask('commonjs', compileModule);
|
|
35
|
-
process.env.
|
|
36
|
-
|
|
33
|
+
process.env.BABEL_MODULE = '';
|
|
34
|
+
process.env.TARGET_MODULE = 'bundle';
|
|
35
|
+
await runTask('bundle', compileModule);
|
|
37
36
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function compileESMBundle(): Promise<void>;
|
|
1
|
+
export declare function compileBundle(): Promise<void>;
|
|
3
2
|
export declare function compileDir(dir: string): Promise<void>;
|
|
4
3
|
export declare function compileFile(file: string): Promise<void>;
|
|
5
4
|
export declare function compileModule(): Promise<void>;
|
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
2
|
import { build } from 'vite';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
|
-
import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, } from '../shared/constant.js';
|
|
4
|
+
import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, UMD_DIR, } from '../shared/constant.js';
|
|
5
5
|
import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
|
|
6
6
|
import { compileSFC } from './compileSFC.js';
|
|
7
7
|
import { compileESEntry, compileCommonJSEntry, compileScriptFile, getScriptExtname } from './compileScript.js';
|
|
8
8
|
import { clearLessFiles, compileLess } from './compileStyle.js';
|
|
9
|
-
import {
|
|
9
|
+
import { getBundleConfig } from '../config/vite.config.js';
|
|
10
10
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
11
11
|
import { generateReference } from './compileTypes.js';
|
|
12
|
+
import { get } from 'lodash-es';
|
|
13
|
+
import { kebabCase } from '@varlet/shared';
|
|
12
14
|
const { copy, ensureFileSync, readdir, removeSync } = fse;
|
|
13
|
-
export async function
|
|
15
|
+
export async function compileBundle() {
|
|
14
16
|
const varletConfig = await getVarletConfig();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const name = kebabCase(get(varletConfig, 'name'));
|
|
18
|
+
const buildOptions = [
|
|
19
|
+
{
|
|
20
|
+
format: 'es',
|
|
21
|
+
fileName: `${name}.esm.js`,
|
|
22
|
+
output: ES_DIR,
|
|
23
|
+
emptyOutDir: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
format: 'cjs',
|
|
27
|
+
fileName: `${name}.cjs.js`,
|
|
28
|
+
output: LIB_DIR,
|
|
29
|
+
emptyOutDir: false,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
format: 'umd',
|
|
33
|
+
fileName: `${name}.js`,
|
|
34
|
+
output: UMD_DIR,
|
|
35
|
+
emptyOutDir: true,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const tasks = buildOptions.map((options) => build(getBundleConfig(varletConfig, options)));
|
|
39
|
+
await Promise.all(tasks);
|
|
20
40
|
}
|
|
21
41
|
export async function compileDir(dir) {
|
|
22
42
|
const dirs = await readdir(dir);
|
|
@@ -37,12 +57,8 @@ export async function compileFile(file) {
|
|
|
37
57
|
}
|
|
38
58
|
export async function compileModule() {
|
|
39
59
|
const targetModule = process.env.TARGET_MODULE;
|
|
40
|
-
if (targetModule === '
|
|
41
|
-
await
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (targetModule === 'esm-bundle') {
|
|
45
|
-
await compileESMBundle();
|
|
60
|
+
if (targetModule === 'bundle') {
|
|
61
|
+
await compileBundle();
|
|
46
62
|
return;
|
|
47
63
|
}
|
|
48
64
|
const dest = targetModule === 'commonjs' ? LIB_DIR : ES_DIR;
|
|
@@ -2,5 +2,10 @@ import { InlineConfig } from 'vite';
|
|
|
2
2
|
import { VarletConfig } from './varlet.config';
|
|
3
3
|
export declare function getDevConfig(varletConfig: Required<VarletConfig>): InlineConfig;
|
|
4
4
|
export declare function getBuildConfig(varletConfig: Required<VarletConfig>): InlineConfig;
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export interface BundleBuildOptions {
|
|
6
|
+
fileName: string;
|
|
7
|
+
output: string;
|
|
8
|
+
format: 'es' | 'cjs' | 'umd';
|
|
9
|
+
emptyOutDir: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getBundleConfig(varletConfig: Required<VarletConfig>, buildOptions: BundleBuildOptions): InlineConfig;
|
|
@@ -2,8 +2,7 @@ import fse from 'fs-extra';
|
|
|
2
2
|
import vue from '@vitejs/plugin-vue';
|
|
3
3
|
import jsx from '@vitejs/plugin-vue-jsx';
|
|
4
4
|
import { markdown, html, inlineCss } from '@varlet/vite-plugins';
|
|
5
|
-
import {
|
|
6
|
-
import { ES_DIR, LIB_DIR, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, UMD_DIR, VITE_RESOLVE_EXTENSIONS, } from '../shared/constant.js';
|
|
5
|
+
import { ES_DIR, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, VITE_RESOLVE_EXTENSIONS, } from '../shared/constant.js';
|
|
7
6
|
import { get } from 'lodash-es';
|
|
8
7
|
import { resolve } from 'path';
|
|
9
8
|
const { copyFileSync, removeSync } = fse;
|
|
@@ -57,24 +56,32 @@ export function getBuildConfig(varletConfig) {
|
|
|
57
56
|
},
|
|
58
57
|
} });
|
|
59
58
|
}
|
|
60
|
-
export function
|
|
59
|
+
export function getBundleConfig(varletConfig, buildOptions) {
|
|
60
|
+
const plugins = [];
|
|
61
61
|
const name = get(varletConfig, 'name');
|
|
62
|
-
const fileName =
|
|
62
|
+
const { fileName, output, format, emptyOutDir } = buildOptions;
|
|
63
|
+
if (format === 'umd') {
|
|
64
|
+
plugins.push(inlineCss({
|
|
65
|
+
jsFile: resolve(output, fileName),
|
|
66
|
+
cssFile: resolve(output, 'style.css'),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
63
69
|
return {
|
|
64
70
|
logLevel: 'silent',
|
|
65
71
|
build: {
|
|
66
|
-
|
|
72
|
+
minify: format === 'cjs' ? false : 'esbuild',
|
|
73
|
+
emptyOutDir,
|
|
67
74
|
copyPublicDir: false,
|
|
68
75
|
lib: {
|
|
69
76
|
name,
|
|
70
|
-
formats: [
|
|
77
|
+
formats: [format],
|
|
71
78
|
fileName: () => fileName,
|
|
72
79
|
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
73
80
|
},
|
|
74
81
|
rollupOptions: {
|
|
75
82
|
external: ['vue'],
|
|
76
83
|
output: {
|
|
77
|
-
dir:
|
|
84
|
+
dir: output,
|
|
78
85
|
exports: 'named',
|
|
79
86
|
globals: {
|
|
80
87
|
vue: 'Vue',
|
|
@@ -84,42 +91,3 @@ export function getESMBundleConfig(varletConfig) {
|
|
|
84
91
|
},
|
|
85
92
|
};
|
|
86
93
|
}
|
|
87
|
-
export function getUMDConfig(varletConfig) {
|
|
88
|
-
const name = get(varletConfig, 'name');
|
|
89
|
-
const fileName = `${kebabCase(name)}.js`;
|
|
90
|
-
const jsFile = resolve(UMD_DIR, fileName);
|
|
91
|
-
const cssFile = resolve(UMD_DIR, 'style.css');
|
|
92
|
-
return {
|
|
93
|
-
logLevel: 'silent',
|
|
94
|
-
build: {
|
|
95
|
-
emptyOutDir: true,
|
|
96
|
-
copyPublicDir: false,
|
|
97
|
-
lib: {
|
|
98
|
-
name,
|
|
99
|
-
formats: ['umd'],
|
|
100
|
-
fileName: () => fileName,
|
|
101
|
-
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
102
|
-
},
|
|
103
|
-
rollupOptions: {
|
|
104
|
-
external: ['vue'],
|
|
105
|
-
output: {
|
|
106
|
-
dir: UMD_DIR,
|
|
107
|
-
exports: 'named',
|
|
108
|
-
globals: {
|
|
109
|
-
vue: 'Vue',
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
plugins: [
|
|
115
|
-
inlineCss({
|
|
116
|
-
jsFile,
|
|
117
|
-
cssFile,
|
|
118
|
-
onEnd() {
|
|
119
|
-
copyFileSync(cssFile, resolve(LIB_DIR, 'style.css'));
|
|
120
|
-
removeSync(cssFile);
|
|
121
|
-
},
|
|
122
|
-
}),
|
|
123
|
-
],
|
|
124
|
-
};
|
|
125
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.7.0-alpha.
|
|
3
|
+
"version": "2.7.0-alpha.1673623558342",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"vite": "4.0.4",
|
|
67
67
|
"vue": "3.2.25",
|
|
68
68
|
"vue-jest": "^5.0.0-alpha.8",
|
|
69
|
-
"@varlet/vite-plugins": "2.7.0-alpha.
|
|
70
|
-
"@varlet/shared": "2.7.0-alpha.
|
|
69
|
+
"@varlet/vite-plugins": "2.7.0-alpha.1673623558342",
|
|
70
|
+
"@varlet/shared": "2.7.0-alpha.1673623558342"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/babel__core": "^7.1.12",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@types/node": "^18.7.20",
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/inquirer": "^9.0.2",
|
|
82
|
-
"@varlet/
|
|
83
|
-
"@varlet/
|
|
82
|
+
"@varlet/icons": "2.7.0-alpha.1673623558342",
|
|
83
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673623558342"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@vue/runtime-core": "3.2.16",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"lodash-es": "^4.17.21",
|
|
91
91
|
"vue": "3.2.25",
|
|
92
92
|
"vue-router": "4.0.12",
|
|
93
|
-
"@varlet/icons": "2.7.0-alpha.
|
|
94
|
-
"@varlet/touch-emulator": "2.7.0-alpha.
|
|
93
|
+
"@varlet/icons": "2.7.0-alpha.1673623558342",
|
|
94
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673623558342"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"dev": "tsc --watch",
|