@varlet/cli 1.25.1-alpha.1643124613252 → 1.26.0

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.en-US.md CHANGED
@@ -186,6 +186,7 @@ module.exports = {
186
186
  header: {
187
187
  darkMode: null,
188
188
  i18n: null,
189
+ playground: null,
189
190
  github: 'https://github.com/varletjs/varlet',
190
191
  },
191
192
  },
package/README.md CHANGED
@@ -182,6 +182,7 @@ module.exports = {
182
182
  header: {
183
183
  darkMode: null,
184
184
  i18n: null,
185
+ playground: null,
185
186
  github: 'https://github.com/varletjs/varlet',
186
187
  },
187
188
  },
@@ -62,6 +62,7 @@ module.exports = {
62
62
  },
63
63
  header: {
64
64
  i18n: null,
65
+ playground: null,
65
66
  github: 'https://github.com/varletjs/varlet',
66
67
  },
67
68
  menu: [
@@ -93,16 +93,19 @@ function compile(cmd) {
93
93
  return [4 /*yield*/, runTask('module', compileModule_1.compileModule)];
94
94
  case 3:
95
95
  _b.sent();
96
- return [4 /*yield*/, runTask('commonjs', function () { return (0, compileModule_1.compileModule)('commonjs'); })];
96
+ return [4 /*yield*/, runTask('esm bundle', function () { return (0, compileModule_1.compileModule)('esm-bundle'); })];
97
97
  case 4:
98
+ _b.sent();
99
+ return [4 /*yield*/, runTask('commonjs', function () { return (0, compileModule_1.compileModule)('commonjs'); })];
100
+ case 5:
98
101
  _b.sent();
99
102
  _a = !cmd.noUmd;
100
- if (!_a) return [3 /*break*/, 6];
103
+ if (!_a) return [3 /*break*/, 7];
101
104
  return [4 /*yield*/, runTask('umd', function () { return (0, compileModule_1.compileModule)('umd'); })];
102
- case 5:
103
- _a = (_b.sent());
104
- _b.label = 6;
105
105
  case 6:
106
+ _a = (_b.sent());
107
+ _b.label = 7;
108
+ case 7:
106
109
  _a;
107
110
  return [2 /*return*/];
108
111
  }
@@ -1,4 +1,5 @@
1
1
  export declare function compileUMD(): Promise<void>;
2
+ export declare function compileESMBundle(): Promise<void>;
2
3
  export declare function compileDir(dir: string): Promise<void>;
3
4
  export declare function compileFile(file: string): Promise<void>;
4
- export declare function compileModule(modules?: 'umd' | 'commonjs' | boolean): Promise<void>;
5
+ export declare function compileModule(modules?: 'umd' | 'commonjs' | 'esm-bundle' | boolean): Promise<void>;
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.compileModule = exports.compileFile = exports.compileDir = exports.compileUMD = void 0;
39
+ exports.compileModule = exports.compileFile = exports.compileDir = exports.compileESMBundle = exports.compileUMD = void 0;
40
40
  var vite_1 = require("vite");
41
41
  var path_1 = require("path");
42
42
  var fs_extra_1 = require("fs-extra");
@@ -57,6 +57,15 @@ function compileUMD() {
57
57
  });
58
58
  }
59
59
  exports.compileUMD = compileUMD;
