@octohash/vite-config 0.2.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jing Haihan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # @octohash/vite-config
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ > [!NOTE]
10
+ > My personal vite config, opinionated but customizable, with built-in support for unplugin, i18n, and more.
11
+
12
+ ```bash
13
+ pnpm add -d @octohash/vite-config
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Automatically detects the project type (app or library) and applies suitable plugins. Manual configuration is rarely needed.
19
+
20
+ ```ts
21
+ import { defineConfig } from '@octohash/vite-config'
22
+ import tailwindcss from '@tailwindcss/vite'
23
+
24
+ export default defineConfig({
25
+ // Vue are autodetected, you can also explicitly enable them
26
+ vue: true,
27
+ // You can override and extend vite config here
28
+ vite: {
29
+ plugins: [
30
+ tailwindcss(),
31
+ ]
32
+ }
33
+ })
34
+ ```
35
+
36
+ ## Customization
37
+
38
+ The following is the top-level configuration (OptionsConfig) used to customize the Vite setup. It covers project type detection, alias resolution, common plugins, and both app/library-specific options.
39
+
40
+ ```ts
41
+ interface OptionsConfig {
42
+ /**
43
+ * Whether to build for production
44
+ *
45
+ * @default auto-detect based on `command === 'build'`
46
+ */
47
+ isBuild?: boolean
48
+ /**
49
+ * Type of the project
50
+ *
51
+ * @default auto-detect based on the `index.html` file
52
+ */
53
+ type?: ProjectType
54
+ /**
55
+ * Aliases used to replace values in `import` or `require` statements
56
+ * Paths are automatically resolved if needed
57
+ *
58
+ * @default { "@": "./src" }
59
+ */
60
+ alias?: AliasOptions
61
+
62
+ // Common Plugin
63
+ /**
64
+ * https://github.com/btd/rollup-plugin-visualizer
65
+ * By default template path is: ./node_modules/.cache/visualizer/stats.html
66
+ *
67
+ * @default false
68
+ */
69
+ visualizer?: boolean | VisualizerPluginOptions
70
+ /**
71
+ * Inject license info to output files
72
+ * Load license file from `package.json`, if it is a monorepo project, the root `package.json` will also be merged
73
+ *
74
+ * @default true
75
+ */
76
+ license?: boolean | LicensePluginOptions
77
+ /**
78
+ * https://github.com/originjs/vite-plugin-federation
79
+ * Module federation
80
+ */
81
+ federation?: FederationPluginOptions
82
+
83
+ // Application Plugin
84
+ /**
85
+ * https://github.com/chenxch/vite-plugin-dynamic-base
86
+ * If you want to build once and deploy to multiple environments, you can enable this plugin to set publicPath at runtime
87
+ * You can set like this: `dynamicBase: 'window.__dynamic_base__'`
88
+ */
89
+ dynamicBase?: string
90
+ /**
91
+ * Inject app loading to `index.html`
92
+ * You can customize the root element and loading template
93
+ * Use `[app-loading-title]` as a placeholder to dynamically set the document title during loading`
94
+ *
95
+ * @default auto-detect based on `projectType === 'app'`
96
+ */
97
+ appLoading?: boolean | AppLoadingPluginOptions
98
+ /**
99
+ * Injects metadata using `define`, accessible via `__VITE_APP_METADATA__`.
100
+ * Includes information such as author, build time, version, and more.
101
+ *
102
+ * @default auto-detect based on `projectType === 'app'`
103
+ */
104
+ metadata?: boolean | MetadataPluginOptions
105
+ /**
106
+ * Generates an import map for the project.
107
+ * Based on https://github.com/jspm/vite-plugin-jspm, with extended CDN provider support and options for include/exclude.
108
+ *
109
+ * @default false
110
+ */
111
+ importMap?: boolean | ImportMapPluginOptions
112
+
113
+ // Library Plugin
114
+ /**
115
+ * https://github.com/qmhc/vite-plugin-dts
116
+ * Generates declaration files from .ts or .vue source files
117
+ *
118
+ * @default auto-detect based on `projectType === 'lib'`
119
+ */
120
+ dts?: boolean | DtsPluginOptions
121
+
122
+ // Vue Plugin
123
+ /**
124
+ * Enable Vue support
125
+ * The goal is to provide an automatic registration mechanism similar to Nuxt in app development.
126
+ *
127
+ * @default auto-detect based on the dependencies
128
+ */
129
+ vue?: boolean | OptionsVue
130
+
131
+ // Override
132
+ vite?: UserConfig
133
+ }
134
+ ```
135
+
136
+ Vue-related options (vue) can also be customized in detail
137
+
138
+ ```ts
139
+ interface OptionsVue {
140
+ /**
141
+ * https://github.com/vuejs/devtools
142
+ * Enable Vue Devtools
143
+ *
144
+ * @default false
145
+ */
146
+ devtools?: boolean | VueDevtoolsPluginOptions
147
+ /**
148
+ * https://github.com/intlify/bundle-tools
149
+ * Enable Vue I18n
150
+ *
151
+ * @default false
152
+ */
153
+ i18n?: boolean | VueI18nPluginOptions
154
+ /**
155
+ * https://github.com/unplugin/unplugin-auto-import
156
+ * Automatically imports commonly used APIs such as `vue`, `vue-router`, `pinia`, `@vueuse/core`, etc
157
+ * Also supports auto-importing UI components from libraries like `ant-design-vue`, `element-plus`, etc
158
+ *
159
+ * @default auto-detect based on `projectType === 'app'`
160
+ */
161
+ imports?: boolean | VueImportsPluginOptions
162
+ /**
163
+ * https://github.com/unplugin/unplugin-vue-components
164
+ * Enabled by default when the project type is `app`
165
+ * The `directoryAsNamespace` option is enabled by default.
166
+ *
167
+ * @default auto-detect based on `projectType === 'app'`
168
+ */
169
+ components?: boolean | VueComponentsPluginOptions
170
+ /**
171
+ * https://github.com/posva/unplugin-vue-router
172
+ * Enabled by default when the project type is `app`
173
+ * Folder(s) to scan for files and generate routes. Defaults to scanning the pages directory.
174
+ *
175
+ * @default auto-detect based on `projectType === 'app'`
176
+ */
177
+ pages?: boolean | VuePagesPluginOptions
178
+ }
179
+ ```
180
+
181
+ <!-- Badges -->
182
+
183
+ [npm-version-src]: https://img.shields.io/npm/v/@octohash/vite-config?style=flat&colorA=080f12&colorB=1fa669
184
+ [npm-version-href]: https://npmjs.com/package/@octohash/vite-config
185
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@octohash/vite-config?style=flat&colorA=080f12&colorB=1fa669
186
+ [npm-downloads-href]: https://npmjs.com/package/@octohash/vite-config
187
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@octohash/vite-config?style=flat&colorA=080f12&colorB=1fa669&label=minzip
188
+ [bundle-href]: https://bundlephobia.com/result?p=@octohash/vite-config
189
+ [license-src]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat&colorA=080f12&colorB=1fa669
190
+ [license-href]: https://github.com/jinghaihan/@octohash/vite-config/LICENSE
191
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
192
+ [jsdocs-href]: https://www.jsdocs.io/package/@octohash/vite-config
@@ -0,0 +1,114 @@
1
+ <style data-app-loading="inject-css">
2
+ html {
3
+ /* same as ant-design-vue/dist/reset.css setting, avoid the title line-height changed */
4
+ line-height: 1.15;
5
+ }
6
+
7
+ .loading {
8
+ position: fixed;
9
+ top: 0;
10
+ left: 0;
11
+ z-index: 9999;
12
+ display: flex;
13
+ flex-direction: column;
14
+ align-items: center;
15
+ justify-content: center;
16
+ width: 100%;
17
+ height: 100%;
18
+ overflow: hidden;
19
+ background-color: #f4f7f9;
20
+
21
+ /* transition: all 0.8s ease-out; */
22
+ }
23
+
24
+ .loading.hidden {
25
+ pointer-events: none;
26
+ visibility: hidden;
27
+ opacity: 0;
28
+ transition: all 0.8s ease-out;
29
+ }
30
+
31
+ .dark .loading {
32
+ background: #0d0d10;
33
+ }
34
+
35
+ .title {
36
+ margin-top: 66px;
37
+ font-size: 28px;
38
+ font-weight: 600;
39
+ color: rgb(0 0 0 / 85%);
40
+ }
41
+
42
+ .dark .title {
43
+ color: #fff;
44
+ }
45
+
46
+ .loader {
47
+ position: relative;
48
+ width: 48px;
49
+ height: 48px;
50
+ }
51
+
52
+ .loader::before {
53
+ position: absolute;
54
+ top: 60px;
55
+ left: 0;
56
+ width: 48px;
57
+ height: 5px;
58
+ content: '';
59
+ background: hsl(var(--primary, 212 100% 45%) / 50%);
60
+ border-radius: 50%;
61
+ animation: shadow-ani 0.5s linear infinite;
62
+ }
63
+
64
+ .loader::after {
65
+ position: absolute;
66
+ top: 0;
67
+ left: 0;
68
+ width: 100%;
69
+ height: 100%;
70
+ content: '';
71
+ background: hsl(var(--primary, 212 100% 45%));
72
+ border-radius: 4px;
73
+ animation: jump-ani 0.5s linear infinite;
74
+ }
75
+
76
+ @keyframes jump-ani {
77
+ 15% {
78
+ border-bottom-right-radius: 3px;
79
+ }
80
+
81
+ 25% {
82
+ transform: translateY(9px) rotate(22.5deg);
83
+ }
84
+
85
+ 50% {
86
+ border-bottom-right-radius: 40px;
87
+ transform: translateY(18px) scale(1, 0.9) rotate(45deg);
88
+ }
89
+
90
+ 75% {
91
+ transform: translateY(9px) rotate(67.5deg);
92
+ }
93
+
94
+ 100% {
95
+ transform: translateY(0) rotate(90deg);
96
+ }
97
+ }
98
+
99
+ @keyframes shadow-ani {
100
+ 0%,
101
+ 100% {
102
+ transform: scale(1, 1);
103
+ }
104
+
105
+ 50% {
106
+ transform: scale(1.2, 1);
107
+ }
108
+ }
109
+ </style>
110
+
111
+ <div class="loading" id="__app-loading__">
112
+ <div class="loader"></div>
113
+ <div class="title">[app-loading-title]</div>
114
+ </div>
@@ -0,0 +1,46 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ //#region rolldown:runtime
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __esm = (fn, res) => function() {
13
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
14
+ };
15
+ var __commonJS = (cb, mod) => function() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
25
+ }
26
+ return to;
27
+ };
28
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
34
+
35
+ //#endregion
36
+ //#region node_modules/.pnpm/tsdown@0.12.4_typescript@5.8.3/node_modules/tsdown/esm-shims.js
37
+ var getFilename, getDirname, __dirname, __filename;
38
+ var init_esm_shims = __esm({ "node_modules/.pnpm/tsdown@0.12.4_typescript@5.8.3/node_modules/tsdown/esm-shims.js"() {
39
+ getFilename = () => fileURLToPath(import.meta.url);
40
+ getDirname = () => path.dirname(getFilename());
41
+ __dirname = /* @__PURE__ */ getDirname();
42
+ __filename = /* @__PURE__ */ getFilename();
43
+ } });
44
+
45
+ //#endregion
46
+ export { __commonJS, __dirname, __filename, __reExport, __require, __toESM, init_esm_shims };
@@ -0,0 +1,190 @@
1
+ import * as vite0 from "vite";
2
+ import { AliasOptions, PluginOption, UserConfig } from "vite";
3
+ import { PluginVisualizerOptions } from "rollup-plugin-visualizer";
4
+ import { PluginOptions } from "vite-plugin-dts";
5
+ import { VitePluginFederationOptions } from "@originjs/vite-plugin-federation";
6
+ import { VitePluginVueDevToolsOptions } from "vite-plugin-vue-devtools";
7
+ import { PluginOptions as PluginOptions$1 } from "@intlify/unplugin-vue-i18n";
8
+ import { Options } from "unplugin-auto-import/types";
9
+ import { Options as Options$1 } from "unplugin-vue-components";
10
+ import { Options as Options$2 } from "unplugin-vue-router";
11
+ import { GeneratorOptions } from "@jspm/generator";
12
+
13
+ //#region src/plugins/app-loading/index.d.ts
14
+ interface AppLoadingPluginOptions {
15
+ rootContainer?: string;
16
+ title?: string;
17
+ filePath?: string;
18
+ }
19
+ //#endregion
20
+ //#region src/plugins/import-map.d.ts
21
+ interface ImportMapPluginOptions extends GeneratorOptions {
22
+ downloadDeps?: boolean;
23
+ debug?: boolean;
24
+ defaultProvider?: 'jspm.io' | 'jsdelivr' | 'unpkg' | 'esm.sh';
25
+ include?: string[];
26
+ exclude?: string[];
27
+ }
28
+ //#endregion
29
+ //#region src/plugins/license.d.ts
30
+ interface LicensePluginOptions {
31
+ name?: string;
32
+ author?: string;
33
+ version?: string;
34
+ description?: string;
35
+ homepage?: string;
36
+ license?: string;
37
+ contact?: string;
38
+ copyright?: {
39
+ holder?: string;
40
+ year?: string | number;
41
+ };
42
+ }
43
+ //#endregion
44
+ //#region src/plugins/metadata.d.ts
45
+ interface MetadataPluginOptions {
46
+ extendMetadata?: Record<string, unknown>;
47
+ }
48
+ //#endregion
49
+ //#region src/types.d.ts
50
+ type ProjectType = 'app' | 'lib';
51
+ interface CommonPluginOptions {
52
+ /**
53
+ * https://github.com/btd/rollup-plugin-visualizer
54
+ * By default template path is: ./node_modules/.cache/visualizer/stats.html
55
+ *
56
+ * @default false
57
+ */
58
+ visualizer?: boolean | PluginVisualizerOptions;
59
+ /**
60
+ * Inject license info to output files
61
+ * Load license file from `package.json`, if it is a monorepo project, the root `package.json` will also be merged
62
+ *
63
+ * @default true
64
+ */
65
+ license?: boolean | LicensePluginOptions;
66
+ /**
67
+ * https://github.com/originjs/vite-plugin-federation
68
+ * Module federation
69
+ */
70
+ federation?: VitePluginFederationOptions;
71
+ }
72
+ interface AppPluginOptions {
73
+ /**
74
+ * https://github.com/chenxch/vite-plugin-dynamic-base
75
+ * If you want to build once and deploy to multiple environments, you can enable this plugin to set publicPath at runtime
76
+ * You can set like this: `dynamicBase: 'window.__dynamic_base__'`
77
+ */
78
+ dynamicBase?: string;
79
+ /**
80
+ * Inject app loading to `index.html`
81
+ * You can customize the root element and loading template
82
+ * Use `[app-loading-title]` as a placeholder to dynamically set the document title during loading`
83
+ *
84
+ * @default auto-detect based on `projectType === 'app'`
85
+ */
86
+ appLoading?: boolean | AppLoadingPluginOptions;
87
+ /**
88
+ * Injects metadata using `define`, accessible via `__VITE_APP_METADATA__`.
89
+ * Includes information such as author, build time, version, and more.
90
+ *
91
+ * @default auto-detect based on `projectType === 'app'`
92
+ */
93
+ metadata?: boolean | MetadataPluginOptions;
94
+ /**
95
+ * Generates an import map for the project.
96
+ * Based on https://github.com/jspm/vite-plugin-jspm, with extended CDN provider support and options for include/exclude.
97
+ *
98
+ * @default false
99
+ */
100
+ importMap?: boolean | ImportMapPluginOptions;
101
+ }
102
+ interface LibPluginOptions {
103
+ /**
104
+ * https://github.com/qmhc/vite-plugin-dts
105
+ * Generates declaration files from .ts or .vue source files
106
+ *
107
+ * @default auto-detect based on `projectType === 'lib'`
108
+ */
109
+ dts?: boolean | PluginOptions;
110
+ }
111
+ interface OptionsVue {
112
+ /**
113
+ * https://github.com/vuejs/devtools
114
+ * Enable Vue Devtools
115
+ *
116
+ * @default false
117
+ */
118
+ devtools?: boolean | VitePluginVueDevToolsOptions;
119
+ /**
120
+ * https://github.com/intlify/bundle-tools
121
+ * Enable Vue I18n
122
+ *
123
+ * @default false
124
+ */
125
+ i18n?: boolean | PluginOptions$1;
126
+ /**
127
+ * https://github.com/unplugin/unplugin-auto-import
128
+ * Auto-imports commonly used APIs such as `vue`, `vue-router`, `pinia`, `@vueuse/core`, etc
129
+ * Also supports auto-importing UI components from libraries like `ant-design-vue`, `element-plus`, etc
130
+ * Files from `src/composables` and `src/utils` will also be auto-imported.
131
+ *
132
+ * @default auto-detect based on `projectType === 'app'`
133
+ */
134
+ imports?: boolean | Options;
135
+ /**
136
+ * https://github.com/unplugin/unplugin-vue-components
137
+ * Enabled by default when the project type is `app`
138
+ * The `directoryAsNamespace` option is enabled by default.
139
+ *
140
+ * @default auto-detect based on `projectType === 'app'`
141
+ */
142
+ components?: boolean | Options$1;
143
+ /**
144
+ * https://github.com/posva/unplugin-vue-router
145
+ * Enabled by default when the project type is `app`
146
+ * Folder(s) to scan for files and generate routes. Defaults to scanning the pages directory.
147
+ *
148
+ * @default auto-detect based on `projectType === 'app'`
149
+ */
150
+ pages?: boolean | Options$2;
151
+ }
152
+ interface OptionsConfig extends CommonPluginOptions, AppPluginOptions, LibPluginOptions {
153
+ /**
154
+ * Whether to build for production
155
+ *
156
+ * @default auto-detect based on `command === 'build'`
157
+ */
158
+ isBuild?: boolean;
159
+ /**
160
+ * Type of the project
161
+ *
162
+ * @default auto-detect based on the `index.html` file
163
+ */
164
+ type?: ProjectType;
165
+ /**
166
+ * Aliases used to replace values in `import` or `require` statements
167
+ * Paths are automatically resolved if needed
168
+ *
169
+ * @default { "@": "./src" }
170
+ */
171
+ alias?: AliasOptions;
172
+ /**
173
+ * Enable Vue support
174
+ * The goal is to provide an automatic registration mechanism similar to Nuxt in app development.
175
+ *
176
+ * @default auto-detect based on the dependencies
177
+ */
178
+ vue?: boolean | OptionsVue;
179
+ vite?: UserConfig;
180
+ }
181
+ interface ConditionPlugin {
182
+ condition?: boolean;
183
+ plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
184
+ }
185
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
186
+ //#endregion
187
+ //#region src/index.d.ts
188
+ declare function defineConfig(options: OptionsConfig): vite0.UserConfigFnPromise;
189
+ //#endregion
190
+ export { AppPluginOptions, CommonPluginOptions, ConditionPlugin, LibPluginOptions, OptionsConfig, OptionsVue, ProjectType, ResolvedOptions, defineConfig };