@quiteer/vite 0.1.0 → 0.1.2

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.
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { cac } from "cac";
3
3
  import { build, createServer, loadEnv, mergeConfig } from "vite";
4
+ import UnoCSS from "@quiteer/unocss";
4
5
  import { PersistentStore, deepMerge } from "@quiteer/utils";
5
- import { AutoImport, Components, Icons, IconsResolver, NaiveUiResolver, Progress, UnoCSS, Vue, VueDevTools, VueJsx, bootstrapEnv, createSvgIconsPlugin, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
6
- import { fileURLToPath } from "node:url";
6
+ import { AutoImport, Components, Icons, IconsResolver, NaiveUiResolver, Progress, Vue, VueDevTools, VueJsx, bootstrapEnv, createSvgIconsPlugin, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
7
+ import path, { join, resolve } from "node:path";
7
8
  import { cwd } from "node:process";
8
- import path, { join } from "node:path";
9
9
  import { isFunction } from "@quiteer/is";
10
10
  import { parserConfig } from "@quiteer/parser-config";
11
11
  import { pathExists } from "fs-extra";
@@ -13,57 +13,73 @@ import { setTimeout } from "node:timers/promises";
13
13
  import { getPortPromise } from "portfinder";
14
14
 
15
15
  //#region package.json
16
- var version = "0.1.0";
16
+ var version = "0.1.2";
17
+
18
+ //#endregion
19
+ //#region src/store.ts
20
+ const store = PersistentStore.getInstance("qvite");
21
+ store.set("root", cwd());
22
+ store.set("command", "serve");
23
+ store.set("config", "qvite.config.ts");
24
+ store.set("mode", "development");
25
+ store.set("env", {});
26
+ store.set("minify", false);
27
+ store.set("port", 8080);
28
+ store.set("prefixes", ["QVITE_", "VITE_"]);
17
29
 
18
30
  //#endregion
19
31
  //#region src/defaults.ts
20
- const defaultOptions = {
21
- plugins: {
22
- Vue: [{ customElement: true }],
32
+ function getDefaultOptions() {
33
+ const root$1 = store.get("root");
34
+ return {
23
35
  UnoCSS: false,
24
- VueDevTools: [{}],
25
- VueJsx: [{}],
26
- Progress: [{}],
27
- FileChangeLogger: false,
28
- RemoveConsole: false,
29
- MockRouter: false,
30
- Icons: false,
31
- SvgIcons: false,
32
- AutoImport: [{ imports: [
33
- "vue",
34
- "vue-router",
35
- { "naive-ui": [
36
- "useDialog",
37
- "useMessage",
38
- "useNotification",
39
- "useLoadingBar"
40
- ] }
41
- ] }],
42
- Components: [{
43
- types: [{
44
- from: "vue-router",
45
- names: ["RouterLink", "RouterView"]
46
- }],
47
- resolvers: [NaiveUiResolver(), IconsResolver({
48
- customCollections: "local",
49
- componentPrefix: "icon-loacl"
50
- })]
51
- }]
52
- },
53
- html: {},
54
- env: {
55
- obfuscate: false,
56
- requiredKeys: ["desc"]
57
- },
58
- vite: {
59
- server: {
60
- port: 3e3,
61
- strictPort: false
36
+ plugins: {
37
+ Vue: [{ customElement: true }],
38
+ VueDevTools: [{}],
39
+ VueJsx: [{}],
40
+ Progress: [{}],
41
+ FileChangeLogger: false,
42
+ RemoveConsole: false,
43
+ MockRouter: false,
44
+ Icons: false,
45
+ SvgIcons: false,
46
+ AutoImport: [{ imports: [
47
+ "vue",
48
+ "vue-router",
49
+ { "naive-ui": [
50
+ "useDialog",
51
+ "useMessage",
52
+ "useNotification",
53
+ "useLoadingBar"
54
+ ] }
55
+ ] }],
56
+ Components: [{
57
+ types: [{
58
+ from: "vue-router",
59
+ names: ["RouterLink", "RouterView"]
60
+ }],
61
+ resolvers: [NaiveUiResolver(), IconsResolver({
62
+ customCollections: "local",
63
+ componentPrefix: "icon-loacl"
64
+ })]
65
+ }]
62
66
  },
63
- resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) } },
64
- build: { minify: false }
65
- }
66
- };
67
+ html: {},
68
+ env: {
69
+ obfuscate: false,
70
+ requiredKeys: ["desc"]
71
+ },
72
+ vite: {
73
+ server: {
74
+ port: 3e3,
75
+ open: false,
76
+ strictPort: false
77
+ },
78
+ resolve: { alias: { "@": resolve(root$1, "src") } },
79
+ build: { minify: false }
80
+ }
81
+ };
82
+ }
67
83
 
68
84
  //#endregion
69
85
  //#region src/plugins.ts
@@ -75,32 +91,45 @@ var plugins_default = {
75
91
  Vue,
76
92
  VueDevTools,
77
93
  VueJsx,
78
- UnoCSS,
79
94
  Components,
80
95
  SvgIcons: createSvgIconsPlugin,
81
96
  Icons,
82
97
  AutoImport
83
98
  };
