File tree Expand file tree Collapse file tree 4 files changed +63
-1
lines changed
Expand file tree Collapse file tree 4 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 1+ 'use server' ;
2+
3+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports
4+ import NextImage , { ImageProps } from 'next/image' ;
5+
6+ import { buildConfig } from '~/build-config/reader' ;
7+ import bcCdnImageLoader from '~/lib/cdn-image-loader' ;
8+
9+ function shouldUseLoaderProp ( props : ImageProps ) : boolean {
10+ if ( typeof props . src !== 'string' ) return false ;
11+
12+ const { src } = props ;
13+
14+ return buildConfig . get ( 'urls' ) . cdnUrls . some ( ( cdn ) => src . startsWith ( `https://${ cdn } ` ) ) ;
15+ }
16+
17+ /**
18+ * This component should be used in place of Next's `Image` component for images from the
19+ * BigCommerce platform, which will reduce load on the Next.js application for image assets.
20+ *
21+ * It defaults to use the default loader in Next.js if it's an image not from the BigCommerce CDN.
22+ *
23+ * @returns {React.ReactElement } The `<Image>` component
24+ */
25+ export const Image = ( { ...props } : ImageProps ) => {
26+ const loader = shouldUseLoaderProp ( props ) ? bcCdnImageLoader : undefined ;
27+
28+ return < NextImage loader = { loader } { ...props } /> ;
29+ } ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { writeBuildConfig } from './build-config/writer';
66import { client } from './client' ;
77import { graphql } from './client/graphql' ;
88import { cspHeader } from './lib/content-security-policy' ;
9+ import withPlaiceholder from "@plaiceholder/next" ;
910
1011const withNextIntl = createNextIntlPlugin ( {
1112 experimental : {
@@ -113,6 +114,9 @@ export default async (): Promise<NextConfig> => {
113114 // Apply withNextIntl to the config
114115 nextConfig = withNextIntl ( nextConfig ) ;
115116
117+ // Apply withPlaiceholder to the config
118+ nextConfig = withPlaiceholder ( nextConfig ) ;
119+
116120 if ( process . env . ANALYZE === 'true' ) {
117121 const withBundleAnalyzer = bundleAnalyzer ( ) ;
118122
Original file line number Diff line number Diff line change 1717 "@conform-to/react" : " ^1.6.1" ,
1818 "@conform-to/zod" : " ^1.6.1" ,
1919 "@icons-pack/react-simple-icons" : " ^11.2.0" ,
20+ "@plaiceholder/next" : " ^3.0.0" ,
2021 "@radix-ui/react-accordion" : " ^1.2.11" ,
2122 "@radix-ui/react-checkbox" : " ^1.3.2" ,
2223 "@radix-ui/react-dialog" : " ^1.1.14" ,
5556 "next-intl" : " ^4.1.0" ,
5657 "nuqs" : " ^2.4.3" ,
5758 "p-lazy" : " ^5.0.0" ,
59+ "plaiceholder" : " ^3.0.0" ,
5860 "react" : " ^19.1.0" ,
5961 "react-day-picker" : " ^9.7.0" ,
6062 "react-dom" : " ^19.1.0" ,
You can’t perform that action at this time.
0 commit comments