@brybrant/vite-config 0.0.1

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.
@@ -0,0 +1,13 @@
1
+ import { UserConfig, UserConfigFnObject } from "vite";
2
+
3
+ //#region vite.config.d.ts
4
+ type ViteOptions = Pick<UserConfig, 'base' | 'plugins'> & {
5
+ /**
6
+ * Does the project use CSS modules?
7
+ * @default false
8
+ */
9
+ cssmodules?: boolean;
10
+ };
11
+ declare const viteConfig: (viteOptions: ViteOptions) => UserConfigFnObject;
12
+ //#endregion
13
+ export { ViteOptions, viteConfig as default };
@@ -0,0 +1,59 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { defineConfig } from "vite";
3
+ import eslintPlugin from "vite-plugin-eslint2";
4
+ import stylelintPlugin from "vite-plugin-stylelint";
5
+ import { optimize } from "svgo";
6
+ import { NodePackageImporter } from "sass-embedded";
7
+ import cssModulesExportJSON from "@brybrant/cssmodules";
8
+ import stylelintConfig from "@brybrant/stylelint-config";
9
+ import svgoConfig from "@brybrant/svgo-config";
10
+ import terserConfig from "@brybrant/terser-config";
11
+ //#region vite.config.ts
12
+ const svgoPlugin = {
13
+ name: "@brybrant/vite-plugin-svgo",
14
+ enforce: "pre",
15
+ async load(id) {
16
+ const [path, qs] = id.split("?");
17
+ if (!path.endsWith(".svg")) return null;
18
+ const convertToJSX = new URLSearchParams(qs).has("jsx");
19
+ return readFile(id, "utf8").then((svg) => {
20
+ const { data } = optimize(svg, Object.assign({}, svgoConfig, { path }));
21
+ /** Borrowed from `vite-plugin-solid-svg` */
22
+ if (convertToJSX) return `export default (props = {}) => ${data.replace(/([{}])/g, "{\"$1\"}").replace(/<!--\s*([\s\S]*?)\s*-->/g, "{/* $1 */}").replace(/(<svg[^>]*)>/i, "$1{...props}>")}`;
23
+ return `export default \`${data}\`;`;
24
+ });
25
+ }
26
+ };
27
+ const viteConfig = (viteOptions) => {
28
+ return defineConfig(({ mode }) => {
29
+ const development = mode === "development";
30
+ return {
31
+ base: viteOptions.base ?? "/",
32
+ build: {
33
+ minify: development ? true : "terser",
34
+ ...!development && { terserOptions: terserConfig }
35
+ },
36
+ css: {
37
+ ...viteOptions.cssmodules && { modules: { getJSON: cssModulesExportJSON } },
38
+ postcss: `${import.meta.dirname}/node_modules/@brybrant/postcss-config`,
39
+ preprocessorOptions: { scss: { importers: [new NodePackageImporter()] } }
40
+ },
41
+ plugins: [
42
+ stylelintPlugin({
43
+ lintInWorker: true,
44
+ config: stylelintConfig
45
+ }),
46
+ svgoPlugin,
47
+ ...viteOptions.plugins ?? [],
48
+ eslintPlugin({ lintInWorker: true })
49
+ ],
50
+ server: {
51
+ host: "127.0.0.1",
52
+ port: 3e3,
53
+ strictPort: true
54
+ }
55
+ };
56
+ });
57
+ };
58
+ //#endregion
59
+ export { viteConfig as default };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@brybrant/vite-config",
3
+ "author": "brybrant",
4
+ "license": "GPL-3.0-only",
5
+ "version": "0.0.1",
6
+ "type": "module",
7
+ "module": "./dist/vite.config.js",
8
+ "types": "./dist/vite.config.d.ts",
9
+ "exports": "./dist/vite.config.js",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/brybrant/configs.git"
16
+ },
17
+ "dependencies": {
18
+ "@brybrant/cssmodules": "^0.0.3",
19
+ "@brybrant/eslint-config": "^0.0.3",
20
+ "@brybrant/postcss-config": "^0.0.3",
21
+ "@brybrant/stylelint-config": "^0.0.3",
22
+ "@brybrant/svgo-config": "^0.0.3",
23
+ "@brybrant/terser-config": "^0.0.3",
24
+ "sass-embedded": "^1.97.3",
25
+ "terser": "^5.46.0",
26
+ "vite": "^7.3.1",
27
+ "vite-plugin-eslint2": "^5.0.5",
28
+ "vite-plugin-stylelint": "6.1.0"
29
+ }
30
+ }