@tanstack/vite-config 0.4.3 → 0.5.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.
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { defineConfig } from "vite";
2
- import { preserveDirectives } from "rollup-plugin-preserve-directives";
3
2
  import { externalizeDeps } from "vite-plugin-externalize-deps";
4
3
  import tsconfigPaths from "vite-tsconfig-paths";
5
4
  import dts from "vite-plugin-dts";
@@ -14,13 +13,13 @@ const tanstackViteConfig = (options) => {
14
13
  const outDir = options.outDir ?? "dist";
15
14
  const cjs = options.cjs ?? true;
16
15
  return defineConfig({
16
+ resolve: { tsconfigPaths: !options.tsconfigPath },
17
17
  plugins: [
18
18
  externalizeDeps({
19
19
  include: options.externalDeps ?? [],
20
20
  except: options.bundledDeps ?? []
21
21
  }),
22
- preserveDirectives(),
23
- tsconfigPaths({ projects: options.tsconfigPath ? [options.tsconfigPath] : void 0 }),
22
+ options.tsconfigPath ? tsconfigPaths({ projects: [options.tsconfigPath] }) : void 0,
24
23
  dts({
25
24
  outDir: `${outDir}/esm`,
26
25
  entryRoot: options.srcDir,
@@ -28,7 +27,7 @@ const tanstackViteConfig = (options) => {
28
27
  exclude: options.exclude,
29
28
  tsconfigPath: options.tsconfigPath,
30
29
  compilerOptions: {
31
- module: 99,
30
+ module: 199,
32
31
  declarationMap: false
33
32
  },
34
33
  beforeWriteFile: (filePath, content) => {
@@ -55,7 +54,7 @@ const tanstackViteConfig = (options) => {
55
54
  exclude: options.exclude,
56
55
  tsconfigPath: options.tsconfigPath,
57
56
  compilerOptions: {
58
- module: 1,
57
+ module: 199,
59
58
  declarationMap: false
60
59
  },
61
60
  beforeWriteFile: (filePath, content) => {
@@ -88,7 +87,7 @@ const tanstackViteConfig = (options) => {
88
87
  return "esm/[name].js";
89
88
  }
90
89
  },
91
- rollupOptions: { output: { preserveModules: true } }
90
+ rolldownOptions: { output: { preserveModules: true } }
92
91
  }
93
92
  });
94
93
  };
package/dist/index.js.map CHANGED
@@ -1 +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: {\n output: {\n preserveModules: true,\n },\n },\n },\n })\n}\n"],"mappings":";;;;;;;AAYA,SAAS,0BAA0B,EACjC,SACA,aAIC;AAED,WAAU,QAAQ,QAChB,uEACA,MAAM,YACP;AAGD,WAAU,QAAQ,QAChB,gDACA,MAAM,YACP;AACD,QAAO;;AAGT,MAAa,sBAAsB,YAAiC;CAClE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,MAAM,QAAQ,OAAO;AAE3B,QAAO,aAAa;EAClB,SAAS;GACP,gBAAgB;IACd,SAAS,QAAQ,gBAAgB,EAAE;IACnC,QAAQ,QAAQ,eAAe,EAAE;IAClC,CAAC;GACF,oBAAoB;GACpB,cAAc,EACZ,UAAU,QAAQ,eAAe,CAAC,QAAQ,aAAa,GAAG,QAC3D,CAAC;GACF,IAAI;IACF,QAAQ,GAAG,OAAO;IAClB,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,SAAS,QAAQ;IACjB,cAAc,QAAQ;IACtB,iBAAiB;KACf,QAAQ;KACR,gBAAgB;KACjB;IACD,kBAAkB,UAAU,YAAY;AACtC,eACE,QAAQ,6BAA6B,UAAU,QAAQ,IAAI;AAC7D,YAAO;MACL;MACA,SAAS,0BAA0B;OAAE;OAAS,WAAW;OAAM,CAAC;MACjE;;IAEH,kBAAkB,gBAAgB;AAChC,SAAI,YAAY,SAAS,GAAG;AAC1B,cAAQ,MAAM,mCAAmC;AACjD,cAAQ,KAAK,EAAE;;;IAGpB,CAAC;GACF,MACI,IAAI;IACF,QAAQ,GAAG,OAAO;IAClB,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,SAAS,QAAQ;IACjB,cAAc,QAAQ;IACtB,iBAAiB;KACf,QAAQ;KACR,gBAAgB;KACjB;IACD,kBAAkB,UAAU,YAAY;AACtC,eACE,QAAQ,6BAA6B,UAAU,QAAQ,IACvD;AACF,YAAO;MACL,UAAU,SAAS,QAAQ,SAAS,SAAS;MAC7C,SAAS,0BAA0B;OACjC;OACA,WAAW;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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// @ts-check\n\nimport { defineConfig } from 'vite'\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 resolve: {\n tsconfigPaths: !options.tsconfigPath,\n },\n plugins: [\n externalizeDeps({\n include: options.externalDeps ?? [],\n except: options.bundledDeps ?? [],\n }),\n // Use vite-tsconfig-paths plugin only when a custom tsconfigPath is specified,\n // otherwise Vite 8's native resolve.tsconfigPaths handles it\n options.tsconfigPath\n ? tsconfigPaths({\n projects: [options.tsconfigPath],\n })\n : undefined,\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: 199, // NodeNext\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: 199, // NodeNext\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 rolldownOptions: {\n output: {\n preserveModules: true,\n },\n },\n },\n })\n}\n"],"mappings":";;;;;;AAWA,SAAS,0BAA0B,EACjC,SACA,aAIC;AAED,WAAU,QAAQ,QAChB,uEACA,MAAM,YACP;AAGD,WAAU,QAAQ,QAChB,gDACA,MAAM,YACP;AACD,QAAO;;AAGT,MAAa,sBAAsB,YAAiC;CAClE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,MAAM,QAAQ,OAAO;AAE3B,QAAO,aAAa;EAClB,SAAS,EACP,eAAe,CAAC,QAAQ,cACzB;EACD,SAAS;GACP,gBAAgB;IACd,SAAS,QAAQ,gBAAgB,EAAE;IACnC,QAAQ,QAAQ,eAAe,EAAE;IAClC,CAAC;GAGF,QAAQ,eACJ,cAAc,EACZ,UAAU,CAAC,QAAQ,aAAa,EACjC,CAAC,GACF;GACJ,IAAI;IACF,QAAQ,GAAG,OAAO;IAClB,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,SAAS,QAAQ;IACjB,cAAc,QAAQ;IACtB,iBAAiB;KACf,QAAQ;KACR,gBAAgB;KACjB;IACD,kBAAkB,UAAU,YAAY;AACtC,eACE,QAAQ,6BAA6B,UAAU,QAAQ,IAAI;AAC7D,YAAO;MACL;MACA,SAAS,0BAA0B;OAAE;OAAS,WAAW;OAAM,CAAC;MACjE;;IAEH,kBAAkB,gBAAgB;AAChC,SAAI,YAAY,SAAS,GAAG;AAC1B,cAAQ,MAAM,mCAAmC;AACjD,cAAQ,KAAK,EAAE;;;IAGpB,CAAC;GACF,MACI,IAAI;IACF,QAAQ,GAAG,OAAO;IAClB,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,SAAS,QAAQ;IACjB,cAAc,QAAQ;IACtB,iBAAiB;KACf,QAAQ;KACR,gBAAgB;KACjB;IACD,kBAAkB,UAAU,YAAY;AACtC,eACE,QAAQ,6BAA6B,UAAU,QAAQ,IACvD;AACF,YAAO;MACL,UAAU,SAAS,QAAQ,SAAS,SAAS;MAC7C,SAAS,0BAA0B;OACjC;OACA,WAAW;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,iBAAiB,EACf,QAAQ,EACN,iBAAiB,MAClB,EACF;GACF;EACF,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,22 +1,13 @@
1
1
  //#region src/types.d.ts
2
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 */
3
+ /** Entry file, e.g. `./src/index.ts` */entry: string | Array<string>; /** Source directory used for type generation, e.g. `./src` */
4
+ srcDir: string; /** Excluded from type generation, e.g. `[./src/tests]` */
5
+ exclude?: Array<string>; /** Directory where build output will be placed, e.g. `./dist` */
6
+ outDir?: string; /** Generate CJS output, defaults to `true` */
7
+ cjs?: boolean; /** Optional path to a custom tsconfig file, defaults to `./tsconfig.json` */
8
+ tsconfigPath?: string; /** Additional dependencies to externalize if not detected by `vite-plugin-externalize-deps` */
9
+ externalDeps?: Array<string | RegExp>; /** Dependencies to bundle. Will be passed to the except argument of `vite-plugin-externalize-deps` */
10
+ bundledDeps?: Array<string | RegExp>; /** Hook called prior to writing each declaration file; allows to transform the content */
20
11
  beforeWriteDeclarationFile?: (filePath: string, content: string) => string;
21
12
  };
