Skip to content

Commit

Permalink
Merge pull request #176 from tjx666/dev
Browse files Browse the repository at this point in the history
- docs: correct nextjs integration error handle
- update Next.js custom-server integration in examples
  • Loading branch information
zthxxx authored Jul 8, 2024
2 parents 0f0205f + 508cb24 commit 1ab6935
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
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 <zthxxx.me@gmail.com>",
"repository": "zthxxx/react-dev-inspector",
"packageManager": "pnpm@8.15.8",
"files": [],
"scripts": {
"prepare": "husky install",
Expand Down

0 comments on commit 1ab6935

Please sign in to comment.