Unverified Commit 1648064d authored by Max Proske's avatar Max Proske Committed by GitHub

Convert analyze-bundles example to TypeScript (#38040)

Converted Next.js Bundle Analyzer example over to TypeScript to align with the Examples guide.

I also replaced `faker` with `@faker-js/faker`. Faker has been forked and maintained [here](https://github.com/faker-js/faker) after the original author [deleted](https://www.theverge.com/2022/1/9/22874949/developer-corrupts-open-source-libraries-projects-affected) the library.

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 1d5dd1ba
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
/** @type {import('next').NextConfig} */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
......
......@@ -8,14 +8,18 @@
"serve": "serve .next/analyze"
},
"dependencies": {
"@next/bundle-analyzer": "^9.1.4",
"cross-env": "^6.0.3",
"faker": "^4.1.0",
"@faker-js/faker": "^7.3.0",
"@next/bundle-analyzer": "^12.1.6",
"cross-env": "^7.0.3",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"serve": "^11.3.2"
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"serve": "^13.0.2",
"typescript": "^4.7.4"
}
}
export default function About() {
const About = () => {
return <div>About us</div>
}
export default About
export default function Contact() {
const Contact = () => {
return <div>This is the contact page.</div>
}
export default Contact
import { NextPage, GetStaticProps } from 'next'
import Link from 'next/link'
import faker from 'faker'
import { faker } from '@faker-js/faker'
const Index = ({ name }) => {
type IndexProps = {
name: string
}
const Index: NextPage<IndexProps> = ({ name }) => {
return (
<div>
<h1>Home Page</h1>
......@@ -17,7 +22,7 @@ const Index = ({ name }) => {
export default Index
export async function getStaticProps() {
export const getStaticProps: GetStaticProps = async () => {
// The name will be generated at build time only
const name = faker.name.findName()
......
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment