Skip to content

Commit

Permalink
feat: make sure to add turbopack for next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
seawatts committed Feb 5, 2025
1 parent fe161f0 commit e4e9830
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 156 deletions.
2 changes: 1 addition & 1 deletion integ-tests/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"start": "next start",
"lint": "next lint",
"test": "jest",
Expand Down
1 change: 1 addition & 0 deletions typescript/nextjs-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"access": "public"
},
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"format": "biome format --write .",
"lint": "biome check .",
Expand Down
51 changes: 32 additions & 19 deletions typescript/nextjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,36 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) {
// Default to new config (>= 14) if version can't be determined
const majorVersion = nextVersion ? parseInt(nextVersion.split('.')[0], 10) : 14
const useNewConfig = majorVersion >= 14
const turboConfig = {
...nextConfig.experimental?.turbo,
rules: { '*.node': { loaders: ['nextjs-node-loader'], as: '*.js' } },
}
const isTurbo = Boolean(process.env.TURBOPACK === '1')

const turboConfig = isTurbo
? {
...(nextConfig.experimental?.turbo || {}),
rules: {
...(nextConfig.experimental?.turbo?.rules || {}),
'*.node': { loaders: ['nextjs-node-loader'], as: '*.js' },
},
}
: undefined

return {
...nextConfig,
...(useNewConfig
? {
serverExternalPackages: [...((nextConfig as any)?.serverExternalPackages || []), '@boundaryml/baml'],
turbo: turboConfig,
experimental: {
...(nextConfig.experimental || {}),
...(isTurbo ? { turbo: turboConfig } : {}),
},
}
: {
experimental: {
...nextConfig.experimental,
...(nextConfig.experimental || {}),
serverComponentsExternalPackages: [
...((nextConfig.experimental as any)?.serverComponentsExternalPackages || []),
'@boundaryml/baml',
],
turbo: turboConfig,
...(isTurbo ? { turbo: turboConfig } : {}),
},
}),
webpack: (config: Configuration, context: any) => {
Expand All @@ -81,19 +91,22 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) {
config.externals = [...(Array.isArray(config.externals) ? config.externals : []), '@boundaryml/baml']
}

config.module = config.module || {}
config.module.rules = config.module.rules || []
config.module.rules.push({
test: /\.node$/,
use: [
{
loader: 'nextjs-node-loader',
options: {
outputPath: config.output?.path,
// Only add webpack rules if not using Turbo
if (!isTurbo) {
config.module = config.module || {}
config.module.rules = config.module.rules || []
config.module.rules.push({
test: /\.node$/,
use: [
{
loader: 'nextjs-node-loader',
options: {
outputPath: config.output?.path,
},
},
},
],
})
],
})
}

return config
},
Expand Down
Loading

0 comments on commit e4e9830

Please sign in to comment.