22
13
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vite-config",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "Shared Vite build config used by TanStack projects.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -15,8 +15,6 @@
15
15
  "url": "https://github.com/sponsors/tannerlinsley"
16
16
  },
17
17
  "type": "module",
18
- "main": "./dist/index.js",
19
- "module": "./dist/index.js",
20
18
  "types": "./dist/index.d.ts",
21
19
  "exports": {
22
20
  ".": "./dist/index.js",
@@ -32,18 +30,16 @@
32
30
  "node": ">=18"
33
31
  },
34
32
  "dependencies": {
35
- "rollup-plugin-preserve-directives": "^0.4.0",
36
33
  "vite-plugin-dts": "4.2.3",
37
34
  "vite-plugin-externalize-deps": "^0.10.0",
38
- "vite-tsconfig-paths": "^5.1.4"
35
+ "vite-tsconfig-paths": "^6.1.0"
39
36
  },
40
37
  "devDependencies": {
41
- "tsdown": "^0.17.0",
42
- "vite": "^7.2.4",
43
- "@tanstack/eslint-config": "0.3.4"
38
+ "vite": "^8.0.0",
39
+ "@tanstack/eslint-config": "0.4.0"
44
40
  },
45
41
  "peerDependencies": {
46
- "vite": "^6.0.0 || ^7.0.0"
42
+ "vite": "^8.0.0"
47
43
  },
