This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to NextJS with npx @next/codemod cra-to-next
- Loading branch information
Showing
15 changed files
with
2,264 additions
and
7,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["next/babel"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,12 @@ yarn-error.log* | |
|
||
dist/ | ||
.eslintcache | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
*.pem | ||
# debug | ||
# local env files | ||
# vercel | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
clearMocks: true, | ||
testPathIgnorePatterns: [ | ||
'<rootDir>/.next/', | ||
'<rootDir>/node_modules/', | ||
'<rootDir>/cypress/', | ||
'<rootDir>/dist/', | ||
'<rootDir>/build/', | ||
], | ||
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'], | ||
transform: { | ||
'^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest', | ||
'.(jpg|jpeg|png|otf|webp|ttf|woff|woff2|svg)$': | ||
'<rootDir>/src/test-utils/fileTransform.js', | ||
}, | ||
// For absolute imports | ||
modulePaths: ['<rootDir>/src'], | ||
collectCoverageFrom: [ | ||
'src/**/*.{js,ts,tsx}', | ||
'!src/**/*.{types,type,d}.ts', | ||
'!src/setup*', | ||
'!src/index.tsx', | ||
'!src/**/index.ts', | ||
'!src/types/**', | ||
'!**/test-utils/**', | ||
'!src/pages/*', | ||
], | ||
coverageThreshold: { | ||
global: { | ||
statements: 95, | ||
branches: 70, | ||
functions: 95, | ||
lines: 94, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
env: { | ||
PUBLIC_URL: '/carousel/', | ||
}, | ||
experimental: { | ||
craCompat: true, | ||
}, | ||
// Remove this to leverage Next.js' static image handling | ||
// read more here: https://nextjs.org/docs/api-reference/next/image | ||
images: { | ||
disableStaticImages: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module '*.jpeg'; | ||
declare module '*.jpg'; | ||
declare module '*.png'; | ||
declare module '*.svg'; | ||
declare module '*.ico'; | ||
declare module '*.webp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { StrictMode } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import App from './App'; | ||
|
||
ReactDOM.render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
document.getElementById('root') | ||
); | ||
export default function NextIndexWrapper() { | ||
return ( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// import NextIndexWrapper from '..' | ||
|
||
// next/dynamic is used to prevent breaking incompatibilities | ||
// with SSR from window.SOME_VAR usage, if this is not used | ||
// next/dynamic can be removed to take advantage of SSR/prerendering | ||
import dynamic from 'next/dynamic'; | ||
|
||
import { GetStaticPathsResult } from 'next'; | ||
|
||
// try changing "ssr" to true below to test for incompatibilities, if | ||
// no errors occur the above static import can be used instead and the | ||
// below removed | ||
const NextIndexWrapper = dynamic(() => import('..'), { ssr: false }); | ||
|
||
/** | ||
* Ensures that [[...slug]].tsx is outputed as index.html | ||
*/ | ||
export async function getStaticPaths(): Promise< | ||
GetStaticPathsResult<{ slug: string[] }> | ||
> { | ||
return { | ||
// An empty array, as per documentation, will generate one only index.html | ||
// ref: https://nextjs.org/docs/basic-features/data-fetching#the-paths-key-required | ||
paths: [{ params: { slug: [] } }], | ||
// To have an SPA both in dev and prod mode | ||
fallback: process.env.NODE_ENV === 'development', | ||
}; | ||
} | ||
|
||
/** | ||
* Empty function needed for getStaticPaths to work | ||
*/ | ||
export async function getStaticProps() { | ||
return { props: {} }; | ||
} | ||
|
||
export default function Page(props: any): JSX.Element { | ||
return <NextIndexWrapper {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Head from 'next/head'; | ||
|
||
export default function MyApp({ Component, pageProps }: any): JSX.Element { | ||
return ( | ||
<> | ||
<Head> | ||
<title>Material-UI Carousel</title> | ||
<meta | ||
name="viewport" | ||
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" | ||
/> | ||
</Head> | ||
|
||
<Component {...pageProps} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Document, { Html, Head, Main, NextScript } from 'next/document'; | ||
|
||
class MyDocument extends Document { | ||
render() { | ||
return ( | ||
<Html lang="en"> | ||
<Head> | ||
<meta charSet="utf-8" /> | ||
<link rel="icon" href={`${process.env.PUBLIC_URL}/favicon.ico`} /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link | ||
rel="manifest" | ||
href={`${process.env.PUBLIC_URL}/manifest.json`} | ||
/> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
</Head> | ||
|
||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
} | ||
} | ||
|
||
export default MyDocument; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require('path'); | ||
|
||
const camelcase = require('camelcase'); | ||
|
||
// This is a custom Jest transformer turning file imports into filenames. | ||
// http://facebook.github.io/jest/docs/en/webpack.html | ||
|
||
module.exports = { | ||
process(src, filename) { | ||
const assetFilename = JSON.stringify(path.basename(filename)); | ||
|
||
if (filename.match(/\.svg$/)) { | ||
// Based on how SVGR generates a component name: | ||
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 | ||
const pascalCaseFilename = camelcase(path.parse(filename).name, { | ||
pascalCase: true, | ||
}); | ||
const componentName = `Svg${pascalCaseFilename}`; | ||
return `const React = require('react'); | ||
module.exports = { | ||
__esModule: true, | ||
default: ${assetFilename}, | ||
ReactComponent: React.forwardRef(function ${componentName}(props, ref) { | ||
return { | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'svg', | ||
ref: ref, | ||
key: null, | ||
props: Object.assign({}, props, { | ||
children: ${assetFilename} | ||
}) | ||
}; | ||
}), | ||
};`; | ||
} | ||
|
||
return `module.exports = ${assetFilename};`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.