Skip to content

Commit

Permalink
fix: support next build for app router without transpile (#833)
Browse files Browse the repository at this point in the history
## Related Issues

Fixes descope/etc#7785


## Description
add build aliases that convert 

tested on next13/14 both app router and pages router
  • Loading branch information
asafshen authored Oct 28, 2024
1 parent bdabab2 commit 58612e4
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 280 deletions.
1 change: 1 addition & 0 deletions packages/sdks/nextjs-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@open-wc/rollup-plugin-html": "^1.2.5",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^8.5.0",
"@swc/core": "^1.4.0",
Expand Down
27 changes: 18 additions & 9 deletions packages/sdks/nextjs-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import preserveDirectives from 'rollup-plugin-preserve-directives';
// import { swc } from 'rollup-plugin-swc3';
import { nodeResolve } from '@rollup/plugin-node-resolve';
// import commonjs from '@rollup/plugin-commonjs';
import alias from '@rollup/plugin-alias';

const nextSubPackages = [
'next/server',
'next/dynamic',
'next/navigation',
'next/router',
'next/link',
'next/headers'
];

// Common plugins for all configurations
const commonPlugins = (outputDir) => [
Expand All @@ -26,6 +36,13 @@ const commonPlugins = (outputDir) => [
preserveDirectives({ supressPreserveModulesWarning: true }),
nodeResolve(),
// commonjs(),
alias({
entries: nextSubPackages.map((alias) => {
// Append the `.js` suffix to Next.js sub-packages
// to ensure compatibility with Node environments
return { find: alias, replacement: `${alias}.js` };
})
}),
autoExternal()
// terser()
];
Expand All @@ -38,15 +55,7 @@ const configurations = ['server', 'client', ''].map((entry) => {

return {
input: inputPath,
external: [
'next/server',
'react',
'next/dynamic',
'next/router',
'next/navigation',
'next/link',
'next/headers'
],
external: ['react', ...nextSubPackages.map((alias) => `${alias}.js`)],
onwarn(warning, warn) {
if (
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
Expand Down
Loading

0 comments on commit 58612e4

Please sign in to comment.