@varlet/cli 2.16.7 → 2.16.8-alpha.1695118057982
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/README.md +1 -0
- package/README.zh-CN.md +1 -1
- package/lib/node/commands/compile.js +2 -1
- package/lib/node/compiler/compileScript.d.ts +2 -0
- package/lib/node/compiler/compileScript.js +30 -3
- package/lib/node/config/varlet.config.d.ts +4 -0
- package/lib/node/config/varlet.default.config.js +3 -0
- package/lib/node/shared/fsUtils.d.ts +2 -0
- package/lib/node/shared/fsUtils.js +2 -0
- package/package.json +10 -13
- package/template/generators/base/.browserslistrc +2 -0
- package/template/generators/base/package.json +0 -4
- package/cjs/babel.config.cjs +0 -29
- package/cjs/babel.sfc.transform.cjs +0 -18
- package/template/generators/base/babel.config.js +0 -10
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varle
|
|
|
58
58
|
| `directives` | Directive folder names | _string[]_ | `[]` |
|
|
59
59
|
| `copy` | Copy file options | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
|
|
60
60
|
| `icons` | Font icon packaging related configuration | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
|
|
61
|
+
| `esbuild` | Esbuild configuration | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
|
|
61
62
|
|
|
62
63
|
#### Menu
|
|
63
64
|
|
package/README.zh-CN.md
CHANGED
|
@@ -58,7 +58,7 @@ varlet-cli gen
|
|
|
58
58
|
| `directives` | 组件库指令文件夹名称 | _string[]_ | `[]` |
|
|
59
59
|
| `copy` | 复制文件配置 | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
|
|
60
60
|
| `icons` | 字体图标打包相关配置 | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
|
|
61
|
-
|
|
61
|
+
| `esbuild` | Esbuild 配置 | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
|
|
62
62
|
|
|
63
63
|
#### Menu
|
|
64
64
|
|
|
@@ -12,8 +12,9 @@ export function removeDir() {
|
|
|
12
12
|
export async function runTask(taskName, task) {
|
|
13
13
|
const s = createSpinner().start({ text: `Compiling ${taskName}` });
|
|
14
14
|
try {
|
|
15
|
+
const start = performance.now();
|
|
15
16
|
await task();
|
|
16
|
-
s.success({ text: `Compilation ${taskName} completed
|
|
17
|
+
s.success({ text: `Compilation ${taskName} completed! (${Math.ceil(performance.now() - start)}ms)` });
|
|
17
18
|
}
|
|
18
19
|
catch (e) {
|
|
19
20
|
s.error({ text: `Compilation ${taskName} failed!` });
|
|
@@ -7,6 +7,8 @@ export declare const scriptIndexes: string[];
|
|
|
7
7
|
export declare const styleIndexes: string[];
|
|
8
8
|
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
9
9
|
export declare const resolveDependence: (file: string, script: string) => string;
|
|
10
|
+
export declare function compileScriptByBabel(script: string, file: string): Promise<string>;
|
|
11
|
+
export declare function compileScriptByEsbuild(script: string): Promise<string>;
|
|
10
12
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
11
13
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
12
14
|
export declare function getScriptExtname(): string;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
|
+
import esbuild from 'esbuild';
|
|
2
3
|
import { transformAsync } from '@babel/core';
|
|
3
4
|
import { bigCamelize } from '@varlet/shared';
|
|
4
|
-
import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
|
|
5
|
+
import { getVersion, isDir, isJsx, isTsx, replaceExt } from '../shared/fsUtils.js';
|
|
5
6
|
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE } from './compileStyle.js';
|
|
6
7
|
import { resolve, extname, dirname } from 'path';
|
|
8
|
+
import { getVarletConfig } from '../config/varlet.config.js';
|
|
9
|
+
import { get } from 'lodash-es';
|
|
7
10
|
const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
|
|
8
11
|
// https://regexr.com/765a4
|
|
9
12
|
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
@@ -78,10 +81,34 @@ export const resolveDependence = (file, script) => {
|
|
|
78
81
|
.replace(EXPORT_FROM_DEPENDENCE_RE, replacer)
|
|
79
82
|
.replace(IMPORT_DEPENDENCE_RE, replacer);
|
|
80
83
|
};
|
|
81
|
-
export async function
|
|
82
|
-
|
|
84
|
+
export async function compileScriptByBabel(script, file) {
|
|
85
|
+
const { code } = (await transformAsync(script, {
|
|
83
86
|
filename: file,
|
|
87
|
+
babelrc: false,
|
|
88
|
+
presets: ['@babel/preset-typescript'],
|
|
89
|
+
plugins: [
|
|
90
|
+
[
|
|
91
|
+
'@vue/babel-plugin-jsx',
|
|
92
|
+
{
|
|
93
|
+
enableObjectSlots: false,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
],
|
|
84
97
|
}));
|
|
98
|
+
return code;
|
|
99
|
+
}
|
|
100
|
+
export async function compileScriptByEsbuild(script) {
|
|
101
|
+
const varletConfig = await getVarletConfig();
|
|
102
|
+
const { code } = await esbuild.transform(script, {
|
|
103
|
+
loader: 'ts',
|
|
104
|
+
target: get(varletConfig, 'esbuild.target'),
|
|
105
|
+
format: 'esm',
|
|
106
|
+
});
|
|
107
|
+
return code;
|
|
108
|
+
}
|
|
109
|
+
export async function compileScript(script, file) {
|
|
110
|
+
let code = isJsx(file) || isTsx(file) ? await compileScriptByBabel(script, file) : script;
|
|
111
|
+
code = await compileScriptByEsbuild(code);
|
|
85
112
|
if (code) {
|
|
86
113
|
code = resolveDependence(file, code);
|
|
87
114
|
code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
|
|
@@ -20,6 +20,9 @@ export interface VarletConfigIcons {
|
|
|
20
20
|
fontWeight?: string;
|
|
21
21
|
fontStyle?: string;
|
|
22
22
|
}
|
|
23
|
+
export interface VarletConfigEsbuild {
|
|
24
|
+
target?: string | string[];
|
|
25
|
+
}
|
|
23
26
|
export interface VarletConfig {
|
|
24
27
|
/**
|
|
25
28
|
* @default `Varlet`
|
|
@@ -62,6 +65,7 @@ export interface VarletConfig {
|
|
|
62
65
|
mobile?: Record<string, any>;
|
|
63
66
|
copy?: CopyOptions['paths'];
|
|
64
67
|
icons?: VarletConfigIcons;
|
|
68
|
+
esbuild?: VarletConfigEsbuild;
|
|
65
69
|
/**
|
|
66
70
|
* @default `[]`
|
|
67
71
|
* Directive folder name for component library.
|
|
@@ -3,6 +3,8 @@ export declare const isMD: (file: string) => boolean;
|
|
|
3
3
|
export declare const isDir: (file: string) => boolean;
|
|
4
4
|
export declare const isSFC: (file: string) => boolean;
|
|
5
5
|
export declare const isDTS: (file: string) => boolean;
|
|
6
|
+
export declare const isJsx: (file: string) => boolean;
|
|
7
|
+
export declare const isTsx: (file: string) => boolean;
|
|
6
8
|
export declare const isScript: (file: string) => boolean;
|
|
7
9
|
export declare const isLess: (file: string) => boolean;
|
|
8
10
|
export declare const isPublicDir: (dir: string) => boolean;
|
|
@@ -12,6 +12,8 @@ export const isMD = (file) => pathExistsSync(file) && extname(file) === '.md';
|
|
|
12
12
|
export const isDir = (file) => pathExistsSync(file) && lstatSync(file).isDirectory();
|
|
13
13
|
export const isSFC = (file) => pathExistsSync(file) && extname(file) === '.vue';
|
|
14
14
|
export const isDTS = (file) => pathExistsSync(file) && file.endsWith('.d.ts');
|
|
15
|
+
export const isJsx = (file) => pathExistsSync(file) && file.endsWith('.jsx');
|
|
16
|
+
export const isTsx = (file) => pathExistsSync(file) && file.endsWith('.tsx');
|
|
15
17
|
export const isScript = (file) => pathExistsSync(file) && SCRIPTS_EXTENSIONS.includes(extname(file));
|
|
16
18
|
export const isLess = (file) => pathExistsSync(file) && extname(file) === '.less';
|
|
17
19
|
export const isPublicDir = (dir) => PUBLIC_DIR_INDEXES.some((index) => pathExistsSync(resolve(dir, index)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.8-alpha.1695118057982",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"files": [
|
|
18
18
|
"lib",
|
|
19
|
-
"cjs",
|
|
20
19
|
"client.js",
|
|
21
20
|
"client.d.ts",
|
|
22
21
|
"template",
|
|
@@ -36,15 +35,13 @@
|
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"@babel/core": "^7.22.5",
|
|
39
|
-
"@babel/helper-plugin-utils": "^7.22.5",
|
|
40
|
-
"@babel/plugin-transform-typescript": "^7.22.5",
|
|
41
|
-
"@babel/preset-env": "^7.22.5",
|
|
42
38
|
"@babel/preset-typescript": "^7.22.5",
|
|
43
39
|
"@vitejs/plugin-vue": "4.2.3",
|
|
44
40
|
"@vitejs/plugin-vue-jsx": "3.0.1",
|
|
45
41
|
"@vue/babel-plugin-jsx": "1.1.4",
|
|
46
42
|
"@vue/compiler-sfc": "3.3.4",
|
|
47
43
|
"@vue/runtime-core": "3.3.4",
|
|
44
|
+
"esbuild": "0.19.3",
|
|
48
45
|
"vitest": "0.34.3",
|
|
49
46
|
"chokidar": "^3.5.2",
|
|
50
47
|
"commander": "^8.3.0",
|
|
@@ -67,8 +64,8 @@
|
|
|
67
64
|
"vite": "4.3.5",
|
|
68
65
|
"vue": "3.3.4",
|
|
69
66
|
"webfont": "^9.0.0",
|
|
70
|
-
"@varlet/shared": "2.16.
|
|
71
|
-
"@varlet/vite-plugins": "2.16.
|
|
67
|
+
"@varlet/shared": "2.16.8-alpha.1695118057982",
|
|
68
|
+
"@varlet/vite-plugins": "2.16.8-alpha.1695118057982"
|
|
72
69
|
},
|
|
73
70
|
"devDependencies": {
|
|
74
71
|
"@types/babel__core": "^7.20.1",
|
|
@@ -83,9 +80,9 @@
|
|
|
83
80
|
"@types/semver": "^7.3.9",
|
|
84
81
|
"@types/sharp": "0.31.1",
|
|
85
82
|
"rimraf": "^5.0.1",
|
|
86
|
-
"@varlet/
|
|
87
|
-
"@varlet/
|
|
88
|
-
"@varlet/
|
|
83
|
+
"@varlet/touch-emulator": "2.16.8-alpha.1695118057982",
|
|
84
|
+
"@varlet/ui": "2.16.8-alpha.1695118057982",
|
|
85
|
+
"@varlet/icons": "2.16.8-alpha.1695118057982"
|
|
89
86
|
},
|
|
90
87
|
"peerDependencies": {
|
|
91
88
|
"@vue/runtime-core": "3.3.4",
|
|
@@ -98,9 +95,9 @@
|
|
|
98
95
|
"lodash-es": "^4.17.21",
|
|
99
96
|
"vue": "3.3.4",
|
|
100
97
|
"vue-router": "4.2.0",
|
|
101
|
-
"@varlet/ui": "2.16.
|
|
102
|
-
"@varlet/
|
|
103
|
-
"@varlet/
|
|
98
|
+
"@varlet/ui": "2.16.8-alpha.1695118057982",
|
|
99
|
+
"@varlet/touch-emulator": "2.16.8-alpha.1695118057982",
|
|
100
|
+
"@varlet/icons": "2.16.8-alpha.1695118057982"
|
|
104
101
|
},
|
|
105
102
|
"scripts": {
|
|
106
103
|
"dev": "tsc --watch",
|
|
@@ -67,10 +67,6 @@
|
|
|
67
67
|
"pre-commit": "pnpm exec lint-staged --allow-empty --concurrent false",
|
|
68
68
|
"commit-msg": "pnpm exec varlet-cli commit-lint $1"
|
|
69
69
|
},
|
|
70
|
-
"browserslist": [
|
|
71
|
-
"Chrome >= 54",
|
|
72
|
-
"iOS >= 10"
|
|
73
|
-
],
|
|
74
70
|
"packageManager": "pnpm@8.0.0",
|
|
75
71
|
"engines": {
|
|
76
72
|
"pnpm": ">=8.0"
|
package/cjs/babel.config.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module.exports = (api, options) => {
|
|
2
|
-
if (api) {
|
|
3
|
-
api.cache.never()
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const isCommonJS = process.env.NODE_ENV === 'test' || process.env.BABEL_MODULE === 'commonjs'
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
presets: [
|
|
10
|
-
[
|
|
11
|
-
require.resolve('@babel/preset-env'),
|
|
12
|
-
{
|
|
13
|
-
modules: isCommonJS ? 'commonjs' : false,
|
|
14
|
-
loose: options.loose,
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
require.resolve('@babel/preset-typescript'),
|
|
18
|
-
require('./babel.sfc.transform.cjs'),
|
|
19
|
-
],
|
|
20
|
-
plugins: [
|
|
21
|
-
[
|
|
22
|
-
require.resolve('@vue/babel-plugin-jsx'),
|
|
23
|
-
{
|
|
24
|
-
enableObjectSlots: options.enableObjectSlots,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
],
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { readFileSync } = require('fs')
|
|
2
|
-
const { declare } = require('@babel/helper-plugin-utils')
|
|
3
|
-
|
|
4
|
-
module.exports = declare(() => ({
|
|
5
|
-
overrides: [
|
|
6
|
-
{
|
|
7
|
-
test: (file) => {
|
|
8
|
-
if (/\.vue$/.test(file)) {
|
|
9
|
-
const code = readFileSync(file, 'utf8')
|
|
10
|
-
return code.includes('lang="ts"') || code.includes("lang='ts'")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return false
|
|
14
|
-
},
|
|
15
|
-
plugins: [require.resolve('@babel/plugin-transform-typescript')],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
}))
|