@vixt/core 0.0.6 → 0.0.8

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vite from 'vite';
2
- import { PluginOption, UserConfig, TransformResult, ProxyOptions } from 'vite';
2
+ import { PluginOption, UserConfig, TransformResult } from 'vite';
3
3
  import * as c12 from 'c12';
4
4
  import { ConfigLayer, LoadConfigOptions } from 'c12';
5
5
  import { TSConfig } from 'pkg-types';
@@ -95,27 +95,6 @@ declare const app: VixtModule<AppOptions>;
95
95
 
96
96
  declare const config: VixtModule<ModuleOptions>;
97
97
 
98
- declare module '@vixt/core' {
99
- interface VixtOptions {
100
- devProxy?: DevProxyOptions;
101
- }
102
- }
103
- interface DevProxyOptions {
104
- /**
105
- * 环境变量的 key
106
- * @default 'VITE_PROXY'
107
- */
108
- key?: string;
109
- }
110
- /**
111
- * @param list [prefix,target,rewrite?][]
112
- */
113
- declare function transformProxy(list: string): {
114
- [k: string]: ProxyOptions;
115
- };
116
- /** 为 vite 开发服务添加代理配置 */
117
- declare const devProxy: VixtModule<DevProxyOptions>;
118
-
119
98
  declare module '@vixt/core' {
120
99
  interface VixtOptions {
121
100
  typescript?: TypescriptOptions;
@@ -132,24 +111,6 @@ interface TypescriptOptions {
132
111
  }
133
112
  declare const typescript: VixtModule<TypescriptOptions>;
134
113
 
135
- declare module '@vixt/core' {
136
- interface VixtOptions {
137
- warmup?: WarmupOptions;
138
- }
139
- }
140
- interface WarmupOptions {
141
- enabled?: boolean;
142
- /**
143
- * The files to be transformed and used on the client-side. Supports glob patterns.
144
- */
145
- clientFiles?: string[];
146
- /**
147
- * The files to be transformed and used in SSR. Supports glob patterns.
148
- */
149
- ssrFiles?: string[];
150
- }
151
- declare const warmup: VixtModule<WarmupOptions>;
152
-
153
114
  declare function defineVixtConfig(input: VixtOptions): VixtOptions;
154
115
  declare const rootDir: string;
155
116
  declare const buildDir = ".vixt";
@@ -165,4 +126,4 @@ declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModu
165
126
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
166
127
  declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
167
128
 
168
- export { type AppHead, type AppOptions, type DevProxyOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, type WarmupOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, transformProxy, typescript, warmup };
129
+ export { type AppHead, type AppOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vite from 'vite';
2
- import { PluginOption, UserConfig, TransformResult, ProxyOptions } from 'vite';
2
+ import { PluginOption, UserConfig, TransformResult } from 'vite';
3
3
  import * as c12 from 'c12';
4
4
  import { ConfigLayer, LoadConfigOptions } from 'c12';
5
5
  import { TSConfig } from 'pkg-types';
@@ -95,27 +95,6 @@ declare const app: VixtModule<AppOptions>;
95
95
 
96
96
  declare const config: VixtModule<ModuleOptions>;
97
97
 
98
- declare module '@vixt/core' {
99
- interface VixtOptions {
100
- devProxy?: DevProxyOptions;
101
- }
102
- }
103
- interface DevProxyOptions {
104
- /**
105
- * 环境变量的 key
106
- * @default 'VITE_PROXY'
107
- */
108
- key?: string;
109
- }
110
- /**
111
- * @param list [prefix,target,rewrite?][]
112
- */
113
- declare function transformProxy(list: string): {
114
- [k: string]: ProxyOptions;
115
- };
116
- /** 为 vite 开发服务添加代理配置 */
117
- declare const devProxy: VixtModule<DevProxyOptions>;
118
-
119
98
  declare module '@vixt/core' {
120
99
  interface VixtOptions {
121
100
  typescript?: TypescriptOptions;
@@ -132,24 +111,6 @@ interface TypescriptOptions {
132
111
  }
133
112
  declare const typescript: VixtModule<TypescriptOptions>;
134
113
 
135
- declare module '@vixt/core' {
136
- interface VixtOptions {
137
- warmup?: WarmupOptions;
138
- }
139
- }
140
- interface WarmupOptions {
141
- enabled?: boolean;
142
- /**
143
- * The files to be transformed and used on the client-side. Supports glob patterns.
144
- */
145
- clientFiles?: string[];
146
- /**
147
- * The files to be transformed and used in SSR. Supports glob patterns.
148
- */
149
- ssrFiles?: string[];
150
- }
151
- declare const warmup: VixtModule<WarmupOptions>;
152
-
153
114
  declare function defineVixtConfig(input: VixtOptions): VixtOptions;
154
115
  declare const rootDir: string;
155
116
  declare const buildDir = ".vixt";
@@ -165,4 +126,4 @@ declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModu
165
126
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
166
127
  declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
167
128
 
168
- export { type AppHead, type AppOptions, type DevProxyOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, type WarmupOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, transformProxy, typescript, warmup };
129
+ export { type AppHead, type AppOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
package/dist/index.mjs CHANGED
@@ -4,15 +4,15 @@ import fs from 'fs-extra';
4
4
  import 'tsx/esm';
5
5
  import { pathToFileURL } from 'mlly';
6
6
  import defu from 'defu';
7
- import Checker from 'vite-plugin-checker';
8
7
  import { loadConfig } from 'c12';
8
+ import Checker from 'vite-plugin-checker';
9
9
 
10
- const name$5 = "vixt:alias";
10
+ const name$3 = "vixt:alias";
11
11
  const alias = defineVixtModule({
12
- meta: { name: name$5 },
12
+ meta: { name: name$3 },
13
13
  setup(_, vixt) {
14
14
  return {
15
- name: name$5,
15
+ name: name$3,
16
16
  config() {
17
17
  return {
18
18
  root: vixt.options.rootDir,
@@ -30,6 +30,42 @@ const alias = defineVixtModule({
30
30
  }
31
31
  });
32
32
 
33
+ function defineVixtConfig(input) {
34
+ return input;
35
+ }
36
+ const rootDir = cwd();
37
+ const buildDir = ".vixt";
38
+ const buildTypesDir = `${buildDir}/types`;
39
+ async function loadVixtConfig(opts) {
40
+ const result = await loadConfig({
41
+ name: "vixt",
42
+ rcFile: false,
43
+ ...opts,
44
+ defaults: {
45
+ rootDir,
46
+ buildDir,
47
+ buildTypesDir,
48
+ ...opts?.defaults
49
+ }
50
+ });
51
+ result.layers = result.layers?.filter((e) => e.cwd);
52
+ return result;
53
+ }
54
+ function resolveLayersDirs(layers = []) {
55
+ const dirs = {};
56
+ for (const layer of layers) {
57
+ const contents = fs.readdirSync(path.resolve(layer.cwd, "src"));
58
+ for (const content of contents) {
59
+ const fileOrDirPath = path.resolve(layer.cwd, "src", content);
60
+ if (fs.statSync(fileOrDirPath).isDirectory()) {
61
+ dirs[content] ?? (dirs[content] = []);
62
+ dirs[content].push(fileOrDirPath);
63
+ }
64
+ }
65
+ }
66
+ return dirs;
67
+ }
68
+
33
69
  function defineVitePlugin(pluginFn) {
34
70
  return pluginFn;
35
71
  }
@@ -72,39 +108,6 @@ async function applyLayerModules(layers) {
72
108
  return modules;
73
109
  }
74
110
 
75
- function defineVixtConfig(input) {
76
- return input;
77
- }
78
- const rootDir = cwd();
79
- const buildDir = ".vixt";
80
- const buildTypesDir = `${buildDir}/types`;
81
- function loadVixtConfig(opts) {
82
- return loadConfig({
83
- name: "vixt",
84
- ...opts,
85
- defaults: {
86
- rootDir,
87
- buildDir,
88
- buildTypesDir,
89
- ...opts?.defaults
90
- }
91
- });
92
- }
93
- function resolveLayersDirs(layers) {
94
- const dirs = {};
95
- for (const layer of layers?.filter((e) => e.cwd) ?? []) {
96
- const contents = fs.readdirSync(path.resolve(layer.cwd, "src"));
97
- for (const content of contents) {
98
- const fileOrDirPath = path.resolve(layer.cwd, "src", content);
99
- if (fs.statSync(fileOrDirPath).isDirectory()) {
100
- dirs[content] ?? (dirs[content] = []);
101
- dirs[content].push(fileOrDirPath);
102
- }
103
- }
104
- }
105
- return dirs;
106
- }
107
-
108
111
  function resolveHeadTag(tag, attrs) {
109
112
  const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
110
113
  return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
@@ -141,10 +144,11 @@ ${noscriptTemplate}
141
144
  fs.outputFileSync(path.resolve(rootDir, `${buildDir2}/index.html`), code);
142
145
  return code;
143
146
  }
144
- const name$4 = "vixt:app";
145
- const defaults$2 = {
147
+ const name$2 = "vixt:app";
148
+ const defaults$1 = {
146
149
  rootId: "app",
147
150
  rootTag: "div",
151
+ baseURL: "/",
148
152
  loadingTemplate: "./loading.html",
149
153
  main: `${buildDir}/main.ts`,
150
154
  head: {
@@ -156,12 +160,12 @@ const defaults$2 = {
156
160
  }
157
161
  };
158
162
  const app = defineVixtModule({
159
- meta: { name: name$4, configKey: "app" },
160
- defaults: defaults$2,
163
+ meta: { name: name$2, configKey: "app" },
164
+ defaults: defaults$1,
161
165
  setup(options, vixt) {
162
166
  generateIndexHtml(options, vixt);
163
167
  return {
164
- name: name$4,
168
+ name: name$2,
165
169
  transformIndexHtml: {
166
170
  order: "pre",
167
171
  handler() {
@@ -181,12 +185,12 @@ const app = defineVixtModule({
181
185
  }
182
186
  });
183
187
 
184
- const name$3 = "vixt:config";
188
+ const name$1 = "vixt:config";
185
189
  const config = defineVixtModule({
186
- meta: { name: name$3 },
190
+ meta: { name: name$1 },
187
191
  setup(options, vixt) {
188
192
  return {
189
- name: name$3,
193
+ name: name$1,
190
194
  enforce: "pre",
191
195
  config(config2) {
192
196
  vixt.options.vite = config2;
@@ -198,84 +202,46 @@ const config = defineVixtModule({
198
202
  }
199
203
  });
200
204
 
201
- function transformProxy(list) {
202
- return Object.fromEntries(
203
- JSON.parse(list).map(([prefix, target, rewrite]) => {
204
- const option = {
205
- target,
206
- changeOrigin: true,
207
- ws: true,
208
- secure: /^https:\/\//.test(target)
209
- };
210
- if (rewrite)
211
- option.rewrite = (path) => path.replace(new RegExp(`^${prefix}`), "");
212
- return [prefix, option];
213
- })
214
- );
215
- }
216
- const name$2 = "vixt:dev-proxy";
217
- const devProxy = defineVixtModule({
218
- meta: { name: name$2, configKey: "devProxy" },
219
- defaults: { key: "VITE_PROXY" },
220
- setup(options) {
221
- return {
222
- name: name$2,
223
- configResolved(config) {
224
- const { env } = config;
225
- const proxyList = env[options.key];
226
- if (proxyList) {
227
- const proxy = transformProxy(proxyList);
228
- config.server.proxy = defu(proxy, config.server.proxy);
229
- config.preview.proxy = defu(proxy, config.server.proxy);
230
- }
231
- }
232
- };
233
- }
234
- });
235
-
236
- function generateDts(options, vixt, config) {
237
- const { root } = config;
238
- const { buildDir } = vixt.options;
239
- const vixtDts = options.references?.map((reference) => {
205
+ function generateVixtDts(options, vixt) {
206
+ const { buildDir, rootDir } = vixt.options;
207
+ const codePath = path.resolve(rootDir, buildDir, "vixt.d.ts");
208
+ const code = options.references?.map((reference) => {
240
209
  if (typeof reference === "string") {
241
210
  return `/// <reference path="${reference}" />`;
242
211
  } else if (typeof reference === "object" && reference.path && reference.content) {
243
- fs.outputFileSync(path.resolve(root, buildDir), reference.content ?? "");
212
+ fs.outputFileSync(path.resolve(rootDir, buildDir), reference.content ?? "");
244
213
  return `/// <reference path="${reference.path}" />`;
245
214
  } else {
246
215
  return "";
247
216
  }
248
217
  }).concat("export {}").join("\n");
249
- const vixtDtsPath = path.resolve(root, buildDir, "vixt.d.ts");
250
- fs.outputFileSync(vixtDtsPath, vixtDts);
218
+ code && fs.outputFileSync(codePath, code);
251
219
  }
252
- function generateTsConfig(options, vixt, config) {
253
- const { root } = config;
254
- const { buildDir } = vixt.options;
255
- const tsConfigPath = path.resolve(root, buildDir, "tsconfig.json");
256
- const layersDirs = vixt._layers.filter((e) => e.cwd).map((e) => e.cwd);
220
+ function generateTsConfig(options, vixt) {
221
+ const { buildDir, rootDir } = vixt.options;
222
+ const codePath = path.resolve(rootDir, buildDir, "tsconfig.json");
223
+ const layersDirs = vixt._layers.map((e) => e.cwd);
257
224
  const tsConfig = defu(options.tsConfig, { include: layersDirs });
258
- fs.outputFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
225
+ const code = JSON.stringify(tsConfig, null, 2);
226
+ fs.outputFileSync(codePath, code);
259
227
  }
260
- function generateEnvDts(options, vixt, config) {
261
- const { env, root } = config;
262
- const { buildDir } = vixt.options;
228
+ function generateEnvDts(options, vixt, env) {
229
+ const { buildTypesDir, rootDir } = vixt.options;
230
+ const codePath = path.resolve(rootDir, buildTypesDir, "vite-env.d.ts");
263
231
  const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
264
232
  ${key}: ${typeof value}`).join("\n ");
265
- const envDts = `interface ImportMeta {
233
+ const code = `interface ImportMeta {
266
234
  readonly env: ImportMetaEnv
267
235
  }
268
236
  interface ImportMetaEnv {
269
237
  ${values}
270
238
  }
271
239
  `;
272
- const envDtsPath = path.resolve(root, buildDir, "types", "vite-env.d.ts");
273
- fs.outputFileSync(envDtsPath, envDts);
240
+ fs.outputFileSync(codePath, code);
274
241
  }
275
- function genarateShims(options, vixt, config) {
276
- const { root } = config;
277
- const { buildDir } = vixt.options;
278
- const shimsDts = `
242
+ function genarateShims(options, vixt) {
243
+ const { buildTypesDir, rootDir } = vixt.options;
244
+ const code = `
279
245
  declare module '*.vue' {
280
246
  import type { DefineComponent } from 'vue'
281
247
 
@@ -283,12 +249,24 @@ declare module '*.vue' {
283
249
  export default component
284
250
  }
285
251
  `;
286
- const shimsDtsPath = path.resolve(root, buildDir, "types", "shims.d.ts");
287
- fs.outputFileSync(shimsDtsPath, shimsDts);
252
+ const codePath = path.resolve(rootDir, buildTypesDir, "shims.d.ts");
253
+ fs.outputFileSync(codePath, code);
288
254
  }
289
- const name$1 = "vixt:typescript";
290
- const defaults$1 = {
291
- references: ["./types/vite-env.d.ts", "./types/shims.d.ts"],
255
+ function genarateGlobalComponents(options, vixt) {
256
+ const { buildTypesDir, rootDir } = vixt.options;
257
+ const codePath = path.resolve(rootDir, buildTypesDir, "global-components.d.ts");
258
+ const code = `
259
+ import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
260
+
261
+ declare module 'vue'{
262
+ interface GlobalComponents extends _GlobalComponents {}
263
+ }
264
+ `;
265
+ fs.outputFileSync(codePath, code);
266
+ }
267
+ const name = "vixt:typescript";
268
+ const defaults = {
269
+ // references: ['types/vite-env.d.ts', 'types/shims.d.ts', 'types/global-components.d.ts'],
292
270
  tsConfig: {
293
271
  extends: "@vue/tsconfig/tsconfig.dom.json",
294
272
  compilerOptions: {
@@ -307,17 +285,18 @@ const defaults$1 = {
307
285
  typeCheck: { enableBuild: false, overlay: { initialIsOpen: false } }
308
286
  };
309
287
  const typescript = defineVixtModule({
310
- meta: { name: name$1, configKey: "typescript" },
311
- defaults: defaults$1,
288
+ meta: { name, configKey: "typescript" },
289
+ defaults,
312
290
  setup(options, vixt) {
313
291
  return [
314
292
  {
315
- name: name$1,
293
+ name,
316
294
  configResolved(config) {
317
- generateDts(options, vixt, config);
318
- generateTsConfig(options, vixt, config);
319
- generateEnvDts(options, vixt, config);
320
- genarateShims(options, vixt, config);
295
+ generateVixtDts(options, vixt);
296
+ generateTsConfig(options, vixt);
297
+ generateEnvDts(options, vixt, config.env);
298
+ genarateShims(options, vixt);
299
+ genarateGlobalComponents(options, vixt);
321
300
  }
322
301
  },
323
302
  Checker(options.typeCheck ?? {})
@@ -325,35 +304,10 @@ const typescript = defineVixtModule({
325
304
  }
326
305
  });
327
306
 
328
- const defaults = {
329
- enabled: true,
330
- clientFiles: ["./index.html", "./src/**/*.vue", "./src/**/*.ts", "./src/**/*.tsx"],
331
- ssrFiles: ["./index.html", "./src/**/*.vue", "./src/**/*.ts", "./src/**/*.tsx"]
332
- };
333
- const name = "vixt:warmup";
334
- const warmup = defineVixtModule({
335
- meta: { name, configKey: "warmup" },
336
- defaults,
337
- setup(options) {
338
- return {
339
- name,
340
- config() {
341
- if (!options.enabled)
342
- return;
343
- return {
344
- server: {
345
- warmup: options
346
- }
347
- };
348
- }
349
- };
350
- }
351
- });
352
-
353
307
  async function loadVixt(opts) {
354
308
  const result = await loadVixtConfig(defu(opts, {
355
309
  defaults: {
356
- modules: [alias, app, config, devProxy, typescript, warmup]
310
+ modules: [alias, app, config, typescript]
357
311
  }
358
312
  }));
359
313
  const layerModules = await applyLayerModules(result.layers);
@@ -372,4 +326,4 @@ function createVixtPlugin(loadOptions) {
372
326
  });
373
327
  }
374
328
 
375
- export { alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, devProxy, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, transformProxy, typescript, warmup };
329
+ export { alias, app, applyLayerModules, buildDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -25,7 +25,7 @@
25
25
  "fs-extra": "^11.2.0",
26
26
  "mlly": "1.7.1",
27
27
  "pathe": "^1.1.2",
28
- "pkg-types": "^1.1.1",
28
+ "pkg-types": "^1.1.3",
29
29
  "tsx": "^4.16.0",
30
30
  "vite": "^5.3.2",
31
31
  "vite-plugin-checker": "^0.7.0",