Skip to content

Commit

Permalink
Add devDependency and loader util for additional bundler
Browse files Browse the repository at this point in the history
This adds `@rspack/core` as a `devDependency` to Next.js, as it will be conditionally referenced in core in the future and will only run when the real dependency is added via a future plugin.

This also creates a `getRspackCore` utility which performs this check, suppresses the lint, and more clearly informs the user of the error.
  • Loading branch information
wbinnssmith committed Feb 12, 2025
1 parent cf73ab1 commit b8db5b9
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@next/third-parties": "workspace:*",
"@opentelemetry/api": "1.4.1",
"@picocss/pico": "1.5.10",
"@rspack/core": "npm:@rspack-canary/[email protected]",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.9.3",
Expand Down
16 changes: 16 additions & 0 deletions packages/next/src/shared/lib/get-rspack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type * as RspackCore from '@rspack/core'

export function getRspackCore(): typeof RspackCore {
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 the appropriate Next.js plugin is installed.'
)
}

throw e
}
}
182 changes: 172 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8db5b9

Please sign in to comment.