@varlet/cli 3.2.7 → 3.2.9-alpha.1715269079229

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 CHANGED
@@ -59,8 +59,9 @@ Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varle
59
59
  | `md3DarkTheme` | md3 dark mode document theme | _Record<string, any>_ | `-` |
60
60
  | `highlight` | Document code snippet style related | _{ style: string }_ | `-` |
61
61
  | `analysis` | Document statistics related | _{ baidu: string }_ | `-` |
62
- | `pc` | PC side document structure configuration | _Record<string, any>_ | `-` |
63
- | `mobile` | Mobile document structure configuration | _Record<string, any>_ | `-` |
62
+ | `pc` | PC side document structure configuration | _[VarletConfigPc](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
63
+ | `mobile` | Mobile document structure configuration | _[VarletConfigMobile](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
64
+ | `bundle` | Bundle output options | _{ external: string[], globals: Record<string, string> }_ | `-` |
64
65
  | `directives` | Component library directive folder name | _string[]_ | `[]` |
65
66
  | `copy` | Copy file configuration | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `- ` |
66
67
  | `icons` | Font icon packaging related configurations | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts) _ | `-` |
package/README.zh-CN.md CHANGED
@@ -59,8 +59,9 @@ varlet-cli gen
59
59
  | `md3DarkTheme` | md3 暗黑模式文档主题 | _Record<string, any>_ | `-` |
60
60
  | `highlight` | 文档代码片段样式相关 | _{ style: string }_ | `-` |
61
61
  | `analysis` | 文档统计相关 | _{ baidu: string }_ | `-` |
62
- | `pc` | pc 端文档结构配置 | _Record<string, any>_ | `-` |
63
- | `mobile` | mobile 端文档结构配置 | _Record<string, any>_ | `-` |
62
+ | `pc` | pc 端文档结构配置 | _[VarletConfigPc](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
63
+ | `mobile` | mobile 端文档结构配置 | _[VarletConfigMobile](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
64
+ | `bundle` | 组件库编译的捆绑产物配置 | _{ external: string[], globals: Record<string, string> }_ | `-` |
64
65
  | `directives` | 组件库指令文件夹名称 | _string[]_ | `[]` |
65
66
  | `copy` | 复制文件配置 | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
66
67
  | `icons` | 字体图标打包相关配置 | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
@@ -18,4 +18,5 @@ export declare function onThemeChange(cb?: (theme: Theme) => void): void;
18
18
  export declare function getSiteStyleVars(theme: Theme): StyleVars;
19
19
  export declare function setColorScheme(theme: Theme): void;
20
20
  export declare function watchTheme(cb: (theme: Theme, from: 'pc' | 'mobile' | 'default' | 'playground') => void, shouldUnmount?: boolean): void;
21
+ export declare function getMobileIndex(): "./mobile" | "./mobile.html";
21
22
  export { AppType, StyleProvider };
@@ -102,4 +102,8 @@ export function watchTheme(cb, shouldUnmount = true) {
102
102
  }
103
103
  cb(getBrowserTheme(), 'default');
104
104
  }
105
+ export function getMobileIndex() {
106
+ const isCf = window.location.origin.includes('pages.dev');
107
+ return isCf ? './mobile' : './mobile.html';
108
+ }
105
109
  export { AppType, StyleProvider };
@@ -10,6 +10,94 @@ export interface VarletConfigIcons extends VIConfig {
10
10
  export interface VarletConfigEsbuild {
11
11
  target?: string | string[];
12
12
  }
13
+ export interface VarletConfigHtmlInjectPoint {
14
+ position?: 'start' | 'end' | 'script-start';
15
+ content?: string;
16
+ }
17
+ export interface VarletConfigHtmlInject {
18
+ head?: VarletConfigHtmlInjectPoint[];
19
+ body?: VarletConfigHtmlInjectPoint[];
20
+ }
21
+ export interface VarletConfigPcMenu {
22
+ text: Record<string, string>;
23
+ type: number;
24
+ doc?: string;
25
+ }
26
+ export interface VarletConfigPcHeader {
27
+ i18n?: Record<string, string>;
28
+ currentVersion?: string;
29
+ github?: string;
30
+ changelog?: string;
31
+ playground?: string;
32
+ themes?: Record<string, string>[];
33
+ versions?: {
34
+ name: string;
35
+ items?: {
36
+ label?: string;
37
+ link?: string;
38
+ }[];
39
+ }[];
40
+ }
41
+ export interface VarletConfigMobileHeader {
42
+ i18n?: Record<string, string>;
43
+ github?: string;
44
+ themes?: Record<string, string>[];
45
+ }
46
+ export interface VarletConfigPcIndexPage {
47
+ description?: Record<string, string>;
48
+ started?: Record<string, string>;
49
+ viewOnGithub?: Record<string, string>;
50
+ features?: {
51
+ name: Record<string, string>;
52
+ description: Record<string, string>;
53
+ }[];
54
+ teamMembers?: {
55
+ label: Record<string, string>;
56
+ members: {
57
+ name?: Record<string, string>;
58
+ title?: Record<string, string>;
59
+ description?: Record<string, string>;
60
+ avatar?: string;
61
+ github?: string;
62
+ twitter?: string;
63
+ }[];
64
+ };
65
+ contributors?: {
66
+ label?: Record<string, string>;
67
+ link?: string;
68
+ image?: string;
69
+ };
70
+ sponsors?: {
71
+ label?: Record<string, string>;
72
+ link?: string;
73
+ image?: string;
74
+ };
75
+ license?: Record<string, string>;
76
+ copyright?: Record<string, string>;
77
+ }
78
+ export interface VarletConfigPc {
79
+ title?: Record<string, string>;
80
+ description?: Record<string, string>;
81
+ keywords?: Record<string, string>;
82
+ redirect?: string;
83
+ clipboard?: Record<string, string>;
84
+ indexPage?: VarletConfigPcIndexPage;
85
+ header?: VarletConfigPcHeader;
86
+ menu?: VarletConfigPcMenu[];
87
+ htmlInject?: VarletConfigHtmlInject;
88
+ fold?: {
89
+ defaultFold?: boolean;
90
+ foldHeight?: number;
91
+ };
92
+ }
93
+ export interface VarletConfigMobile {
94
+ title?: Record<string, string>;
95
+ description?: Record<string, string>;
96
+ keywords?: Record<string, string>;
97
+ redirect?: string;
98
+ header?: VarletConfigMobileHeader;
99
+ htmlInject?: VarletConfigHtmlInject;
100
+ }
13
101
  export interface VarletConfig {
14
102
  /**
15
103
  * @default `Varlet`
@@ -53,11 +141,15 @@ export interface VarletConfig {
53
141
  analysis?: {
54
142
  baidu: string;
55
143
  };
56
- pc?: Record<string, any>;
57
- mobile?: Record<string, any>;
144
+ pc?: VarletConfigPc;
145
+ mobile?: VarletConfigMobile;
58
146
  copy?: CopyOptions['paths'];
59
147
  icons?: VarletConfigIcons;
60
148
  esbuild?: VarletConfigEsbuild;
149
+ bundle?: {
150
+ external?: string[];
151
+ globals?: Record<string, string>;
152
+ };
61
153
  /**
62
154
  * @default `[]`
63
155
  * Directive folder name for component library.
@@ -17,7 +17,7 @@ export default defineConfig({
17
17
  host: 'localhost',
18
18
  port: 8080,
19
19
  title: 'VARLET',
20
- logo: 'https://varletjs.github.io/varlet/varlet_icon.png',
20
+ logo: 'varlet_icon.png',
21
21
  defaultLanguage: 'zh-CN',
22
22
  highlight: {
23
23
  /**
@@ -421,15 +421,15 @@ export default defineConfig({
421
421
  currentVersion: 'v3.x',
422
422
  versions: [
423
423
  {
424
- name: 'varlet.gitee.io',
424
+ name: 'varlet.pages.dev',
425
425
  items: [
426
426
  {
427
427
  label: 'v3.x',
428
- link: 'https://varletjs.github.io/varlet',
428
+ link: 'https://varlet.pages.dev',
429
429
  },
430
430
  {
431
431
  label: 'v2.x',
432
- link: 'https://varletjs.github.io/varlet/v2',
432
+ link: 'https://varlet.pages.dev/v2',
433
433
  },
434
434
  ],
435
435
  },
@@ -465,6 +465,10 @@ export default defineConfig({
465
465
  defaultFold: false,
466
466
  foldHeight: 50,
467
467
  },
468
+ htmlInject: {
469
+ head: [],
470
+ body: [],
471
+ },
468
472
  },
469
473
  mobile: {
470
474
  title,
@@ -484,6 +488,10 @@ export default defineConfig({
484
488
  { 'zh-CN': 'Md3 暗色', 'en-US': 'Md3 Dark', value: 'md3DarkTheme' },
485
489
  ],
486
490
  },
491
+ htmlInject: {
492
+ head: [],
493
+ body: [],
494
+ },
487
495
  },
488
496
  themeKey: 'VARLET_V3_THEME',
489
497
  defaultLightTheme: 'md3LightTheme',
@@ -1,5 +1,17 @@
1
1
  import { InlineConfig } from 'vite';
2
- import { VarletConfig } from './varlet.config.js';
2
+ import { VarletConfig, type VarletConfigHtmlInject } from './varlet.config.js';
3
+ export declare function getHtmlInject(inject: VarletConfigHtmlInject): {
4
+ head: {
5
+ start: (string | undefined)[];
6
+ end: (string | undefined)[];
7
+ scriptStart: (string | undefined)[];
8
+ };
9
+ body: {
10
+ start: (string | undefined)[];
11
+ end: (string | undefined)[];
12
+ scriptStart: (string | undefined)[];
13
+ };
14
+ };
3
15
  export declare function getDevConfig(varletConfig: Required<VarletConfig>): InlineConfig;
4
16
  export declare function getBuildConfig(varletConfig: Required<VarletConfig>): InlineConfig;
5
17
  export interface BundleBuildOptions {
@@ -4,6 +4,21 @@ import { get } from 'lodash-es';
4
4
  import { resolve } from 'path';
5
5
  import vue from '@vitejs/plugin-vue';
6
6
  import jsx from '@vitejs/plugin-vue-jsx';
7
+ export function getHtmlInject(inject) {
8
+ const getContent = (injectKey, position) => inject[injectKey]?.filter((point) => point.position === position).map((point) => point.content) ?? [];
9
+ return {
10
+ head: {
11
+ start: getContent('head', 'start'),
12
+ end: getContent('head', 'end'),
13
+ scriptStart: getContent('head', 'script-start'),
14
+ },
15
+ body: {
16
+ start: getContent('body', 'start'),
17
+ end: getContent('body', 'end'),
18
+ scriptStart: getContent('body', 'script-start'),
19
+ },
20
+ };
21
+ }
7
22
  export function getDevConfig(varletConfig) {
8
23
  const defaultLanguage = get(varletConfig, 'defaultLanguage');
9
24
  const alias = get(varletConfig, 'alias', {});
@@ -43,9 +58,11 @@ export function getDevConfig(varletConfig) {
43
58
  pcTitle: get(varletConfig, `pc.title['${defaultLanguage}']`),
44
59
  pcDescription: get(varletConfig, `pc.description['${defaultLanguage}']`),
45
60
  pcKeywords: get(varletConfig, `pc.keywords['${defaultLanguage}']`),
61
+ pcHtmlInject: getHtmlInject(get(varletConfig, 'pc.htmlInject')),
46
62
  mobileTitle: get(varletConfig, `mobile.title['${defaultLanguage}']`),
47
63
  mobileDescription: get(varletConfig, `mobile.description['${defaultLanguage}']`),
48
64
  mobileKeywords: get(varletConfig, `mobile.keywords['${defaultLanguage}']`),
65
+ mobileHtmlInject: getHtmlInject(get(varletConfig, 'mobile.htmlInject')),
49
66
  },
50
67
  }),
51
68
  ],
@@ -73,6 +90,8 @@ export function getBuildConfig(varletConfig) {
73
90
  export function getBundleConfig(varletConfig, buildOptions) {
74
91
  const plugins = [];
75
92
  const name = get(varletConfig, 'name');
93
+ const external = get(varletConfig, 'bundle.external', []);
94
+ const globals = get(varletConfig, 'bundle.globals', {});
76
95
  const { fileName, output, format, emptyOutDir, removeEnv } = buildOptions;
77
96
  if (format === 'umd') {
78
97
  plugins.push(inlineCss({
@@ -99,12 +118,13 @@ export function getBundleConfig(varletConfig, buildOptions) {
99
118
  entry: resolve(ES_DIR, 'index.bundle.mjs'),
100
119
  },
101
120
  rollupOptions: {
102
- external: ['vue'],
121
+ external: ['vue', ...external],
103
122
  output: {
104
123
  dir: output,
105
124
  exports: 'named',
106
125
  globals: {
107
126
  vue: 'Vue',
127
+ ...globals,
108
128
  },
109
129
  },
110
130
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "3.2.7",
3
+ "version": "3.2.9-alpha.1715269079229",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -65,8 +65,8 @@
65
65
  "sharp": "0.31.1",
66
66
  "slash": "^3.0.0",
67
67
  "typescript": "^5.1.5",
68
- "@varlet/shared": "3.2.7",
69
- "@varlet/vite-plugins": "3.2.7"
68
+ "@varlet/shared": "3.2.9-alpha.1715269079229",
69
+ "@varlet/vite-plugins": "3.2.9-alpha.1715269079229"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/babel__core": "^7.20.1",
@@ -81,9 +81,9 @@
81
81
  "@types/semver": "^7.3.9",
82
82
  "@types/sharp": "0.31.1",
83
83
  "rimraf": "^5.0.1",
84
- "@varlet/ui": "3.2.7",
85
- "@varlet/icons": "3.2.7",
86
- "@varlet/touch-emulator": "3.2.7"
84
+ "@varlet/ui": "3.2.9-alpha.1715269079229",
85
+ "@varlet/icons": "3.2.9-alpha.1715269079229",
86
+ "@varlet/touch-emulator": "3.2.9-alpha.1715269079229"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@vue/runtime-core": "3.4.21",
@@ -96,9 +96,9 @@
96
96
  "lodash-es": "^4.17.21",
97
97
  "vue": "3.4.21",
98
98
  "vue-router": "4.2.0",
99
- "@varlet/ui": "3.2.7",
100
- "@varlet/icons": "3.2.7",
101
- "@varlet/touch-emulator": "3.2.7"
99
+ "@varlet/ui": "3.2.9-alpha.1715269079229",
100
+ "@varlet/touch-emulator": "3.2.9-alpha.1715269079229",
101
+ "@varlet/icons": "3.2.9-alpha.1715269079229"
102
102
  },
103
103
  "scripts": {
104
104
  "dev": "tsc --watch",
package/site/index.html CHANGED
@@ -1,6 +1,11 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
+ <%
5
+ pcHtmlInject.head.start.forEach(function(tag) { %>
6
+ <%- tag %>
7
+ <% });
8
+ %>
4
9
  <meta charset="UTF-8" />
5
10
  <title><%= pcTitle %></title>
6
11
  <meta http-equiv="Cache-Control" content="no-cache">
@@ -32,6 +37,11 @@
32
37
  color: var(--site-config-color-text);
33
38
  }
34
39
  </style>
40
+ <%
41
+ pcHtmlInject.head.scriptStart.forEach(function(tag) { %>
42
+ <%- tag %>
43
+ <% });
44
+ %>
35
45
  <script>
36
46
  if ('<%= baidu %>') {
37
47
  var _hmt = _hmt || [];
@@ -57,10 +67,29 @@
57
67
  }
58
68
  })
59
69
  </script>
70
+ <%
71
+ pcHtmlInject.head.end.forEach(function(tag) { %>
72
+ <%- tag %>
73
+ <% });
74
+ %>
60
75
  </head>
61
76
  <body>
77
+ <%
78
+ pcHtmlInject.body.start.forEach(function(tag) { %>
79
+ <%- tag %>
80
+ <% });
81
+ %>
62
82
  <div id="app"></div>
63
-
83
+ <%
84
+ pcHtmlInject.body.scriptStart.forEach(function(tag) { %>
85
+ <%- tag %>
86
+ <% });
87
+ %>
64
88
  <script type="module" src="/pc/main.ts"></script>
89
+ <%
90
+ pcHtmlInject.body.end.forEach(function(tag) { %>
91
+ <%- tag %>
92
+ <% });
93
+ %>
65
94
  </body>
66
95
  </html>
@@ -89,6 +89,7 @@ import {
89
89
  watchLang,
90
90
  watchTheme,
91
91
  setTheme,
92
+ getMobileIndex,
92
93
  type Theme,
93
94
  } from '@varlet/cli/client'
94
95
  import { removeEmpty, inIframe, isPhone } from '../utils'
@@ -114,7 +115,7 @@ export default defineComponent({
114
115
  const changeLanguage = (lang: string) => {
115
116
  language.value = lang
116
117
  showMenu.value = false
117
- window.location.href = `./mobile.html#${route.path}?language=${language.value}&replace=${route.query.replace}`
118
+ window.location.href = `${getMobileIndex()}#${route.path}?language=${language.value}&replace=${route.query.replace}`
118
119
 
119
120
  if (!isPhone() && inIframe()) {
120
121
  ;(window.top as any).scrollToMenu(redirect.slice(1))
@@ -122,7 +123,7 @@ export default defineComponent({
122
123
  }
123
124
 
124
125
  const back = () => {
125
- window.location.href = `./mobile.html#${redirect}?language=${language.value}&replace=${redirect.slice(1)}`
126
+ window.location.href = `${getMobileIndex()}#${redirect}?language=${language.value}&replace=${redirect.slice(1)}`
126
127
 
127
128
  if (!isPhone() && inIframe()) {
128
129
  ;(window.top as any).scrollToMenu(redirect.slice(1))
package/site/mobile.html CHANGED
@@ -1,6 +1,11 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
+ <%
5
+ mobileHtmlInject.head.start.forEach(function(tag) { %>
6
+ <%- tag %>
7
+ <% });
8
+ %>
4
9
  <meta charset="UTF-8" />
5
10
  <title><%= mobileTitle %></title>
6
11
  <meta http-equiv="Cache-Control" content="no-cache">
@@ -27,6 +32,11 @@
27
32
  font-display: swap;
28
33
  }
29
34
  </style>
35
+ <%
36
+ mobileHtmlInject.head.scriptStart.forEach(function(tag) { %>
37
+ <%- tag %>
38
+ <% });
39
+ %>
30
40
  <script>
31
41
  if ('<%= baidu %>') {
32
42
  var _hmt = _hmt || [];
@@ -38,10 +48,29 @@
38
48
  })()
39
49
  }
40
50
  </script>
51
+ <%
52
+ mobileHtmlInject.head.end.forEach(function(tag) { %>
53
+ <%- tag %>
54
+ <% });
55
+ %>
41
56
  </head>
42
57
  <body>
58
+ <%
59
+ mobileHtmlInject.body.start.forEach(function(tag) { %>
60
+ <%- tag %>
61
+ <% });
62
+ %>
43
63
  <div id="app"></div>
44
-
64
+ <%
65
+ mobileHtmlInject.body.scriptStart.forEach(function(tag) { %>
66
+ <%- tag %>
67
+ <% });
68
+ %>
45
69
  <script type="module" src="/mobile/main.ts"></script>
70
+ <%
71
+ mobileHtmlInject.body.end.forEach(function(tag) { %>
72
+ <%- tag %>
73
+ <% });
74
+ %>
46
75
  </body>
47
76
  </html>
package/site/pc/App.vue CHANGED
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import config from '@config'
3
3
  import { defineComponent, onMounted, ref } from 'vue'
4
- import { getPCLocationInfo } from '@varlet/cli/client'
4
+ import { getPCLocationInfo, getMobileIndex } from '@varlet/cli/client'
5
5
  import { isPhone } from '../utils'
6
6
  import { get } from 'lodash-es'
7
7
 
@@ -14,7 +14,7 @@ export default defineComponent({
14
14
  const { language, menuName } = getPCLocationInfo()
15
15
 
16
16
  if (isPhone() && useMobile.value) {
17
- window.location.href = `./mobile.html#/${menuName}?language=${language || defaultLanguage}&platform=mobile`
17
+ window.location.href = `${getMobileIndex()}#/${menuName}?language=${language || defaultLanguage}&platform=mobile`
18
18
  return
19
19
  }
20
20
  }
@@ -1,12 +1,14 @@
1
1
  <template>
2
2
  <div class="varlet-site-mobile varlet-site-mobile--375">
3
3
  <div class="varlet-site-mobile-content">
4
- <iframe id="mobile" :src="`./mobile.html#/${componentName}?language=${language}&platform=pc&replace=${replace}${hash ? `#${hash}` : ''}`"></iframe>
4
+ <iframe id="mobile" :src="`${getMobileIndex()}#/${componentName}?language=${language}&platform=pc&replace=${replace}${hash ? `#${hash}` : ''}`"></iframe>
5
5
  </div>
6
6
  </div>
7
7
  </template>
8
8
 
9
9
  <script lang="ts">
10
+ import { getMobileIndex } from '@varlet/cli/client'
11
+
10
12
  export default {
11
13
  name: 'AppMobile',
12
14
  props: {
@@ -22,6 +24,11 @@ export default {
22
24
  hash: {
23
25
  type: String
24
26
  }
27
+ },
28
+ setup() {
29
+ return {
30
+ getMobileIndex
31
+ }
25
32
  }
26
33
  }
27
34
  </script>