84
99
 
85
- //#endregion
86
- //#region src/store.ts
87
- const store = PersistentStore.getInstance("qvite");
88
- store.set("root", cwd());
89
- store.set("command", "serve");
90
- store.set("config", "qvite.config.ts");
91
- store.set("mode", "development");
92
- store.set("env", {});
93
- store.set("minify", false);
94
- store.set("port", 8080);
95
- store.set("prefixes", ["QVITE_", "VITE_"]);
96
-
97
100
  //#endregion
98
101
  //#region src/transform.ts
102
+ function withUnoInjection(config) {
103
+ const { html } = config;
104
+ if (!config.UnoCSS) return html;
105
+ const injection = {
106
+ tag: "script",
107
+ attrs: { type: "module" },
108
+ children: `import 'uno.css'`,
109
+ position: "head"
110
+ };
111
+ const next = { ...html };
112
+ if (next.pages) {
113
+ const pages = {};
114
+ for (const [k, v] of Object.entries(next.pages)) {
115
+ const cfg = { ...v || {} };
116
+ cfg.tags = [...cfg.tags ?? [], injection];
117
+ pages[k] = cfg;
118
+ }
119
+ next.pages = pages;
120
+ } else {
121
+ const cfg = { ...next.config || {} };
122
+ cfg.tags = [...cfg.tags ?? [], injection];
123
+ next.config = cfg;
124
+ }
125
+ return next;
126
+ }
99
127
  async function normalizeConfig(raw) {
100
- return deepMerge(defaultOptions, raw);
128
+ return deepMerge(getDefaultOptions(), raw);
101
129
  }
102
130
  function geVitePlugins(config) {
103
- const { html, env, plugins } = config;
131
+ const { env, plugins } = config;
132
+ const html = withUnoInjection(config);
104
133
  return [
105
134
  ...Object.keys(plugins).map((key) => {
106
135
  const pluginOptions = plugins[key];
@@ -109,7 +138,8 @@ function geVitePlugins(config) {
109
138
  return null;
110
139
  }).filter(Boolean),
111
140
  virtualHtmlPlugin(html),
112
- envConfigPlugin(env)
141
+ envConfigPlugin(env),
142
+ config.UnoCSS ? UnoCSS() : void 0
113
143
  ];
114
144
  }
115
145
  async function toViteInlineConfig(config) {
package/dist/index.d.mts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { UserConfig, defineConfig as defineConfig$1 } from "tsdown";
2
2
  import { UserConfig as UserConfig$1, defineConfig as defineConfig$2 } from "vite";
3
- import { AutoImport, Components, EnvConfig, EnvConfigPluginOptions, FileSystemIconLoader, Icons, IconsResolver, NaiveUiResolver, Progress, UnoCSS, VirtualHtmlOptions, Vue, VueDevTools, VueJsx, createSvgIconsPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin } from "@quiteer/vite-plugins";
3
+ import { AutoImport, Components, EnvConfig, EnvConfigPluginOptions, FileSystemIconLoader, Icons, IconsResolver, NaiveUiResolver, Progress, VirtualHtmlOptions, Vue, VueDevTools, VueJsx, createSvgIconsPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin } from "@quiteer/vite-plugins";
4
4
 
5
5
  //#region src/typings.d.ts
6
6
  type PluginOptions<T extends (...args: any) => any> = boolean | Parameters<T>;
7
7
  interface QvitePlugins {
8
8
  Vue?: PluginOptions<typeof Vue>;
9
- UnoCSS?: PluginOptions<typeof UnoCSS>;
10
9
  VueJsx?: PluginOptions<typeof VueJsx>;
11
10
  Progress?: PluginOptions<typeof Progress>;
12
11
  VueDevTools?: PluginOptions<typeof VueDevTools>;
@@ -19,6 +18,7 @@ interface QvitePlugins {
19
18
  AutoImport?: PluginOptions<typeof AutoImport>;
20
19
  }
21
20
  interface QviteConfig {
21
+ UnoCSS?: boolean;
22
22
  vite?: UserConfig$1;
23
23
  tsdown?: UserConfig | UserConfig[];
24
24
  plugins?: QvitePlugins;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quiteer/vite",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "在 vite 的基础上增强的前端架构 cli",
6
6
  "author": "quiteer",
7
7
  "license": "MIT",
@@ -58,8 +58,9 @@
58
58
  "vite": "npm:rolldown-vite@7.2.2",
59
59
  "zx": "^8.8.5",
60
60
  "@quiteer/is": "0.0.2",
61
+ "@quiteer/unocss": "0.0.0",
61
62
  "@quiteer/utils": "0.0.2",
62
- "@quiteer/vite-plugins": "^0.0.16"
63
+ "@quiteer/vite-plugins": "^0.1.2"
63
64
  },
64
65
  "scripts": {
65
66
  "dev": "tsdown -w",