@tanstack/router-plugin 1.20.3-alpha.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/cjs/core/code-splitter/compilers.cjs +755 -0
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -0
- package/dist/cjs/core/code-splitter/compilers.d.cts +22 -0
- package/dist/cjs/core/code-splitter/framework-options.cjs +34 -0
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -0
- package/dist/cjs/core/code-splitter/framework-options.d.cts +10 -0
- package/dist/cjs/core/code-splitter/path-ids.cjs +37 -0
- package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -0
- package/dist/cjs/core/code-splitter/path-ids.d.cts +2 -0
- package/dist/cjs/core/config.cjs +46 -0
- package/dist/cjs/core/config.cjs.map +1 -0
- package/dist/cjs/core/config.d.cts +160 -0
- package/dist/cjs/core/constants.cjs +19 -0
- package/dist/cjs/core/constants.cjs.map +1 -0
- package/dist/cjs/core/constants.d.cts +5 -0
- package/dist/cjs/core/route-autoimport-plugin.cjs +98 -0
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -0
- package/dist/cjs/core/route-autoimport-plugin.d.cts +6 -0
- package/dist/cjs/core/route-hmr-statement.cjs +33 -0
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -0
- package/dist/cjs/core/route-hmr-statement.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +173 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.d.cts +3 -0
- package/dist/cjs/core/router-composed-plugin.cjs +27 -0
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-composed-plugin.d.cts +3 -0
- package/dist/cjs/core/router-generator-plugin.cjs +145 -0
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-generator-plugin.d.cts +3 -0
- package/dist/cjs/core/router-hmr-plugin.cjs +51 -0
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-hmr-plugin.d.cts +8 -0
- package/dist/cjs/core/utils.cjs +12 -0
- package/dist/cjs/core/utils.cjs.map +1 -0
- package/dist/cjs/core/utils.d.cts +2 -0
- package/dist/cjs/esbuild.cjs +20 -0
- package/dist/cjs/esbuild.cjs.map +1 -0
- package/dist/cjs/esbuild.d.cts +127 -0
- package/dist/cjs/index.cjs +9 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/rspack.cjs +22 -0
- package/dist/cjs/rspack.cjs.map +1 -0
- package/dist/cjs/rspack.d.cts +139 -0
- package/dist/cjs/vite.cjs +22 -0
- package/dist/cjs/vite.cjs.map +1 -0
- package/dist/cjs/vite.d.cts +159 -0
- package/dist/cjs/webpack.cjs +22 -0
- package/dist/cjs/webpack.cjs.map +1 -0
- package/dist/cjs/webpack.d.cts +127 -0
- package/dist/esm/core/code-splitter/compilers.d.ts +22 -0
- package/dist/esm/core/code-splitter/compilers.js +737 -0
- package/dist/esm/core/code-splitter/compilers.js.map +1 -0
- package/dist/esm/core/code-splitter/framework-options.d.ts +10 -0
- package/dist/esm/core/code-splitter/framework-options.js +34 -0
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -0
- package/dist/esm/core/code-splitter/path-ids.d.ts +2 -0
- package/dist/esm/core/code-splitter/path-ids.js +37 -0
- package/dist/esm/core/code-splitter/path-ids.js.map +1 -0
- package/dist/esm/core/config.d.ts +160 -0
- package/dist/esm/core/config.js +46 -0
- package/dist/esm/core/config.js.map +1 -0
- package/dist/esm/core/constants.d.ts +5 -0
- package/dist/esm/core/constants.js +19 -0
- package/dist/esm/core/constants.js.map +1 -0
- package/dist/esm/core/route-autoimport-plugin.d.ts +6 -0
- package/dist/esm/core/route-autoimport-plugin.js +81 -0
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -0
- package/dist/esm/core/route-hmr-statement.d.ts +1 -0
- package/dist/esm/core/route-hmr-statement.js +16 -0
- package/dist/esm/core/route-hmr-statement.js.map +1 -0
- package/dist/esm/core/router-code-splitter-plugin.d.ts +3 -0
- package/dist/esm/core/router-code-splitter-plugin.js +173 -0
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -0
- package/dist/esm/core/router-composed-plugin.d.ts +3 -0
- package/dist/esm/core/router-composed-plugin.js +27 -0
- package/dist/esm/core/router-composed-plugin.js.map +1 -0
- package/dist/esm/core/router-generator-plugin.d.ts +3 -0
- package/dist/esm/core/router-generator-plugin.js +123 -0
- package/dist/esm/core/router-generator-plugin.js.map +1 -0
- package/dist/esm/core/router-hmr-plugin.d.ts +8 -0
- package/dist/esm/core/router-hmr-plugin.js +51 -0
- package/dist/esm/core/router-hmr-plugin.js.map +1 -0
- package/dist/esm/core/utils.d.ts +2 -0
- package/dist/esm/core/utils.js +12 -0
- package/dist/esm/core/utils.js.map +1 -0
- package/dist/esm/esbuild.d.ts +127 -0
- package/dist/esm/esbuild.js +20 -0
- package/dist/esm/esbuild.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/rspack.d.ts +139 -0
- package/dist/esm/rspack.js +22 -0
- package/dist/esm/rspack.js.map +1 -0
- package/dist/esm/vite.d.ts +159 -0
- package/dist/esm/vite.js +22 -0
- package/dist/esm/vite.js.map +1 -0
- package/dist/esm/webpack.d.ts +127 -0
- package/dist/esm/webpack.js +22 -0
- package/dist/esm/webpack.js.map +1 -0
- package/package.json +133 -0
- package/src/core/code-splitter/compilers.ts +1005 -0
- package/src/core/code-splitter/framework-options.ts +41 -0
- package/src/core/code-splitter/path-ids.ts +39 -0
- package/src/core/config.ts +80 -0
- package/src/core/constants.ts +17 -0
- package/src/core/route-autoimport-plugin.ts +102 -0
- package/src/core/route-hmr-statement.ts +13 -0
- package/src/core/router-code-splitter-plugin.ts +253 -0
- package/src/core/router-composed-plugin.ts +32 -0
- package/src/core/router-generator-plugin.ts +172 -0
- package/src/core/router-hmr-plugin.ts +65 -0
- package/src/core/utils.ts +18 -0
- package/src/esbuild.ts +56 -0
- package/src/index.ts +4 -0
- package/src/rspack.ts +67 -0
- package/src/vite.ts +57 -0
- package/src/webpack.ts +55 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { isAbsolute, join, normalize, resolve } from 'node:path'
|
|
2
|
+
import { generator, resolveConfigPath } from '@tanstack/router-generator'
|
|
3
|
+
|
|
4
|
+
import { getConfig } from './config'
|
|
5
|
+
import type { FSWatcher } from 'chokidar'
|
|
6
|
+
import type { UnpluginFactory } from 'unplugin'
|
|
7
|
+
import type { Config } from './config'
|
|
8
|
+
|
|
9
|
+
let lock = false
|
|
10
|
+
const checkLock = () => lock
|
|
11
|
+
const setLock = (bool: boolean) => {
|
|
12
|
+
lock = bool
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const PLUGIN_NAME = 'unplugin:router-generator'
|
|
16
|
+
|
|
17
|
+
export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
18
|
+
Partial<Config> | undefined
|
|
19
|
+
> = (options = {}) => {
|
|
20
|
+
let ROOT: string = process.cwd()
|
|
21
|
+
let userConfig = options as Config
|
|
22
|
+
|
|
23
|
+
const getRoutesDirectoryPath = () => {
|
|
24
|
+
return isAbsolute(userConfig.routesDirectory)
|
|
25
|
+
? userConfig.routesDirectory
|
|
26
|
+
: join(ROOT, userConfig.routesDirectory)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const generate = async () => {
|
|
30
|
+
if (checkLock()) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setLock(true)
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
await generator(userConfig, process.cwd())
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error(err)
|
|
40
|
+
console.info()
|
|
41
|
+
} finally {
|
|
42
|
+
setLock(false)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const handleFile = async (
|
|
47
|
+
file: string,
|
|
48
|
+
event: 'create' | 'update' | 'delete',
|
|
49
|
+
) => {
|
|
50
|
+
const filePath = normalize(file)
|
|
51
|
+
|
|
52
|
+
if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
|
|
53
|
+
userConfig = getConfig(options, ROOT)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
event === 'update' &&
|
|
59
|
+
filePath === resolve(userConfig.generatedRouteTree)
|
|
60
|
+
) {
|
|
61
|
+
// skip generating routes if the generated route tree is updated
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
66
|
+
if (filePath.startsWith(routesDirectoryPath)) {
|
|
67
|
+
await generate()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {
|
|
72
|
+
if (userConfig.enableRouteGeneration ?? true) {
|
|
73
|
+
await cb()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
name: 'router-generator-plugin',
|
|
79
|
+
async watchChange(id, { event }) {
|
|
80
|
+
await run(async () => {
|
|
81
|
+
await handleFile(id, event)
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
vite: {
|
|
85
|
+
configResolved(config) {
|
|
86
|
+
ROOT = config.root
|
|
87
|
+
userConfig = getConfig(options, ROOT)
|
|
88
|
+
|
|
89
|
+
// if (config.command === 'serve') {
|
|
90
|
+
// await run(generate)
|
|
91
|
+
// }
|
|
92
|
+
},
|
|
93
|
+
async buildStart() {
|
|
94
|
+
if (this.environment.name === 'server') {
|
|
95
|
+
// When building in environment mode, we only need to generate routes
|
|
96
|
+
// for the client environment
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
await run(generate)
|
|
100
|
+
},
|
|
101
|
+
sharedDuringBuild: true,
|
|
102
|
+
},
|
|
103
|
+
rspack(compiler) {
|
|
104
|
+
userConfig = getConfig(options, ROOT)
|
|
105
|
+
|
|
106
|
+
let handle: FSWatcher | null = null
|
|
107
|
+
|
|
108
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
109
|
+
await run(generate)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
113
|
+
if (handle) {
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// rspack watcher doesn't register newly created files
|
|
118
|
+
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
119
|
+
const chokidar = await import('chokidar')
|
|
120
|
+
handle = chokidar
|
|
121
|
+
.watch(routesDirectoryPath, { ignoreInitial: true })
|
|
122
|
+
.on('add', async () => {
|
|
123
|
+
await run(generate)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
await run(generate)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
130
|
+
if (handle) {
|
|
131
|
+
await handle.close()
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
webpack(compiler) {
|
|
136
|
+
userConfig = getConfig(options, ROOT)
|
|
137
|
+
|
|
138
|
+
let handle: FSWatcher | null = null
|
|
139
|
+
|
|
140
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
141
|
+
await run(generate)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
145
|
+
if (handle) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// webpack watcher doesn't register newly created files
|
|
150
|
+
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
151
|
+
const chokidar = await import('chokidar')
|
|
152
|
+
handle = chokidar
|
|
153
|
+
.watch(routesDirectoryPath, { ignoreInitial: true })
|
|
154
|
+
.on('add', async () => {
|
|
155
|
+
await run(generate)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
await run(generate)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
162
|
+
if (handle) {
|
|
163
|
+
await handle.close()
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
168
|
+
console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')
|
|
169
|
+
})
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
2
|
+
import { getConfig } from './config'
|
|
3
|
+
import { routeHmrStatement } from './route-hmr-statement'
|
|
4
|
+
import { debug, fileIsInRoutesDirectory } from './utils'
|
|
5
|
+
import type { Config } from './config'
|
|
6
|
+
import type { UnpluginFactory } from 'unplugin'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This plugin adds HMR support for file routes.
|
|
10
|
+
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
11
|
+
* handles HMR for code-split routes itself.
|
|
12
|
+
*/
|
|
13
|
+
export const unpluginRouterHmrFactory: UnpluginFactory<
|
|
14
|
+
Partial<Config> | undefined
|
|
15
|
+
> = (options = {}) => {
|
|
16
|
+
let ROOT: string = process.cwd()
|
|
17
|
+
let userConfig = options as Config
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name: 'router-hmr-plugin',
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
|
|
23
|
+
transform(code, id) {
|
|
24
|
+
if (!code.includes('export const Route = createFileRoute(')) {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (debug) console.info('Adding HMR handling to route ', id)
|
|
29
|
+
|
|
30
|
+
const ast = parseAst({ code })
|
|
31
|
+
ast.program.body.push(routeHmrStatement)
|
|
32
|
+
const result = generateFromAst(ast, {
|
|
33
|
+
sourceMaps: true,
|
|
34
|
+
filename: id,
|
|
35
|
+
sourceFileName: id,
|
|
36
|
+
})
|
|
37
|
+
if (debug) {
|
|
38
|
+
logDiff(code, result.code)
|
|
39
|
+
console.log('Output:\n', result.code + '\n\n')
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
transformInclude(id) {
|
|
45
|
+
return fileIsInRoutesDirectory(id, userConfig.routesDirectory)
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
vite: {
|
|
49
|
+
configResolved(config) {
|
|
50
|
+
ROOT = config.root
|
|
51
|
+
userConfig = getConfig(options, ROOT)
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
rspack() {
|
|
56
|
+
ROOT = process.cwd()
|
|
57
|
+
userConfig = getConfig(options, ROOT)
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
webpack() {
|
|
61
|
+
ROOT = process.cwd()
|
|
62
|
+
userConfig = getConfig(options, ROOT)
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAbsolute, join, normalize } from 'node:path'
|
|
2
|
+
|
|
3
|
+
export const debug =
|
|
4
|
+
process.env.TSR_VITE_DEBUG &&
|
|
5
|
+
['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)
|
|
6
|
+
|
|
7
|
+
export function fileIsInRoutesDirectory(
|
|
8
|
+
filePath: string,
|
|
9
|
+
routesDirectory: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
const routesDirectoryPath = isAbsolute(routesDirectory)
|
|
12
|
+
? routesDirectory
|
|
13
|
+
: join(process.cwd(), routesDirectory)
|
|
14
|
+
|
|
15
|
+
const path = normalize(filePath)
|
|
16
|
+
|
|
17
|
+
return path.startsWith(routesDirectoryPath)
|
|
18
|
+
}
|
package/src/esbuild.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createEsbuildPlugin } from 'unplugin'
|
|
2
|
+
|
|
3
|
+
import { configSchema } from './core/config'
|
|
4
|
+
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
|
|
5
|
+
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
|
|
6
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin'
|
|
7
|
+
|
|
8
|
+
import type { Config } from './core/config'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* export default {
|
|
14
|
+
* plugins: [TanStackRouterGeneratorEsbuild()],
|
|
15
|
+
* // ...
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const TanStackRouterGeneratorEsbuild = createEsbuildPlugin(
|
|
20
|
+
unpluginRouterGeneratorFactory,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* export default {
|
|
27
|
+
* plugins: [TanStackRouterCodeSplitterEsbuild()],
|
|
28
|
+
* // ...
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const TanStackRouterCodeSplitterEsbuild = createEsbuildPlugin(
|
|
33
|
+
unpluginRouterCodeSplitterFactory,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* export default {
|
|
40
|
+
* plugins: [TanStackRouterEsbuild()],
|
|
41
|
+
* // ...
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
const TanStackRouterEsbuild = createEsbuildPlugin(unpluginRouterComposedFactory)
|
|
46
|
+
|
|
47
|
+
export default TanStackRouterEsbuild
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
configSchema,
|
|
51
|
+
TanStackRouterGeneratorEsbuild,
|
|
52
|
+
TanStackRouterCodeSplitterEsbuild,
|
|
53
|
+
TanStackRouterEsbuild,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type { Config }
|
package/src/index.ts
ADDED
package/src/rspack.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createRspackPlugin } from 'unplugin'
|
|
2
|
+
|
|
3
|
+
import { configSchema } from './core/config'
|
|
4
|
+
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
|
|
5
|
+
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
|
|
6
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin'
|
|
7
|
+
import type { Config } from './core/config'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* // ...
|
|
14
|
+
* tools: {
|
|
15
|
+
* rspack: {
|
|
16
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
17
|
+
* },
|
|
18
|
+
* },
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const TanStackRouterGeneratorRspack = /* #__PURE__ */ createRspackPlugin(
|
|
23
|
+
unpluginRouterGeneratorFactory,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* export default defineConfig({
|
|
30
|
+
* // ...
|
|
31
|
+
* tools: {
|
|
32
|
+
* rspack: {
|
|
33
|
+
* plugins: [TanStackRouterCodeSplitterRspack()],
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
const TanStackRouterCodeSplitterRspack = /* #__PURE__ */ createRspackPlugin(
|
|
40
|
+
unpluginRouterCodeSplitterFactory,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* // ...
|
|
48
|
+
* tools: {
|
|
49
|
+
* rspack: {
|
|
50
|
+
* plugins: [TanStackRouterRspack()],
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
const TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(
|
|
57
|
+
unpluginRouterComposedFactory,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
export default TanStackRouterRspack
|
|
61
|
+
export {
|
|
62
|
+
configSchema,
|
|
63
|
+
TanStackRouterRspack,
|
|
64
|
+
TanStackRouterGeneratorRspack,
|
|
65
|
+
TanStackRouterCodeSplitterRspack,
|
|
66
|
+
}
|
|
67
|
+
export type { Config }
|
package/src/vite.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createVitePlugin } from 'unplugin'
|
|
2
|
+
|
|
3
|
+
import { configSchema } from './core/config'
|
|
4
|
+
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
|
|
5
|
+
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
|
|
6
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin'
|
|
7
|
+
|
|
8
|
+
import type { Config } from './core/config'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [TanStackRouterGeneratorVite()],
|
|
15
|
+
* // ...
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
20
|
+
unpluginRouterGeneratorFactory,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* export default defineConfig({
|
|
27
|
+
* plugins: [TanStackRouterCodeSplitterVite()],
|
|
28
|
+
* // ...
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
33
|
+
unpluginRouterCodeSplitterFactory,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* export default defineConfig({
|
|
40
|
+
* plugins: [TanStackRouterVite()],
|
|
41
|
+
* // ...
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
const TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)
|
|
46
|
+
const tanstackRouter = TanStackRouterVite
|
|
47
|
+
|
|
48
|
+
export default TanStackRouterVite
|
|
49
|
+
export {
|
|
50
|
+
configSchema,
|
|
51
|
+
TanStackRouterGeneratorVite,
|
|
52
|
+
TanStackRouterCodeSplitterVite,
|
|
53
|
+
TanStackRouterVite,
|
|
54
|
+
tanstackRouter,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type { Config }
|
package/src/webpack.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createWebpackPlugin } from 'unplugin'
|
|
2
|
+
|
|
3
|
+
import { configSchema } from './core/config'
|
|
4
|
+
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
|
|
5
|
+
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
|
|
6
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin'
|
|
7
|
+
import type { Config } from './core/config'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export default {
|
|
13
|
+
* // ...
|
|
14
|
+
* plugins: [TanStackRouterGeneratorWebpack()],
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
const TanStackRouterGeneratorWebpack = /* #__PURE__ */ createWebpackPlugin(
|
|
19
|
+
unpluginRouterGeneratorFactory,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* export default {
|
|
26
|
+
* // ...
|
|
27
|
+
* plugins: [TanStackRouterCodeSplitterWebpack()],
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const TanStackRouterCodeSplitterWebpack = /* #__PURE__ */ createWebpackPlugin(
|
|
32
|
+
unpluginRouterCodeSplitterFactory,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* export default {
|
|
39
|
+
* // ...
|
|
40
|
+
* plugins: [TanStackRouterWebpack()],
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
const TanStackRouterWebpack = /* #__PURE__ */ createWebpackPlugin(
|
|
45
|
+
unpluginRouterComposedFactory,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
export default TanStackRouterWebpack
|
|
49
|
+
export {
|
|
50
|
+
configSchema,
|
|
51
|
+
TanStackRouterWebpack,
|
|
52
|
+
TanStackRouterGeneratorWebpack,
|
|
53
|
+
TanStackRouterCodeSplitterWebpack,
|
|
54
|
+
}
|
|
55
|
+
export type { Config }
|