@quiteer/vite 0.1.1 → 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,8 +1,9 @@
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 { AutoImport, Components, Icons, IconsResolver, NaiveUiResolver, Progress, Vue, VueDevTools, VueJsx, bootstrapEnv, createSvgIconsPlugin, envConfigPlugin, fileChangeLoggerPlugin, mockRouterPlugin, removeConsolePlugin, virtualHtmlPlugin } from "@quiteer/vite-plugins";
6
7
  import path, { join, resolve } from "node:path";
7
8
  import { cwd } from "node:process";
8
9
  import { isFunction } from "@quiteer/is";
@@ -12,7 +13,7 @@ import { setTimeout } from "node:timers/promises";
12
13
  import { getPortPromise } from "portfinder";
13
14
 
14
15
  //#region package.json
15
- var version = "0.1.1";
16
+ var version = "0.1.2";
16
17
 
17
18
  //#endregion
18
19
  //#region src/store.ts
@@ -30,12 +31,10 @@ store.set("prefixes", ["QVITE_", "VITE_"]);
30
31
  //#region src/defaults.ts
31
32
  function getDefaultOptions() {
32
33
  const root$1 = store.get("root");
33
- const src = resolve(root$1, "src");
34
- console.log("src :>> ", src);
35
34
  return {
35
+ UnoCSS: false,
36
36
  plugins: {
37
37
  Vue: [{ customElement: true }],
38
- UnoCSS: false,
39
38
  VueDevTools: [{}],
40
39
  VueJsx: [{}],
41
40
  Progress: [{}],
@@ -92,7 +91,6 @@ var plugins_default = {
92
91
  Vue,
93
92
  VueDevTools,
94
93
  VueJsx,
95
- UnoCSS,
96
94
  Components,
97
95
  SvgIcons: createSvgIconsPlugin,
98
96
  Icons,
@@ -101,11 +99,37 @@ var plugins_default = {
101
99
 
102
100
  //#endregion
103
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
+ }
104
127
  async function normalizeConfig(raw) {
105
128
  return deepMerge(getDefaultOptions(), raw);
106
129
  }
107
130
  function geVitePlugins(config) {
108
- const { html, env, plugins } = config;
131
+ const { env, plugins } = config;
132
+ const html = withUnoInjection(config);
109
133
  return [
110
134
  ...Object.keys(plugins).map((key) => {
111
135
  const pluginOptions = plugins[key];
@@ -114,7 +138,8 @@ function geVitePlugins(config) {
114
138
  return null;
115
139
  }).filter(Boolean),
116
140
  virtualHtmlPlugin(html),
117
- envConfigPlugin(env)
141
+ envConfigPlugin(env),
142
+ config.UnoCSS ? UnoCSS() : void 0
118
143
  ];
119
144
  }
120
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.1",
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.17"
63
+ "@quiteer/vite-plugins": "^0.1.2"
63
64
  },
64
65
  "scripts": {
65
66
  "dev": "tsdown -w",