next-dev-qr 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +71 -0
- package/index.js +27 -0
- package/package.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright [2026] [Raunak]
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, so subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# next-dev-qr
|
|
2
|
+
|
|
3
|
+
A lightweight, **zero-config** utility to generate a QR code in your terminal when starting the Next.js development server. Perfect for instant mobile testing without manually typing local IP addresses.
|
|
4
|
+
|
|
5
|
+
Built for modern Next.js (14, 15+), supporting both **Webpack** and **Turbopack**.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* **๐ Zero Friction:** Scan and open your dev site on mobile instantly.
|
|
10
|
+
* **๐ Turbopack Ready:** Uses the Next.js `instrumentation` hook to work with the latest compilers.
|
|
11
|
+
* **๐ Smart IP Detection:** Automatically finds your local network IP.
|
|
12
|
+
* **๐งน Dev-Only:** Automatically disables itself in production environments to keep logs clean.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install next-dev-qr
|
|
18
|
+
# or
|
|
19
|
+
pnpm add next-dev-qr
|
|
20
|
+
# or
|
|
21
|
+
yarn add next-dev-qr
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Next.js 14.1+ supports an `instrumentation` file that runs code when the server starts. This is the recommended way to use `next-dev-qr`.
|
|
27
|
+
|
|
28
|
+
### 1. Enable Instrumentation
|
|
29
|
+
Ensure your `next.config.js` allows the instrumentation hook (this is default in Next.js 15).
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
/** @type {import('next').NextConfig} */
|
|
33
|
+
const nextConfig = {
|
|
34
|
+
experimental: {
|
|
35
|
+
instrumentationHook: true,
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = nextConfig
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Create the Hook
|
|
43
|
+
Create an `instrumentation.ts` (or `.js`) file in your **root directory** (or inside `/src` if you use it).
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
export async function register() {
|
|
47
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
48
|
+
const { register: registerQR } = await import('next-dev-qr');
|
|
49
|
+
registerQR();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 3. Run
|
|
55
|
+
Start your server as usual:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The QR code will appear in your terminal immediately after the server initializes.
|
|
62
|
+
|
|
63
|
+
## Why not a Webpack Plugin?
|
|
64
|
+
Traditional Next.js plugins modify the Webpack config. However, with the move toward **Turbopack (Rust-based compiler)**, Webpack plugins are being phased out. `next-dev-qr` uses the **Instrumentation API**, making it bundler-agnostic and future-proof.
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
This project aims to demonstrate the utility of QR-based mobile debugging for potential inclusion in Next.js core. Feel free to open issues or PRs.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
MIT
|
|
71
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const qrcode = require('qrcode-terminal');
|
|
2
|
+
const ip = require('address');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The register() function is called by Next.js during server initialization.
|
|
6
|
+
* This works with both Webpack and Turbopack.
|
|
7
|
+
*/
|
|
8
|
+
function register() {
|
|
9
|
+
// Only execute in development mode and on the server side
|
|
10
|
+
if (process.env.NODE_ENV === 'development' && typeof window === 'undefined') {
|
|
11
|
+
|
|
12
|
+
// Check a global flag to prevent double-logging in some environments
|
|
13
|
+
if (!global.__NEXT_QR_LOGGED__) {
|
|
14
|
+
const port = process.env.PORT || 3000;
|
|
15
|
+
const localIp = ip.ip();
|
|
16
|
+
const url = `http://${localIp}:${port}`;
|
|
17
|
+
|
|
18
|
+
console.log('\n\x1b[35m%s\x1b[0m', '๐ Next.js Mobile Access:');
|
|
19
|
+
qrcode.generate(url, { small: true });
|
|
20
|
+
console.log(`Network: ${url}\n`);
|
|
21
|
+
|
|
22
|
+
global.__NEXT_QR_LOGGED__ = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { register };
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "next-dev-qr",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"description": "QR code generator for Next.js dev server (Turbopack compatible)",
|
|
6
|
+
"keywords": ["nextjs", "turbopack", "dx", "qrcode", "mobile-testing"],
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"author": "Raunak",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"address": "^2.0.3",
|
|
15
|
+
"qrcode-terminal": "^0.12.0"
|
|
16
|
+
}
|
|
17
|
+
}
|