@tanstack/vite-config 0.4.0 → 0.4.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.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.js +1 -0
- package/package.json +10 -5
- package/src/{index.js → index.ts} +12 -10
- package/src/{index.d.ts → types.ts} +0 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Options } from "./types.js";
|
|
2
|
+
import { UserConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
declare const tanstackViteConfig: (options: Options) => UserConfig;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Options, tanstackViteConfig };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import { preserveDirectives } from "rollup-plugin-preserve-directives";
|
|
3
|
+
import { externalizeDeps } from "vite-plugin-externalize-deps";
|
|
4
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
5
|
+
import dts from "vite-plugin-dts";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
function ensureImportFileExtension({ content, extension }) {
|
|
9
|
+
content = content.replace(/(im|ex)port\s[\w{}/*\s,]+from\s['"](?:\.\.?\/)+?[^.'"]+(?=['"];?)/gm, `$&.${extension}`);
|
|
10
|
+
content = content.replace(/import\(['"](?:\.\.?\/)+?[^.'"]+(?=['"];?)/gm, `$&.${extension}`);
|
|
11
|
+
return content;
|
|
12
|
+
}
|
|
13
|
+
const tanstackViteConfig = (options) => {
|
|
14
|
+
const outDir = options.outDir ?? "dist";
|
|
15
|
+
const cjs = options.cjs ?? true;
|
|
16
|
+
return defineConfig({
|
|
17
|
+
plugins: [
|
|
18
|
+
externalizeDeps({
|
|
19
|
+
include: options.externalDeps ?? [],
|
|
20
|
+
except: options.bundledDeps ?? []
|
|
21
|
+
}),
|
|
22
|
+
preserveDirectives(),
|
|
23
|
+
tsconfigPaths({ projects: options.tsconfigPath ? [options.tsconfigPath] : void 0 }),
|
|
24
|
+
dts({
|
|
25
|
+
outDir: `${outDir}/esm`,
|
|
26
|
+
entryRoot: options.srcDir,
|
|
27
|
+
include: options.srcDir,
|
|
28
|
+
exclude: options.exclude,
|
|
29
|
+
tsconfigPath: options.tsconfigPath,
|
|
30
|
+
compilerOptions: {
|
|
31
|
+
module: 99,
|
|
32
|
+
declarationMap: false
|
|
33
|
+
},
|
|
34
|
+
beforeWriteFile: (filePath, content) => {
|
|
35
|
+
content = options.beforeWriteDeclarationFile?.(filePath, content) || content;
|
|
36
|
+
return {
|
|
37
|
+
filePath,
|
|
38
|
+
content: ensureImportFileExtension({
|
|
39
|
+
content,
|
|
40
|
+
extension: "js"
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
afterDiagnostic: (diagnostics) => {
|
|
45
|
+
if (diagnostics.length > 0) {
|
|
46
|
+
console.error("Please fix the above type errors");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
cjs ? dts({
|
|
52
|
+
outDir: `${outDir}/cjs`,
|
|
53
|
+
entryRoot: options.srcDir,
|
|
54
|
+
include: options.srcDir,
|
|
55
|
+
exclude: options.exclude,
|
|
56
|
+
tsconfigPath: options.tsconfigPath,
|
|
57
|
+
compilerOptions: {
|
|
58
|
+
module: 1,
|
|
59
|
+
declarationMap: false
|
|
60
|
+
},
|
|
61
|
+
beforeWriteFile: (filePath, content) => {
|
|
62
|
+
content = options.beforeWriteDeclarationFile?.(filePath, content) || content;
|
|
63
|
+
return {
|
|
64
|
+
filePath: filePath.replace(".d.ts", ".d.cts"),
|
|
65
|
+
content: ensureImportFileExtension({
|
|
66
|
+
content,
|
|
67
|
+
extension: "cjs"
|
|
68
|
+
})
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
afterDiagnostic: (diagnostics) => {
|
|
72
|
+
if (diagnostics.length > 0) {
|
|
73
|
+
console.error("Please fix the above type errors");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}) : void 0
|
|
78
|
+
],
|
|
79
|
+
build: {
|
|
80
|
+
outDir,
|
|
81
|
+
minify: false,
|
|
82
|
+
sourcemap: true,
|
|
83
|
+
lib: {
|
|
84
|
+
entry: options.entry,
|
|
85
|
+
formats: cjs ? ["es", "cjs"] : ["es"],
|
|
86
|
+
fileName: (format) => {
|
|
87
|
+
if (format === "cjs") return "cjs/[name].cjs";
|
|
88
|
+
return "esm/[name].js";
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
rollupOptions: { output: { preserveModules: true } }
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { tanstackViteConfig };
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// @ts-check\n\nimport { defineConfig } from 'vite'\nimport { preserveDirectives } from 'rollup-plugin-preserve-directives'\nimport { externalizeDeps } from 'vite-plugin-externalize-deps'\nimport tsconfigPaths from 'vite-tsconfig-paths'\nimport dts from 'vite-plugin-dts'\nimport type { UserConfig } from 'vite'\nimport type { Options } from './types.js'\n\nexport type { Options }\n\nfunction ensureImportFileExtension({\n content,\n extension,\n}: {\n content: string\n extension: string\n}) {\n // replace e.g. `import { foo } from './foo'` with `import { foo } from './foo.js'`\n content = content.replace(\n /(im|ex)port\\s[\\w{}/*\\s,]+from\\s['\"](?:\\.\\.?\\/)+?[^.'\"]+(?=['\"];?)/gm,\n `$&.${extension}`,\n )\n\n // replace e.g. `import('./foo')` with `import('./foo.js')`\n content = content.replace(\n /import\\(['\"](?:\\.\\.?\\/)+?[^.'\"]+(?=['\"];?)/gm,\n `$&.${extension}`,\n )\n return content\n}\n\nexport const tanstackViteConfig = (options: Options): UserConfig => {\n const outDir = options.outDir ?? 'dist'\n const cjs = options.cjs ?? true\n\n return defineConfig({\n plugins: [\n externalizeDeps({\n include: options.externalDeps ?? [],\n except: options.bundledDeps ?? [],\n }),\n preserveDirectives(),\n tsconfigPaths({\n projects: options.tsconfigPath ? [options.tsconfigPath] : undefined,\n }),\n dts({\n outDir: `${outDir}/esm`,\n entryRoot: options.srcDir,\n include: options.srcDir,\n exclude: options.exclude,\n tsconfigPath: options.tsconfigPath,\n compilerOptions: {\n module: 99, // ESNext\n declarationMap: false,\n },\n beforeWriteFile: (filePath, content) => {\n content =\n options.beforeWriteDeclarationFile?.(filePath, content) || content\n return {\n filePath,\n content: ensureImportFileExtension({ content, extension: 'js' }),\n }\n },\n afterDiagnostic: (diagnostics) => {\n if (diagnostics.length > 0) {\n console.error('Please fix the above type errors')\n process.exit(1)\n }\n },\n }),\n cjs\n ? dts({\n outDir: `${outDir}/cjs`,\n entryRoot: options.srcDir,\n include: options.srcDir,\n exclude: options.exclude,\n tsconfigPath: options.tsconfigPath,\n compilerOptions: {\n module: 1, // CommonJS\n declarationMap: false,\n },\n beforeWriteFile: (filePath, content) => {\n content =\n options.beforeWriteDeclarationFile?.(filePath, content) ||\n content\n return {\n filePath: filePath.replace('.d.ts', '.d.cts'),\n content: ensureImportFileExtension({\n content,\n extension: 'cjs',\n }),\n }\n },\n afterDiagnostic: (diagnostics) => {\n if (diagnostics.length > 0) {\n console.error('Please fix the above type errors')\n process.exit(1)\n }\n },\n })\n : undefined,\n ],\n build: {\n outDir,\n minify: false,\n sourcemap: true,\n lib: {\n entry: options.entry,\n formats: cjs ? ['es', 'cjs'] : ['es'],\n fileName: (format) => {\n if (format === 'cjs') return 'cjs/[name].cjs'\n return 'esm/[name].js'\n },\n },\n rollupOptions: {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;OACZ,CAAC;MACH;;IAEH,kBAAkB,gBAAgB;AAChC,SAAI,YAAY,SAAS,GAAG;AAC1B,cAAQ,MAAM,mCAAmC;AACjD,cAAQ,KAAK,EAAE;;;IAGpB,CAAC,GACF;GACL;EACD,OAAO;GACL;GACA,QAAQ;GACR,WAAW;GACX,KAAK;IACH,OAAO,QAAQ;IACf,SAAS,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAK;IACrC,WAAW,WAAW;AACpB,SAAI,WAAW,MAAO,QAAO;AAC7B,YAAO;;IAEV;GACD,eAAe,EACb,QAAQ,EACN,iBAAiB,MAClB,EACF;GACF;EACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type Options = {
|
|
3
|
+
/** Entry file, e.g. `./src/index.ts` */
|
|
4
|
+
entry: string | Array<string>;
|
|
5
|
+
/** Source directory used for type generation, e.g. `./src` */
|
|
6
|
+
srcDir: string;
|
|
7
|
+
/** Excluded from type generation, e.g. `[./src/tests]` */
|
|
8
|
+
exclude?: Array<string>;
|
|
9
|
+
/** Directory where build output will be placed, e.g. `./dist` */
|
|
10
|
+
outDir?: string;
|
|
11
|
+
/** Generate CJS output, defaults to `true` */
|
|
12
|
+
cjs?: boolean;
|
|
13
|
+
/** Optional path to a custom tsconfig file, defaults to `./tsconfig.json` */
|
|
14
|
+
tsconfigPath?: string;
|
|
15
|
+
/** Additional dependencies to externalize if not detected by `vite-plugin-externalize-deps` */
|
|
16
|
+
externalDeps?: Array<string | RegExp>;
|
|
17
|
+
/** Dependencies to bundle. Will be passed to the except argument of `vite-plugin-externalize-deps` */
|
|
18
|
+
bundledDeps?: Array<string | RegExp>;
|
|
19
|
+
/** Hook called prior to writing each declaration file; allows to transform the content */
|
|
20
|
+
beforeWriteDeclarationFile?: (filePath: string, content: string) => string;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Options };
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vite-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Shared Vite build config used by TanStack projects.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"import": {
|
|
21
|
-
"types": "./
|
|
22
|
-
"default": "./
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"./package.json": "./package.json"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"preferGlobal": false,
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"files": [
|
|
30
|
+
"dist",
|
|
30
31
|
"src"
|
|
31
32
|
],
|
|
32
33
|
"engines": {
|
|
@@ -39,11 +40,15 @@
|
|
|
39
40
|
"vite-tsconfig-paths": "^5.1.4"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"
|
|
43
|
+
"tsdown": "^0.17.0-beta.6",
|
|
44
|
+
"vite": "^7.2.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vite": "^6.0.0 || ^7.0.0"
|
|
43
48
|
},
|
|
44
49
|
"scripts": {
|
|
45
50
|
"test:types": "tsc",
|
|
46
51
|
"test:eslint": "eslint --concurrency=auto ./src",
|
|
47
|
-
"
|
|
52
|
+
"build": "tsdown"
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -5,12 +5,18 @@ import { preserveDirectives } from 'rollup-plugin-preserve-directives'
|
|
|
5
5
|
import { externalizeDeps } from 'vite-plugin-externalize-deps'
|
|
6
6
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
7
7
|
import dts from 'vite-plugin-dts'
|
|
8
|
+
import type { UserConfig } from 'vite'
|
|
9
|
+
import type { Options } from './types.js'
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export type { Options }
|
|
12
|
+
|
|
13
|
+
function ensureImportFileExtension({
|
|
14
|
+
content,
|
|
15
|
+
extension,
|
|
16
|
+
}: {
|
|
17
|
+
content: string
|
|
18
|
+
extension: string
|
|
19
|
+
}) {
|
|
14
20
|
// replace e.g. `import { foo } from './foo'` with `import { foo } from './foo.js'`
|
|
15
21
|
content = content.replace(
|
|
16
22
|
/(im|ex)port\s[\w{}/*\s,]+from\s['"](?:\.\.?\/)+?[^.'"]+(?=['"];?)/gm,
|
|
@@ -25,11 +31,7 @@ function ensureImportFileExtension({ content, extension }) {
|
|
|
25
31
|
return content
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
* @param {import('./index.js').Options} options
|
|
30
|
-
* @returns {import('vite').UserConfig}
|
|
31
|
-
*/
|
|
32
|
-
export const tanstackViteConfig = (options) => {
|
|
34
|
+
export const tanstackViteConfig = (options: Options): UserConfig => {
|
|
33
35
|
const outDir = options.outDir ?? 'dist'
|
|
34
36
|
const cjs = options.cjs ?? true
|
|
35
37
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { UserConfig } from 'vite'
|
|
2
|
-
|
|
3
1
|
export type Options = {
|
|
4
2
|
/** Entry file, e.g. `./src/index.ts` */
|
|
5
3
|
entry: string | Array<string>
|
|
@@ -20,6 +18,3 @@ export type Options = {
|
|
|
20
18
|
/** Hook called prior to writing each declaration file; allows to transform the content */
|
|
21
19
|
beforeWriteDeclarationFile?: (filePath: string, content: string) => string
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
/** https://tanstack.com/config/latest/docs/vite */
|
|
25
|
-
export function tanstackViteConfig(config: Options): UserConfig
|