Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: correct nextjs integration error handle #176

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
process.env.ESLINT_TSCONFIG = 'tsconfig.json'
const jsonExtJsoncFiles = [
'**/tsconfig.json',
'**/tsconfig.*.json',
'.vscode/*.json',
]

module.exports = {
root: true,
Expand Down Expand Up @@ -321,6 +326,10 @@ module.exports = {
'antfu/if-newline': 'off',
// https://github.com/antfu/eslint-config/blob/v0.39.7/packages/eslint-config-basic/index.js#L398
'antfu/top-level-function': 'off',

// this will cause many changes when auto fix package.json
'jsonc/sort-keys': 'off',
'jsonc/comma-dangle': ['error', 'always-multiline'],
},

overrides: [
Expand All @@ -331,5 +340,12 @@ module.exports = {
'unicorn/prefer-node-protocol': 'off',
},
},
{
files: ['*.json'],
excludedFiles: jsonExtJsoncFiles,
rules: {
'jsonc/comma-dangle': 'off',
},
},
],
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
],
"svg.preview.background": "transparent",

// use eslint codeActionOnSave to format
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
},

"tailwindCSS.experimental.classRegex": [
"\\b(?:class|className): *`((.|\n)*?)`",
"\\b(?:class|className): *\"((.|\n)*?)\"",
Expand Down
2 changes: 1 addition & 1 deletion docs/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://nextjs.org/docs/advanced-features/customizing-babel-config
// https://nextjs.org/docs/pages/building-your-application/configuring/babel
module.exports = {
presets: [
'next/babel',
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/compiler-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Follow the docs of [Nextjs Babel configuration](https://nextjs.org/docs/pages/bu
add plugin to `.babelrc.js` or `babel.config.js`:

```tsx filename=".babelrc.js" showLineNumbers {8}
// https://nextjs.org/docs/advanced-features/customizing-babel-config
// https://nextjs.org/docs/pages/building-your-application/configuring/babel
module.exports = {
presets: [
'next/babel',
Expand Down
13 changes: 8 additions & 5 deletions docs/pages/docs/integration/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Here provide a example template for your to create a `server.mjs` as custom serv

```js filename="server.mjs" showLineNumbers {6,27}
/**
* https://nextjs.org/docs/advanced-features/custom-server
* https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
*/
import { createServer } from 'node:http'
import next from 'next'
Expand Down Expand Up @@ -78,11 +78,14 @@ app.prepare().then(() => {
res.statusCode = 500
res.end('internal server error')
}
}).listen(port, (err) => {
if (err) throw err
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
})
.once('error', (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
```

> That is because the `launchEditorMiddleware` can it CANNOT running in Next.js [Edge Runtime](https://github.com/vercel/next.js/discussions/34179),
Expand Down
12 changes: 8 additions & 4 deletions docs/server.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* https://nextjs.org/docs/advanced-features/custom-server
* https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
*/
import { createServer } from 'node:http'
import next from 'next'
Expand Down Expand Up @@ -49,8 +49,12 @@ app.prepare().then(() => {
res.statusCode = 500
res.end('internal server error')
}
}).listen(port, (err) => {
if (err) throw err
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
.once('error', (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
})
2 changes: 1 addition & 1 deletion examples/nextjs-custom-server/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://nextjs.org/docs/advanced-features/customizing-babel-config
// https://nextjs.org/docs/pages/building-your-application/configuring/babel
module.exports = {
presets: [
'next/babel',
Expand Down
12 changes: 8 additions & 4 deletions examples/nextjs-custom-server/server.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* https://nextjs.org/docs/advanced-features/custom-server
* https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
*/
import { createServer } from 'node:http'
import next from 'next'
Expand Down Expand Up @@ -49,8 +49,12 @@ app.prepare().then(() => {
res.statusCode = 500
res.end('internal server error')
}
}).listen(port, (err) => {
if (err) throw err
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
.once('error', (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.debug(`\n > Ready on http://${hostname}:${port} \n`)
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"author": "zthxxx <[email protected]>",
"repository": "zthxxx/react-dev-inspector",
"packageManager": "[email protected]",
"files": [],
"scripts": {
"prepare": "husky install",
Expand Down
Loading