@@ -3,23 +3,25 @@ import '@contentlayer2/utils/effect/Tracing/Enable'
33import * as core from '@contentlayer2/core'
44import { errorToString } from '@contentlayer2/utils'
55import { E , OT , pipe , S , T } from '@contentlayer2/utils/effect'
6+ import type * as esbuild from 'esbuild'
67import type { WebpackOptionsNormalized } from 'webpack'
78
89import { checkConstraints } from './check-constraints.js'
910
1011export type NextPluginOptions = {
1112 configPath ?: string | undefined
13+ esbuildOptions ?: Pick < esbuild . BuildOptions , 'external' > | undefined
1214}
1315
1416/** Seems like the next.config.js export function might be executed multiple times, so we need to make sure we only run it once */
1517let contentlayerInitialized = false
1618
17- const runContentlayerDev = async ( { configPath } : NextPluginOptions ) => {
19+ const runContentlayerDev = async ( { configPath, esbuildOptions } : NextPluginOptions ) => {
1820 if ( contentlayerInitialized ) return
1921 contentlayerInitialized = true
2022
2123 await pipe (
22- core . getConfigWatch ( { configPath } ) ,
24+ core . getConfigWatch ( { configPath, esbuildOptions } ) ,
2325 S . tapSkipFirstRight ( ( ) => T . log ( `Contentlayer config change detected. Updating type definitions and data...` ) ) ,
2426 S . tapRight ( ( config ) => ( config . source . options . disableImportAliasWarning ? T . unit : T . fork ( core . validateTsconfig ) ) ) ,
2527 S . chainSwitchMapEitherRight ( ( config ) => core . generateDotpkgStream ( { config, verbose : false , isDev : true } ) ) ,
@@ -29,12 +31,12 @@ const runContentlayerDev = async ({ configPath }: NextPluginOptions) => {
2931 )
3032}
3133
32- const runContentlayerBuild = async ( { configPath } : NextPluginOptions ) => {
34+ const runContentlayerBuild = async ( { configPath, esbuildOptions } : NextPluginOptions ) => {
3335 if ( contentlayerInitialized ) return
3436 contentlayerInitialized = true
3537
3638 await pipe (
37- core . getConfig ( { configPath } ) ,
39+ core . getConfig ( { configPath, esbuildOptions } ) ,
3840 T . chain ( ( config ) => core . generateDotpkg ( { config, verbose : false } ) ) ,
3941 T . tap ( core . logGenerateInfo ) ,
4042 OT . withSpan ( 'next-contentlayer:runContentlayerBuild' ) ,
@@ -56,14 +58,14 @@ export const runBeforeWebpackCompile = async ({
5658 const isNextDev = mode === 'development'
5759 const isBuild = mode === 'production'
5860
59- const { configPath } = pluginOptions
61+ const { configPath, esbuildOptions } = pluginOptions
6062
6163 if ( isBuild ) {
6264 checkConstraints ( )
63- await runContentlayerBuild ( { configPath } )
65+ await runContentlayerBuild ( { configPath, esbuildOptions } )
6466 } else if ( isNextDev && ! devServerStartedRef . current ) {
6567 devServerStartedRef . current = true
6668 // TODO also block here until first Contentlayer run is complete
67- runContentlayerDev ( { configPath } )
69+ runContentlayerDev ( { configPath, esbuildOptions } )
6870 }
6971}
0 commit comments