@djangocfg/nextjs 2.1.32 → 2.1.34
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/README.md +22 -0
- package/bin/dev-with-browser.js +105 -0
- package/dist/config/index.d.mts +5 -1
- package/dist/config/index.mjs +8 -3
- package/dist/config/index.mjs.map +1 -1
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -6
- package/src/config/createNextConfig.ts +9 -2
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
## Features
|
|
19
19
|
|
|
20
|
+
- **Dev Server with Browser Auto-Open** - Cross-platform CLI that works with Turbopack and webpack
|
|
20
21
|
- **Zero-Config PWA** - Progressive Web App out of the box (service worker, offline support, manifest)
|
|
21
22
|
- **Base Next.js Config** - Universal, reusable Next.js configuration factory for monorepos
|
|
22
23
|
- **AI Documentation** - Search DjangoCFG docs via MCP server and CLI
|
|
@@ -39,6 +40,27 @@ yarn add @djangocfg/nextjs
|
|
|
39
40
|
|
|
40
41
|
## Quick Start
|
|
41
42
|
|
|
43
|
+
### Next.js Dev Server with Auto Browser Open
|
|
44
|
+
|
|
45
|
+
Start Next.js dev server with automatic browser opening (works with both Turbopack and webpack):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# In package.json
|
|
49
|
+
{
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dev": "nextjs-dev -p 3000", // Turbopack + auto browser open
|
|
52
|
+
"dev:webpack": "nextjs-dev --webpack" // webpack + auto browser open
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Features:**
|
|
58
|
+
- ✅ Cross-platform (macOS, Windows, Linux)
|
|
59
|
+
- ✅ Works with Turbopack (Next.js 16 default)
|
|
60
|
+
- ✅ Works with webpack mode
|
|
61
|
+
- ✅ Waits for server to be ready before opening
|
|
62
|
+
- ✅ Zero configuration
|
|
63
|
+
|
|
42
64
|
### AI Documentation Search
|
|
43
65
|
|
|
44
66
|
Search DjangoCFG documentation from the terminal:
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Next.js Dev Server with Auto Browser Opening
|
|
4
|
+
*
|
|
5
|
+
* Cross-platform solution that works with both Turbopack and webpack
|
|
6
|
+
* Opens browser automatically when server is ready
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* "dev": "dev-with-browser"
|
|
10
|
+
* "dev": "dev-with-browser --port 3000"
|
|
11
|
+
* "dev": "dev-with-browser --webpack"
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { spawn } = require('child_process');
|
|
15
|
+
const { exec } = require('child_process');
|
|
16
|
+
const consola = require('consola');
|
|
17
|
+
|
|
18
|
+
// Parse arguments
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const portArg = args.find(arg => arg.startsWith('--port') || arg === '-p');
|
|
21
|
+
const portIndex = args.indexOf(portArg);
|
|
22
|
+
const PORT = portArg
|
|
23
|
+
? args[portIndex + 1]
|
|
24
|
+
: process.env.PORT || '3000';
|
|
25
|
+
|
|
26
|
+
// Build next dev command
|
|
27
|
+
const nextArgs = ['dev'];
|
|
28
|
+
|
|
29
|
+
// Add port
|
|
30
|
+
if (!args.includes('-p') && !args.includes('--port')) {
|
|
31
|
+
nextArgs.push('-p', PORT);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Pass through other flags (like --webpack)
|
|
35
|
+
args.forEach((arg, i) => {
|
|
36
|
+
if (arg !== '-p' && arg !== '--port' && args[i - 1] !== '-p' && args[i - 1] !== '--port') {
|
|
37
|
+
nextArgs.push(arg);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const URL = `http://localhost:${PORT}`;
|
|
42
|
+
|
|
43
|
+
consola.info(`Starting Next.js dev server on port ${PORT}...`);
|
|
44
|
+
|
|
45
|
+
// Start Next.js dev server
|
|
46
|
+
const devServer = spawn('next', nextArgs, {
|
|
47
|
+
stdio: 'inherit',
|
|
48
|
+
shell: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Wait for server to be ready, then open browser
|
|
52
|
+
let serverReady = false;
|
|
53
|
+
let attempts = 0;
|
|
54
|
+
const maxAttempts = 60; // 30 seconds max
|
|
55
|
+
|
|
56
|
+
const checkInterval = setInterval(async () => {
|
|
57
|
+
if (serverReady || attempts >= maxAttempts) {
|
|
58
|
+
if (attempts >= maxAttempts) {
|
|
59
|
+
consola.warn('Server took too long to start, skipping browser open');
|
|
60
|
+
}
|
|
61
|
+
clearInterval(checkInterval);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
attempts++;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const response = await fetch(URL);
|
|
69
|
+
if (response.ok) {
|
|
70
|
+
serverReady = true;
|
|
71
|
+
clearInterval(checkInterval);
|
|
72
|
+
|
|
73
|
+
consola.success(`Server ready! Opening browser at ${URL}`);
|
|
74
|
+
|
|
75
|
+
// Open browser (cross-platform)
|
|
76
|
+
const command = process.platform === 'darwin'
|
|
77
|
+
? 'open'
|
|
78
|
+
: process.platform === 'win32'
|
|
79
|
+
? 'start'
|
|
80
|
+
: 'xdg-open';
|
|
81
|
+
|
|
82
|
+
exec(`${command} ${URL}`, (error) => {
|
|
83
|
+
if (error) {
|
|
84
|
+
consola.warn(`Failed to open browser: ${error.message}`);
|
|
85
|
+
consola.info(`Please open manually: ${URL}`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
// Server not ready yet, continue checking
|
|
91
|
+
}
|
|
92
|
+
}, 500);
|
|
93
|
+
|
|
94
|
+
// Cleanup on exit
|
|
95
|
+
process.on('SIGINT', () => {
|
|
96
|
+
clearInterval(checkInterval);
|
|
97
|
+
devServer.kill();
|
|
98
|
+
process.exit();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
process.on('SIGTERM', () => {
|
|
102
|
+
clearInterval(checkInterval);
|
|
103
|
+
devServer.kill();
|
|
104
|
+
process.exit();
|
|
105
|
+
});
|
package/dist/config/index.d.mts
CHANGED
|
@@ -338,7 +338,11 @@ interface BaseNextConfigOptions {
|
|
|
338
338
|
transpilePackages?: string[];
|
|
339
339
|
/** Additional optimize package imports (merged with defaults) */
|
|
340
340
|
optimizePackageImports?: string[];
|
|
341
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* Automatically open browser in dev mode (default: false)
|
|
343
|
+
* NOTE: Only works with webpack mode in Next.js 16+ (Turbopack doesn't support webpack plugins)
|
|
344
|
+
* For Turbopack compatibility, use a custom dev script instead of this option
|
|
345
|
+
*/
|
|
342
346
|
openBrowser?: boolean;
|
|
343
347
|
/** Check for @djangocfg/* package updates on startup (default: true) */
|
|
344
348
|
checkUpdates?: boolean;
|
package/dist/config/index.mjs
CHANGED
|
@@ -14,7 +14,7 @@ var require_package = __commonJS({
|
|
|
14
14
|
"package.json"(exports, module) {
|
|
15
15
|
module.exports = {
|
|
16
16
|
name: "@djangocfg/nextjs",
|
|
17
|
-
version: "2.1.
|
|
17
|
+
version: "2.1.34",
|
|
18
18
|
description: "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
|
|
19
19
|
keywords: [
|
|
20
20
|
"nextjs",
|
|
@@ -97,11 +97,13 @@ var require_package = __commonJS({
|
|
|
97
97
|
files: [
|
|
98
98
|
"dist",
|
|
99
99
|
"src",
|
|
100
|
+
"bin",
|
|
100
101
|
"README.md",
|
|
101
102
|
"LICENSE"
|
|
102
103
|
],
|
|
103
104
|
bin: {
|
|
104
|
-
"djangocfg-docs": "./dist/ai/cli.mjs"
|
|
105
|
+
"djangocfg-docs": "./dist/ai/cli.mjs",
|
|
106
|
+
"nextjs-dev": "./bin/dev-with-browser.js"
|
|
105
107
|
},
|
|
106
108
|
scripts: {
|
|
107
109
|
build: "tsup",
|
|
@@ -113,7 +115,7 @@ var require_package = __commonJS({
|
|
|
113
115
|
"ai-docs": "tsx src/ai/cli.ts"
|
|
114
116
|
},
|
|
115
117
|
peerDependencies: {
|
|
116
|
-
next: "^
|
|
118
|
+
next: "^16.0.10"
|
|
117
119
|
},
|
|
118
120
|
dependencies: {
|
|
119
121
|
"@ducanh2912/next-pwa": "^10.2.9",
|
|
@@ -1528,6 +1530,9 @@ function createBaseNextConfig(options = {}) {
|
|
|
1528
1530
|
...options.experimental
|
|
1529
1531
|
},
|
|
1530
1532
|
// Webpack configuration
|
|
1533
|
+
// NOTE: Next.js 16 uses Turbopack by default in dev mode, which doesn't support webpack plugins.
|
|
1534
|
+
// DevStartupPlugin only runs in webpack mode (next dev --webpack).
|
|
1535
|
+
// For Turbopack compatibility, consider using a custom dev script for browser auto-open.
|
|
1531
1536
|
webpack: (config, webpackOptions) => {
|
|
1532
1537
|
const { isServer, dev } = webpackOptions;
|
|
1533
1538
|
if (dev && !isServer) {
|