-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathget-rspack.ts
44 lines (39 loc) · 1.32 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
42
43
44
import { warnOnce } from '../../build/output/log'
export function getRspackCore() {
warnRspack()
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() {
warnRspack()
try {
// eslint-disable-next-line import/no-extraneous-dependencies
const plugin = require('@rspack/plugin-react-refresh')
const entry = require.resolve(
'@rspack/plugin-react-refresh/react-refresh-entry'
)
plugin.entry = entry
return plugin
} 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 warnRspack() {
warnOnce(
`\`next-rspack\` is currently experimental. It's not an official Next.js plugin, and is supported by the Rspack team in partnership with Next.js. Help improve Next.js and Rspack by providing feedback at https://github.com/vercel/next.js/discussions/77800`
)
}