48
44
  "scripts": {
49
45
  "test:types": "tsc",
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // @ts-check
2
2
 
3
3
  import { defineConfig } from 'vite'
4
- import { preserveDirectives } from 'rollup-plugin-preserve-directives'
5
4
  import { externalizeDeps } from 'vite-plugin-externalize-deps'
6
5
  import tsconfigPaths from 'vite-tsconfig-paths'
7
6
  import dts from 'vite-plugin-dts'
@@ -36,15 +35,21 @@ export const tanstackViteConfig = (options: Options): UserConfig => {
36
35
  const cjs = options.cjs ?? true
37
36
 
38
37
  return defineConfig({
38
+ resolve: {
39
+ tsconfigPaths: !options.tsconfigPath,
40
+ },
39
41
  plugins: [
40
42
  externalizeDeps({
41
43
  include: options.externalDeps ?? [],
42
44
  except: options.bundledDeps ?? [],
43
45
  }),
44
- preserveDirectives(),
45
- tsconfigPaths({
46
- projects: options.tsconfigPath ? [options.tsconfigPath] : undefined,
47
- }),
46
+ // Use vite-tsconfig-paths plugin only when a custom tsconfigPath is specified,
47
+ // otherwise Vite 8's native resolve.tsconfigPaths handles it
48
+ options.tsconfigPath
49
+ ? tsconfigPaths({
50
+ projects: [options.tsconfigPath],
51
+ })
52
+ : undefined,
48
53
  dts({
49
54
  outDir: `${outDir}/esm`,
50
55
  entryRoot: options.srcDir,
@@ -52,7 +57,7 @@ export const tanstackViteConfig = (options: Options): UserConfig => {
52
57
  exclude: options.exclude,
53
58
  tsconfigPath: options.tsconfigPath,
54
59
  compilerOptions: {
55
- module: 99, // ESNext
60
+ module: 199, // NodeNext
56
61
  declarationMap: false,
57
62
  },
58
63
  beforeWriteFile: (filePath, content) => {
@@ -78,7 +83,7 @@ export const tanstackViteConfig = (options: Options): UserConfig => {
78
83
  exclude: options.exclude,
79
84
  tsconfigPath: options.tsconfigPath,
80
85
  compilerOptions: {
81
- module: 1, // CommonJS
86
+ module: 199, // NodeNext
82
87
  declarationMap: false,
83
88
  },
84
89
  beforeWriteFile: (filePath, content) => {
@@ -114,7 +119,7 @@ export const tanstackViteConfig = (options: Options): UserConfig => {
114
119
  return 'esm/[name].js'
115
120
  },
116
121
  },
117
- rollupOptions: {
122
+ rolldownOptions: {
118
123
  output: {
119
124
  preserveModules: true,
120
125
  },