-
Notifications
You must be signed in to change notification settings - Fork 28.1k
/
Copy pathget-rspack.ts
41 lines (36 loc) · 1.04 KB
/
get-rspack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { CanaryOnlyError, isStableBuild } from './canary-only'
export function getRspackCore() {
gateCanary()
try {
// eslint-disable-next-line import/no-extraneous-dependencies
return require('@rspack/core')
} catch (e) {
if (e instanceof Error && 'code' in e && e.code === 'MODULE_NOT_FOUND') {
throw new Error(
'@rspack/core is not available. Please make sure `next-rspack` is correctly installed.'
)
}
throw e
}
}
export function getRspackReactRefresh() {
gateCanary()
try {
// eslint-disable-next-line import/no-extraneous-dependencies
return require('@rspack/plugin-react-refresh')
} catch (e) {
if (e instanceof Error && 'code' in e && e.code === 'MODULE_NOT_FOUND') {
throw new Error(
'@rspack/plugin-react-refresh is not available. Please make sure `next-rspack` is correctly installed.'
)
}
throw e
}
}
function gateCanary() {
if (isStableBuild()) {
throw new CanaryOnlyError(
'Rspack support is only available in Next.js canary.'
)
}
}