60
+ function compileESMBundle() {
61
+ return new Promise(function (resolve, reject) {
62
+ var config = (0, vite_config_1.getESMBundleConfig)((0, varlet_config_1.getVarletConfig)());
63
+ (0, vite_1.build)(config)
64
+ .then(function () { return resolve(); })
65
+ .catch(reject);
66
+ });
67
+ }
68
+ exports.compileESMBundle = compileESMBundle;
60
69
  function compileDir(dir) {
61
70
  return __awaiter(this, void 0, void 0, function () {
62
71
  var dirs;
@@ -138,13 +147,19 @@ function compileModule(modules) {
138
147
  _a.sent();
139
148
  return [2 /*return*/];
140
149
  case 2:
150
+ if (!(modules === 'esm-bundle')) return [3 /*break*/, 4];
151
+ return [4 /*yield*/, compileESMBundle()];
152
+ case 3:
153
+ _a.sent();
154
+ return [2 /*return*/];
155
+ case 4:
141
156
  process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
142
157
  dest = modules === 'commonjs' ? constant_1.LIB_DIR : constant_1.ES_DIR;
143
158
  return [4 /*yield*/, (0, fs_extra_1.copy)(constant_1.SRC_DIR, dest)];
144
- case 3:
159
+ case 5:
145
160
  _a.sent();
146
161
  return [4 /*yield*/, (0, fs_extra_1.readdir)(dest)];
147
- case 4:
162
+ case 6:
148
163
  moduleDir = _a.sent();
149
164
  return [4 /*yield*/, Promise.all(moduleDir.map(function (filename) {
150
165
  var file = (0, path_1.resolve)(dest, filename);
@@ -154,13 +169,13 @@ function compileModule(modules) {
154
169
  }
155
170
  return (0, fsUtils_1.isDir)(file) ? compileDir(file) : null;
156
171
  }))];
157
- case 5:
172
+ case 7:
158
173
  _a.sent();
159
174
  return [4 /*yield*/, (0, fsUtils_1.getPublicDirs)()];
160
- case 6:
175
+ case 8:
161
176
  publicDirs = _a.sent();
162
177
  return [4 /*yield*/, (modules === 'commonjs' ? (0, compileScript_1.compileCommonJSEntry)(dest, publicDirs) : (0, compileScript_1.compileESEntry)(dest, publicDirs))];
163
- case 7:
178
+ case 9:
164
179
  _a.sent();
165
180
  (0, compileTypes_1.generateReference)(dest);
166
181
  return [2 /*return*/];
@@ -1,4 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
2
  export declare function getDevConfig(varletConfig: Record<string, any>): InlineConfig;
3
3
  export declare function getBuildConfig(varletConfig: Record<string, any>): InlineConfig;
4
+ export declare function getESMBundleConfig(varletConfig: Record<string, any>): InlineConfig;
4
5
  export declare function getUMDConfig(varletConfig: Record<string, any>): InlineConfig;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getUMDConfig = exports.getBuildConfig = exports.getDevConfig = void 0;
17
+ exports.getUMDConfig = exports.getESMBundleConfig = exports.getBuildConfig = exports.getDevConfig = void 0;
18
18
  var plugin_vue_1 = __importDefault(require("@vitejs/plugin-vue"));
19
19
  var markdown_vite_plugin_1 = __importDefault(require("@varlet/markdown-vite-plugin"));
20
20
  var plugin_vue_jsx_1 = __importDefault(require("@vitejs/plugin-vue-jsx"));
@@ -102,6 +102,34 @@ function clear() {
102
102
  },
103
103
  };
104
104
  }
105
+ function getESMBundleConfig(varletConfig) {
106
+ var name = (0, lodash_1.get)(varletConfig, 'name');
107
+ var fileName = "".concat((0, lodash_1.kebabCase)(name), ".esm.js");
108
+ return {
109
+ logLevel: 'silent',
110
+ build: {
111
+ emptyOutDir: true,
112
+ lib: {
113
+ name: name,
114
+ formats: ['es'],
115
+ fileName: function () { return fileName; },
116
+ entry: (0, path_1.resolve)(constant_1.ES_DIR, 'umdIndex.js'),
117
+ },
118
+ rollupOptions: {
119
+ external: ['vue'],
120
+ output: {
121
+ dir: constant_1.ES_DIR,
122
+ exports: 'named',
123
+ globals: {
124
+ vue: 'Vue',
125
+ },
126
+ },
127
+ },
128
+ },
129
+ plugins: [clear()],
130
+ };
131
+ }
132
+ exports.getESMBundleConfig = getESMBundleConfig;
105
133
  function getUMDConfig(varletConfig) {
106
134
  var name = (0, lodash_1.get)(varletConfig, 'name');
107
135
  var fileName = "".concat((0, lodash_1.kebabCase)(name), ".js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "1.25.1-alpha.1643124613252",
3
+ "version": "1.26.0",
4
4
  "description": "cli of varlet",
5
5
  "bin": {
6
6
  "varlet-cli": "./lib/index.js"
@@ -33,9 +33,9 @@
33
33
  "@babel/helper-plugin-utils": "^7.14.5",
34
34
  "@babel/preset-env": "^7.14.8",
35
35
  "@babel/preset-typescript": "^7.14.5",
36
- "@varlet/icons": "1.25.1-alpha.1643124613252",
37
- "@varlet/markdown-vite-plugin": "1.25.1-alpha.1643124613252",
38
- "@varlet/touch-emulator": "1.25.1-alpha.1643124613252",
36
+ "@varlet/icons": "1.26.0",
37
+ "@varlet/markdown-vite-plugin": "1.26.0",
38
+ "@varlet/touch-emulator": "1.26.0",
39
39
  "@vitejs/plugin-vue": "1.9.2",
40
40
  "@vitejs/plugin-vue-jsx": "1.1.8",
41
41
  "@vue/babel-plugin-jsx": "1.0.7",
@@ -74,7 +74,7 @@
74
74
  "@types/semver": "^7.3.9"
75
75
  },
76
76
  "peerDependencies": {
77
- "@varlet/touch-emulator": "1.25.1-alpha.1643124613252",
77
+ "@varlet/touch-emulator": "1.26.0",
78
78
  "@vue/test-utils": "^2.0.0-rc.6",
79
79
  "clipboard": "^2.0.6",
80
80
  "live-server": "^1.2.1",
@@ -86,5 +86,5 @@
86
86
  "dev": "tsc --watch",
87
87
  "build": "tsc"
88
88
  },
89
- "readme": "# @varlet/cli\n\n开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题\n\n### 特性\n\n- 1.开箱即用的组件库开发环境\n- 2.开箱即用的组件库编译工具,支持导出 `esm` 和 `umd` 两种模块代码\n- 3.基于配置文件的组件库文档站点,支持百度统计和主题定制\n- 4.支持 `单文件组件(sfc)` 和 `tsx,jsx` 两种风格的组件库编写风格\n- 5.开箱即用的代码检查工具\n- 6.开箱即用的单元测试工具\n- 7.开箱即用的代码发布工具,发布到 npm 和 github, 并自动生成更新日志\n- 8.支持 `Typescript`\n- 9.支持 `暗黑模式`\n- 10.基于 `pnpm`\n\n### 快速开始\n\n`@varlet/cli` 内置了 `单文件组件(sfc)` 和 `tsx, jsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。\n帮助用户直接进入组件本身的开发,推荐使用 `pnpm` 作为包管理工具。\n\n```shell\n# 安装命令行工具\npnpm add @varlet/cli -g\n# 使用 gen 命令生成项目\nvarlet-cli gen 项目名\ncd 项目名\npnpm install\npnpm dev\n```\n\n然后通过简单修改一些组件库模板的基础信息,就可以开始组件库的开发了\n\n## 高级定制\n\n### 配置文件\n\n项目根目录下的 `varlet.config.js` 用来管理整个组件库项目的具体细节\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `host` | 开发服务器主机 | _number_ | `localhost` |\n| `port` | 开发服务器端口 | _number_ | `8080` |\n| `name` | 组件库全名\t| _string_ | `Varlet` |\n| `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |\n| `title` | 文档中组件库的标题 | _string_ | `VARLET` |\n| `logo` | 文档中组件库的logo | _string_ | `-` |\n| `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |\n| `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |\n| `themes` | 文档主题 | _SiteThemes_ | `-` |\n| `darkThemes` | 暗黑模式文档主题 | _SiteThemes_ | `-` |\n| `highlight` | 文档代码片段样式相关 | _SiteHighlight_ | `-` |\n| `analysis` | 文档统计相关 | _SiteAnalysis_ | `-` |\n| `pc` | pc端文档结构配置 | _SitePC_ | `-` |\n| `mobile` | mobile端文档结构配置 | _SiteMobile_ | `-` |\n| `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |\n\n#### 模块适配对象\n\n一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到 `commonjs` 和 `esmodule` 的目的,例如 `dayjs` 的 `esmodule` 写法是\n\n```js\nimport dayjs from 'dayjs/esm'\n```\n\n而为了构建 `commonjs` 时的写法是\n\n```js\nimport * as dayjs from 'dayjs'\n```\n\n在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配\n\n```js\n// varlet.config.js\nmodule.exports = {\n moduleCompatible: {\n \"import dayjs from 'dayjs/esm'\\n\": \"import * as dayjs from 'dayjs'\\n\"\n }\n}\n```\n\n#### SiteThemes\n\n主题变量相关,由于默认的主题变量可能时常修改,以 `varlet` 官方文档的主题为准\n\n| 参数 |\n| ----- |\n| `color-body` |\n| `color-bar` |\n| `color-sub-bar` |\n| `color-text` |\n| `color-sub-text` |\n| `color-border` |\n| `color-shadow` |\n| `color-introduce-border` |\n| `color-primary` |\n| `color-link` |\n| `color-type` |\n| `color-progress` |\n| `color-progress-track` |\n| `color-side-bar` |\n| `color-side-bar-active-background` |\n| `color-app-bar` |\n| `color-nav-button-hover-background` |\n| `color-pc-language-active` |\n| `color-pc-language-active-background` |\n| `color-mobile-cell-hover` |\n| `color-mobile-language-active` |\n| `color-mobile-language-active-background` |\n\n#### SiteHighlight\n\n代码片段高亮,基于[highlight.js](https://highlightjs.org/)\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `style` | highlight的css地址 | _string_ | `-` |\n\n#### SiteAnalysis\n\n统计埋点相关\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `baidu` | 百度统计脚本地址 | _string_ | `-` |\n\n#### SitePC, SiteMobile\n\n文档结构部分相关,示例配置如下\n\n```js\nmodule.exports = {\n pc: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n github: 'https://github.com/varletjs/varlet',\n },\n menu: [\n {\n text: {\n 'zh-CN': '开发指南',\n },\n // 侧边栏菜单目录\n type: 1,\n },\n {\n text: {\n 'zh-CN': '基本介绍',\n },\n doc: 'home',\n // 索引项目根目录下的md文档\n type: 3,\n },\n {\n text: {\n 'zh-CN': '基础组件',\n },\n type: 1,\n },\n {\n text: {\n 'zh-CN': 'Button 按钮',\n },\n doc: 'button',\n // 索引组件根目录下的md文档\n type: 2,\n },\n ],\n },\n mobile: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n github: 'https://github.com/varletjs/varlet',\n },\n },\n}\n```\n\n### 命令相关\n\n#### 启动开发服务器\n\n```shell\nvarlet-cli dev\n```\n\n#### 构建文档站点\n\n```shell\nvarlet-cli build\n```\n\n#### 预览文档站点\n\n```shell\nvarlet-cli preview\n```\n\n#### 构建组件库代码\n\n```shell\nvarlet-cli compile\n```\n\n#### 执行所有的单元测试\n\n```shell\nvarlet-cli test\n```\n\n#### 以 watch 模式执行单元测试\n\n```shell\nvarlet-cli test -w\nor\nvarlet-cli test -wa\n```\n\n#### 检查代码\n\n```shell\nvarlet-cli lint\n```\n\n#### 校验提交信息\n\n```shell\nvarlet-cli commit-lint\n```\n\n#### 生成更新日志\n\n```shell\nvarlet-cli changelog\n```\n\n#### 发布组件库\n\n```shell\nvarlet-cli release\n```\n\n#### 生成一个项目模板\n```shell\nvarlet-cli gen <projectName>\n```\n\n### babel\n\n对 `babel` 进行配置,首先在 `package.json` 中指定目标浏览器\n\n```json\n{\n \"browserslist\": [\n \"Chrome >= 51\",\n \"iOS >= 10\"\n ]\n}\n```\n\n创建 `babel.config,js`\n\n```js\n// babel.config.js\nmodule.exports = {\n presets: [\n [\n '@varlet/cli/preset',\n {\n loose: process.env.NODE_ENV === 'compile',\n },\n ],\n ],\n}\n```\n\n### git 和 npm\n\n#### git-hook\n\n`simple-git-hooks`,`lint-staged` 配合 `eslint`,`stylelint`,`varlet-cli commit-lint` 做commit前的检查,`package.json` 配置如下\n\n```json\n{\n \"simple-git-hooks\": {\n \"pre-commit\": \"pnpm exec lint-staged --allow-empty --concurrent false\",\n \"commit-msg\": \"npx --no-install varlet-cli commit-lint $1\"\n },\n \"lint-staged\": {\n \"*.{ts,tsx,js,vue,less}\": \"prettier --write\",\n \"*.{ts,tsx,js,vue}\": \"eslint --fix\",\n \"*.{vue,css,less}\": \"stylelint --fix\"\n },\n \"eslintConfig\": {\n \"root\": true,\n \"ignorePatterns\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"public/**\",\n \"src/*/__tests__/**\",\n \".varlet/**\"\n ],\n \"extends\": [\n \"@varlet\"\n ]\n },\n \"stylelint\": {\n \"extends\": [\n \"@varlet/stylelint-config\"\n ],\n \"ignoreFiles\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"coverage/**\",\n \"public/**\",\n \"highlight/**\"\n ]\n }\n}\n```\n\n挂载钩子\n\n```shell\nnpx simple-git-hooks\n```\n\n创建 `.prettierignore`\n\n```text\n// .prettierignore\ncoverage/**\nes/**\numd/**\nsite/**\npublic/**\nsrc/*/__tests__/**\n*.md\n```\n\n### typescript\n\n创建 `tsconfig.json`\n\n```json\n{\n \"compilerOptions\": {\n \"strict\": true,\n \"downlevelIteration\": true,\n \"declaration\": true,\n \"skipLibCheck\": true,\n \"esModuleInterop\": true,\n \"allowJs\": true,\n \"lib\": [\"esnext\", \"dom\"],\n \"allowSyntheticDefaultImports\": true,\n \"jsx\": \"preserve\"\n }\n}\n```\n\n#### 发布前注意\n\n1. `npm` 的仓库源必须指向 `npm` 官方镜像\n2. 执行 `npm login` 进行登录\n\n### Contributors\n\n<a href=\"https://github.com/varletjs/varlet/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=haoziqaq/varlet\" />\n</a>"
89
+ "readme": "# @varlet/cli\n\n开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题\n\n### 特性\n\n- 1.开箱即用的组件库开发环境\n- 2.开箱即用的组件库编译工具,支持导出 `esm` 和 `umd` 两种模块代码\n- 3.基于配置文件的组件库文档站点,支持百度统计和主题定制\n- 4.支持 `单文件组件(sfc)` 和 `tsx,jsx` 两种风格的组件库编写风格\n- 5.开箱即用的代码检查工具\n- 6.开箱即用的单元测试工具\n- 7.开箱即用的代码发布工具,发布到 npm 和 github, 并自动生成更新日志\n- 8.支持 `Typescript`\n- 9.支持 `暗黑模式`\n- 10.基于 `pnpm`\n\n### 快速开始\n\n`@varlet/cli` 内置了 `单文件组件(sfc)` 和 `tsx, jsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。\n帮助用户直接进入组件本身的开发,推荐使用 `pnpm` 作为包管理工具。\n\n```shell\n# 安装命令行工具\npnpm add @varlet/cli -g\n# 使用 gen 命令生成项目\nvarlet-cli gen 项目名\ncd 项目名\npnpm install\npnpm dev\n```\n\n然后通过简单修改一些组件库模板的基础信息,就可以开始组件库的开发了\n\n## 高级定制\n\n### 配置文件\n\n项目根目录下的 `varlet.config.js` 用来管理整个组件库项目的具体细节\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `host` | 开发服务器主机 | _number_ | `localhost` |\n| `port` | 开发服务器端口 | _number_ | `8080` |\n| `name` | 组件库全名\t| _string_ | `Varlet` |\n| `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |\n| `title` | 文档中组件库的标题 | _string_ | `VARLET` |\n| `logo` | 文档中组件库的logo | _string_ | `-` |\n| `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |\n| `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |\n| `themes` | 文档主题 | _SiteThemes_ | `-` |\n| `darkThemes` | 暗黑模式文档主题 | _SiteThemes_ | `-` |\n| `highlight` | 文档代码片段样式相关 | _SiteHighlight_ | `-` |\n| `analysis` | 文档统计相关 | _SiteAnalysis_ | `-` |\n| `pc` | pc端文档结构配置 | _SitePC_ | `-` |\n| `mobile` | mobile端文档结构配置 | _SiteMobile_ | `-` |\n| `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |\n\n#### 模块适配对象\n\n一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到 `commonjs` 和 `esmodule` 的目的,例如 `dayjs` 的 `esmodule` 写法是\n\n```js\nimport dayjs from 'dayjs/esm'\n```\n\n而为了构建 `commonjs` 时的写法是\n\n```js\nimport * as dayjs from 'dayjs'\n```\n\n在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配\n\n```js\n// varlet.config.js\nmodule.exports = {\n moduleCompatible: {\n \"import dayjs from 'dayjs/esm'\\n\": \"import * as dayjs from 'dayjs'\\n\"\n }\n}\n```\n\n#### SiteThemes\n\n主题变量相关,由于默认的主题变量可能时常修改,以 `varlet` 官方文档的主题为准\n\n| 参数 |\n| ----- |\n| `color-body` |\n| `color-bar` |\n| `color-sub-bar` |\n| `color-text` |\n| `color-sub-text` |\n| `color-border` |\n| `color-shadow` |\n| `color-introduce-border` |\n| `color-primary` |\n| `color-link` |\n| `color-type` |\n| `color-progress` |\n| `color-progress-track` |\n| `color-side-bar` |\n| `color-side-bar-active-background` |\n| `color-app-bar` |\n| `color-nav-button-hover-background` |\n| `color-pc-language-active` |\n| `color-pc-language-active-background` |\n| `color-mobile-cell-hover` |\n| `color-mobile-language-active` |\n| `color-mobile-language-active-background` |\n\n#### SiteHighlight\n\n代码片段高亮,基于[highlight.js](https://highlightjs.org/)\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `style` | highlight的css地址 | _string_ | `-` |\n\n#### SiteAnalysis\n\n统计埋点相关\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `baidu` | 百度统计脚本地址 | _string_ | `-` |\n\n#### SitePC, SiteMobile\n\n文档结构部分相关,示例配置如下\n\n```js\nmodule.exports = {\n pc: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n github: 'https://github.com/varletjs/varlet',\n },\n menu: [\n {\n text: {\n 'zh-CN': '开发指南',\n },\n // 侧边栏菜单目录\n type: 1,\n },\n {\n text: {\n 'zh-CN': '基本介绍',\n },\n doc: 'home',\n // 索引项目根目录下的md文档\n type: 3,\n },\n {\n text: {\n 'zh-CN': '基础组件',\n },\n type: 1,\n },\n {\n text: {\n 'zh-CN': 'Button 按钮',\n },\n doc: 'button',\n // 索引组件根目录下的md文档\n type: 2,\n },\n ],\n },\n mobile: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n playground: null,\n github: 'https://github.com/varletjs/varlet',\n },\n },\n}\n```\n\n### 命令相关\n\n#### 启动开发服务器\n\n```shell\nvarlet-cli dev\n```\n\n#### 构建文档站点\n\n```shell\nvarlet-cli build\n```\n\n#### 预览文档站点\n\n```shell\nvarlet-cli preview\n```\n\n#### 构建组件库代码\n\n```shell\nvarlet-cli compile\n```\n\n#### 执行所有的单元测试\n\n```shell\nvarlet-cli test\n```\n\n#### 以 watch 模式执行单元测试\n\n```shell\nvarlet-cli test -w\nor\nvarlet-cli test -wa\n```\n\n#### 检查代码\n\n```shell\nvarlet-cli lint\n```\n\n#### 校验提交信息\n\n```shell\nvarlet-cli commit-lint\n```\n\n#### 生成更新日志\n\n```shell\nvarlet-cli changelog\n```\n\n#### 发布组件库\n\n```shell\nvarlet-cli release\n```\n\n#### 生成一个项目模板\n```shell\nvarlet-cli gen <projectName>\n```\n\n### babel\n\n对 `babel` 进行配置,首先在 `package.json` 中指定目标浏览器\n\n```json\n{\n \"browserslist\": [\n \"Chrome >= 51\",\n \"iOS >= 10\"\n ]\n}\n```\n\n创建 `babel.config,js`\n\n```js\n// babel.config.js\nmodule.exports = {\n presets: [\n [\n '@varlet/cli/preset',\n {\n loose: process.env.NODE_ENV === 'compile',\n },\n ],\n ],\n}\n```\n\n### git 和 npm\n\n#### git-hook\n\n`simple-git-hooks`,`lint-staged` 配合 `eslint`,`stylelint`,`varlet-cli commit-lint` 做commit前的检查,`package.json` 配置如下\n\n```json\n{\n \"simple-git-hooks\": {\n \"pre-commit\": \"pnpm exec lint-staged --allow-empty --concurrent false\",\n \"commit-msg\": \"npx --no-install varlet-cli commit-lint $1\"\n },\n \"lint-staged\": {\n \"*.{ts,tsx,js,vue,less}\": \"prettier --write\",\n \"*.{ts,tsx,js,vue}\": \"eslint --fix\",\n \"*.{vue,css,less}\": \"stylelint --fix\"\n },\n \"eslintConfig\": {\n \"root\": true,\n \"ignorePatterns\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"public/**\",\n \"src/*/__tests__/**\",\n \".varlet/**\"\n ],\n \"extends\": [\n \"@varlet\"\n ]\n },\n \"stylelint\": {\n \"extends\": [\n \"@varlet/stylelint-config\"\n ],\n \"ignoreFiles\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"coverage/**\",\n \"public/**\",\n \"highlight/**\"\n ]\n }\n}\n```\n\n挂载钩子\n\n```shell\nnpx simple-git-hooks\n```\n\n创建 `.prettierignore`\n\n```text\n// .prettierignore\ncoverage/**\nes/**\numd/**\nsite/**\npublic/**\nsrc/*/__tests__/**\n*.md\n```\n\n### typescript\n\n创建 `tsconfig.json`\n\n```json\n{\n \"compilerOptions\": {\n \"strict\": true,\n \"downlevelIteration\": true,\n \"declaration\": true,\n \"skipLibCheck\": true,\n \"esModuleInterop\": true,\n \"allowJs\": true,\n \"lib\": [\"esnext\", \"dom\"],\n \"allowSyntheticDefaultImports\": true,\n \"jsx\": \"preserve\"\n }\n}\n```\n\n#### 发布前注意\n\n1. `npm` 的仓库源必须指向 `npm` 官方镜像\n2. 执行 `npm login` 进行登录\n\n### Contributors\n\n<a href=\"https://github.com/varletjs/varlet/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=haoziqaq/varlet\" />\n</a>"
90
90
  }
@@ -18,6 +18,7 @@
18
18
  <div
19
19
  :id="`clip-target-${cid}`"
20
20
  class="var-site-code-example__code"
21
+ :class="[disabledFold ? 'var-site-code-example--scroller' : null]"
21
22
  ref="code"
22
23
  :style="{
23
24
  height: height >= 0 ? `${height}px` : undefined,
@@ -57,18 +58,17 @@ export default defineComponent({
57
58
  const clipboard: Ref = ref(get(config, 'pc.clipboard', {}))
58
59
  const height: Ref<number> = ref(-1)
59
60
 
60
- let fullHeight = 0
61
-
62
61
  const toggle = async () => {
63
62
  const foldHeight = fold.value.foldHeight
64
63
 
65
64
  if (height.value === foldHeight) {
65
+ height.value = -1
66
+ await nextTick()
67
+ const { offsetHeight } = code.value as HTMLElement
66
68
  height.value = foldHeight
67
69
  await doubleRaf()
68
- height.value = fullHeight
70
+ height.value = offsetHeight
69
71
  } else {
70
- height.value = fullHeight
71
- await doubleRaf()
72
72
  height.value = foldHeight
73
73
  }
74
74
  }
@@ -81,8 +81,7 @@ export default defineComponent({
81
81
  })
82
82
 
83
83
  const { offsetHeight } = code.value as HTMLElement
84
- fullHeight = offsetHeight
85
- disabledFold.value = fullHeight - fold.value.foldHeight < offset
84
+ disabledFold.value = offsetHeight - fold.value.foldHeight < offset
86
85
  height.value = fold.value?.defaultFold ? fold.value?.foldHeight : -1
87
86
  })
88
87
 
@@ -20,4 +20,10 @@
20
20
  overflow: hidden;
21
21
  border-radius: 4px;
22
22
  }
23
+
24
+ &--scroller {
25
+ code {
26
+ white-space: nowrap;
27
+ }
28
+ }
23
29
  }
@@ -6,6 +6,15 @@
6
6
  </div>
7
7
 
8
8
  <div class="varlet-site-header__tail">
9
+ <a
10
+ class="varlet-site-header__link"
11
+ target="_blank"
12
+ :href="playground"
13
+ v-ripple
14
+ v-if="playground"
15
+ >
16
+ <var-site-icon name="code-json" :size="24" />
17
+ </a>
9
18
  <a
10
19
  class="varlet-site-header__link"
11
20
  target="_blank"
@@ -80,8 +89,9 @@ export default defineComponent({
80
89
  const logo: Ref<string> = ref(get(config, 'logo'))
81
90
  const themesKey = get(config, 'themesKey')
82
91
  const languages: Ref<Record<string, string>> = ref(get(config, 'pc.header.i18n'))
83
- const github: Ref<Record<string, string>> = ref(get(config, 'pc.header.github'))
84
- const darkMode: Ref<Record<string, string>> = ref(get(config, 'pc.header.darkMode'))
92
+ const playground: Ref<string> = ref(get(config, 'pc.header.playground'))
93
+ const github: Ref<string> = ref(get(config, 'pc.header.github'))
94
+ const darkMode: Ref<boolean> = ref(get(config, 'pc.header.darkMode'))
85
95
  const currentThemes = ref(getBrowserThemes(themesKey))
86
96
 
87
97
  const isOpenMenu: Ref<boolean> = ref(false)
@@ -120,6 +130,7 @@ export default defineComponent({
120
130
  title,
121
131
  languages,
122
132
  nonEmptyLanguages,
133
+ playground,
123
134
  github,
124
135
  isOpenMenu,
125
136
  darkMode,
@@ -201,6 +212,12 @@ export default defineComponent({
201
212
  align-items: center;
202
213
  }
203
214
 
215
+ @media screen and (max-width: 400px) {
216
+ &__tail {
217
+ display: none;
218
+ }
219
+ }
220
+
204
221
  &__language {
205
222
  border-radius: 3px;
206
223
  height: 40px;
@@ -30,6 +30,7 @@ module.exports = {
30
30
  'en-US': 'English',
31
31
  },
32
32
  github: 'https://github.com/varletjs/varlet',
33
+ playground: 'https://varlet.gitee.io/varlet-ui-playground',
33
34
  darkMode: true,
34
35
  },
35
36
  clipboard: {