Update Next.js to 12 and switch to npm (#562)

* Update Commerce to Next.js 12

* Switch to npm

* Removed yarn

* Updated fetch type

* Fixed issue with BC deployment
This commit is contained in:
Luis Alvarez D 2021-11-09 11:12:00 -05:00 committed by GitHub
parent e3471db3eb
commit 582e9257d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 27349 additions and 7301 deletions

View File

@ -105,11 +105,10 @@ Our commitment to Open Source can be found [here](https://vercel.com/oss).
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device.
2. Create a new branch `git checkout -b MY_BRANCH_NAME`
3. Install yarn: `npm install -g yarn`
4. Install the dependencies: `yarn`
5. Duplicate `.env.template` and rename it to `.env.local`
6. Add proper store values to `.env.local`
7. Run `yarn dev` to build and watch for code changes
3. Install the dependencies: `npm i`
4. Duplicate `.env.template` and rename it to `.env.local`
5. Add proper store values to `.env.local`
6. Run `npm run dev` to build and watch for code changes
## Work in progress

View File

@ -46,15 +46,17 @@ const ProductCard: FC<Props> = ({
<span>{product.name}</span>
</div>
{product?.images && (
<Image
quality="85"
src={product.images[0]?.url || placeholderImg}
alt={product.name || 'Product Image'}
height={320}
width={320}
layout="fixed"
{...imgProps}
/>
<div>
<Image
quality="85"
src={product.images[0]?.url || placeholderImg}
alt={product.name || 'Product Image'}
height={320}
width={320}
layout="fixed"
{...imgProps}
/>
</div>
)}
</>
)}
@ -80,16 +82,18 @@ const ProductCard: FC<Props> = ({
)}
<div className={s.imageContainer}>
{product?.images && (
<Image
alt={product.name || 'Product Image'}
className={s.productImage}
src={product.images[0]?.url || placeholderImg}
height={540}
width={540}
quality="85"
layout="responsive"
{...imgProps}
/>
<div>
<Image
alt={product.name || 'Product Image'}
className={s.productImage}
src={product.images[0]?.url || placeholderImg}
height={540}
width={540}
quality="85"
layout="responsive"
{...imgProps}
/>
</div>
)}
</div>
</>
@ -110,16 +114,18 @@ const ProductCard: FC<Props> = ({
/>
<div className={s.imageContainer}>
{product?.images && (
<Image
alt={product.name || 'Product Image'}
className={s.productImage}
src={product.images[0]?.url || placeholderImg}
height={540}
width={540}
quality="85"
layout="responsive"
{...imgProps}
/>
<div>
<Image
alt={product.name || 'Product Image'}
className={s.productImage}
src={product.images[0]?.url || placeholderImg}
height={540}
width={540}
quality="85"
layout="responsive"
{...imgProps}
/>
</div>
)}
</div>
</>

View File

@ -13,9 +13,7 @@
}
.thumb {
@apply transition-transform transition-colors
ease-linear duration-75 overflow-hidden inline-block
cursor-pointer h-full;
@apply overflow-hidden inline-block cursor-pointer h-full;
width: 125px;
width: calc(100% / 3);
}
@ -48,11 +46,6 @@
@screen md {
.thumb:hover {
transform: scale(1.02);
background-color: rgba(255, 255, 255, 0.08);
}
.thumb.selected {
@apply bg-white;
}
.album {

View File

@ -17,16 +17,15 @@
}
.imageContainer {
@apply text-center;
@apply text-center h-full relative;
}
.imageContainer > div,
.imageContainer > div > div {
@apply h-full;
.imageContainer > span {
height: 100% !important;
}
.sliderContainer .img {
@apply w-full h-auto max-h-full object-cover;
@apply w-full h-full max-h-full object-cover;
}
.button {

View File

@ -58,7 +58,11 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
)}
</div>
<ProductSidebar key={product.id} product={product} className={s.sidebar} />
<ProductSidebar
key={product.id}
product={product}
className={s.sidebar}
/>
</div>
<hr className="mt-7 border-accent-2" />
<section className="py-12 px-6 mb-10">

View File

@ -62,12 +62,14 @@ const WishlistCard: FC<Props> = ({ product }) => {
return (
<div className={cn(s.root, { 'opacity-75 pointer-events-none': removing })}>
<div className={`col-span-3 ${s.productBg}`}>
<Image
src={product.images[0]?.url || placeholderImg}
width={400}
height={400}
alt={product.images[0]?.alt || 'Product Image'}
/>
<div>
<Image
src={product.images[0]?.url || placeholderImg}
width={400}
height={400}
alt={product.images[0]?.alt || 'Product Image'}
/>
</div>
</div>
<div className="col-span-7">

View File

@ -1,11 +1,11 @@
import type { RequestInit, Response } from '@vercel/fetch'
import type { FetchOptions, Response } from '@vercel/fetch'
import type { BigcommerceConfig } from '../index'
import { BigcommerceApiError, BigcommerceNetworkError } from './errors'
import fetch from './fetch'
const fetchStoreApi =
<T>(getConfig: () => BigcommerceConfig) =>
async (endpoint: string, options?: RequestInit): Promise<T> => {
async (endpoint: string, options?: FetchOptions): Promise<T> => {
const config = getConfig()
let res: Response
@ -19,7 +19,7 @@ const fetchStoreApi =
'X-Auth-Client': config.storeApiClientId,
},
})
} catch (error) {
} catch (error: any) {
throw new BigcommerceNetworkError(
`Fetch to Bigcommerce failed: ${error.message}`
)

View File

@ -1,3 +1,3 @@
import zeitFetch from '@vercel/fetch'
import vercelFetch from '@vercel/fetch'
export default zeitFetch()
export default vercelFetch()

View File

@ -1,5 +1,5 @@
import type { NextApiHandler } from 'next'
import type { RequestInit, Response } from '@vercel/fetch'
import type { FetchOptions, Response } from '@vercel/fetch'
import type { APIEndpoint, APIHandler } from './utils/types'
import type { CartSchema } from '../types/cart'
import type { CustomerSchema } from '../types/customer'
@ -160,7 +160,7 @@ export interface CommerceAPIConfig {
fetch<Data = any, Variables = any>(
query: string,
queryData?: CommerceAPIFetchOptions<Variables>,
fetchOptions?: RequestInit
fetchOptions?: FetchOptions
): Promise<GraphQLFetcherResult<Data>>
}
@ -170,7 +170,7 @@ export type GraphQLFetcher<
> = (
query: string,
queryData?: CommerceAPIFetchOptions<Variables>,
fetchOptions?: RequestInit
fetchOptions?: FetchOptions
) => Promise<Data>
export interface GraphQLFetcherResult<Data = any> {

3
next-env.d.ts vendored
View File

@ -1,3 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

27278
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"dev": "NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"start": "next start",
"analyze": "BUNDLE_ANALYZE=both yarn build",
"analyze": "BUNDLE_ANALYZE=both next build",
"lint": "next lint",
"prettier-fix": "prettier --write .",
"find:unused": "npx next-unused",
@ -21,7 +21,7 @@
},
"dependencies": {
"@react-spring/web": "^9.2.1",
"@vercel/fetch": "^6.1.0",
"@vercel/fetch": "^6.1.1",
"autoprefixer": "^10.2.6",
"body-scroll-lock": "^3.1.5",
"classnames": "^2.3.1",
@ -33,7 +33,7 @@
"lodash.debounce": "^4.0.8",
"lodash.random": "^3.2.0",
"lodash.throttle": "^4.1.1",
"next": "^11.0.0",
"next": "^12.0.3",
"next-seo": "^4.26.0",
"next-themes": "^0.0.14",
"postcss": "^8.3.5",

7236
yarn.lock

File diff suppressed because it is too large Load Diff