@@ -24,9 +24,17 @@ import {
2424 verifyPublishDir ,
2525} from './build/verification.js'
2626
27+ const skipPlugin =
28+ process . env . NETLIFY_NEXT_PLUGIN_SKIP === 'true' || process . env . NETLIFY_NEXT_PLUGIN_SKIP === '1'
29+ const skipText = 'Skipping Next.js plugin due to NETLIFY_NEXT_PLUGIN_SKIP environment variable.'
2730const tracer = wrapTracer ( trace . getTracer ( 'Next.js runtime' ) )
2831
2932export const onPreDev = async ( options : NetlifyPluginOptions ) => {
33+ if ( skipPlugin ) {
34+ console . warn ( skipText )
35+ return
36+ }
37+
3038 await tracer . withActiveSpan ( 'onPreDev' , async ( ) => {
3139 const context = new PluginContext ( options )
3240
@@ -36,6 +44,11 @@ export const onPreDev = async (options: NetlifyPluginOptions) => {
3644}
3745
3846export const onPreBuild = async ( options : NetlifyPluginOptions ) => {
47+ if ( skipPlugin ) {
48+ console . warn ( skipText )
49+ return
50+ }
51+
3952 await tracer . withActiveSpan ( 'onPreBuild' , async ( ) => {
4053 // Enable Next.js standalone mode at build time
4154 process . env . NEXT_PRIVATE_STANDALONE = 'true'
@@ -53,6 +66,11 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
5366}
5467
5568export const onBuild = async ( options : NetlifyPluginOptions ) => {
69+ if ( skipPlugin ) {
70+ console . warn ( skipText )
71+ return
72+ }
73+
5674 await tracer . withActiveSpan ( 'onBuild' , async ( span ) => {
5775 const ctx = new PluginContext ( options )
5876
@@ -86,12 +104,22 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
86104}
87105
88106export const onPostBuild = async ( options : NetlifyPluginOptions ) => {
107+ if ( skipPlugin ) {
108+ console . warn ( skipText )
109+ return
110+ }
111+
89112 await tracer . withActiveSpan ( 'onPostBuild' , async ( ) => {
90113 await publishStaticDir ( new PluginContext ( options ) )
91114 } )
92115}
93116
94117export const onSuccess = async ( ) => {
118+ if ( skipPlugin ) {
119+ console . warn ( skipText )
120+ return
121+ }
122+
95123 await tracer . withActiveSpan ( 'onSuccess' , async ( ) => {
96124 const prewarm = [ process . env . DEPLOY_URL , process . env . DEPLOY_PRIME_URL , process . env . URL ] . filter (
97125 // If running locally then the deploy ID is a placeholder value. Filtering for `https://0--` removes it.
@@ -102,6 +130,11 @@ export const onSuccess = async () => {
102130}
103131
104132export const onEnd = async ( options : NetlifyPluginOptions ) => {
133+ if ( skipPlugin ) {
134+ console . warn ( skipText )
135+ return
136+ }
137+
105138 await tracer . withActiveSpan ( 'onEnd' , async ( ) => {
106139 await unpublishStaticDir ( new PluginContext ( options ) )
107140 } )
0 commit comments