@djangocfg/nextjs 2.1.33 → 2.1.35

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 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,114 @@
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
+
21
+ // Extract port
22
+ let PORT = process.env.PORT || '3000';
23
+ const portIndex = args.findIndex(arg => arg === '-p' || arg === '--port');
24
+ if (portIndex !== -1 && args[portIndex + 1]) {
25
+ PORT = args[portIndex + 1];
26
+ }
27
+
28
+ // Build next dev command
29
+ const nextArgs = ['dev', '-p', PORT];
30
+
31
+ // Check if --webpack flag is present
32
+ const hasWebpackFlag = args.includes('--webpack');
33
+
34
+ // Add --turbopack by default (unless --webpack is specified)
35
+ // This silences the "webpack config with no turbopack config" warning
36
+ if (!hasWebpackFlag) {
37
+ nextArgs.push('--turbopack');
38
+ }
39
+
40
+ // Pass through other flags, excluding port arguments
41
+ args.forEach((arg, i) => {
42
+ const isPreviousPort = i > 0 && (args[i - 1] === '-p' || args[i - 1] === '--port');
43
+ const isPortFlag = arg === '-p' || arg === '--port';
44
+
45
+ if (!isPortFlag && !isPreviousPort) {
46
+ nextArgs.push(arg);
47
+ }
48
+ });
49
+
50
+ const URL = `http://localhost:${PORT}`;
51
+
52
+ consola.info(`Starting Next.js dev server on port ${PORT}...`);
53
+
54
+ // Start Next.js dev server
55
+ const devServer = spawn('next', nextArgs, {
56
+ stdio: 'inherit',
57
+ shell: true,
58
+ });
59
+
60
+ // Wait for server to be ready, then open browser
61
+ let serverReady = false;
62
+ let attempts = 0;
63
+ const maxAttempts = 60; // 30 seconds max
64
+
65
+ const checkInterval = setInterval(async () => {
66
+ if (serverReady || attempts >= maxAttempts) {
67
+ if (attempts >= maxAttempts) {
68
+ consola.warn('Server took too long to start, skipping browser open');
69
+ }
70
+ clearInterval(checkInterval);
71
+ return;
72
+ }
73
+
74
+ attempts++;
75
+
76
+ try {
77
+ const response = await fetch(URL);
78
+ if (response.ok) {
79
+ serverReady = true;
80
+ clearInterval(checkInterval);
81
+
82
+ consola.success(`Server ready! Opening browser at ${URL}`);
83
+
84
+ // Open browser (cross-platform)
85
+ const command = process.platform === 'darwin'
86
+ ? 'open'
87
+ : process.platform === 'win32'
88
+ ? 'start'
89
+ : 'xdg-open';
90
+
91
+ exec(`${command} ${URL}`, (error) => {
92
+ if (error) {
93
+ consola.warn(`Failed to open browser: ${error.message}`);
94
+ consola.info(`Please open manually: ${URL}`);
95
+ }
96
+ });
97
+ }
98
+ } catch (err) {
99
+ // Server not ready yet, continue checking
100
+ }
101
+ }, 500);
102
+
103
+ // Cleanup on exit
104
+ process.on('SIGINT', () => {
105
+ clearInterval(checkInterval);
106
+ devServer.kill();
107
+ process.exit();
108
+ });
109
+
110
+ process.on('SIGTERM', () => {
111
+ clearInterval(checkInterval);
112
+ devServer.kill();
113
+ process.exit();
114
+ });
@@ -338,7 +338,11 @@ interface BaseNextConfigOptions {
338
338
  transpilePackages?: string[];
339
339
  /** Additional optimize package imports (merged with defaults) */
340
340
  optimizePackageImports?: string[];
341
- /** Automatically open browser in dev mode (default: false) */
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;
@@ -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.33",
17
+ version: "2.1.35",
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",
@@ -1452,9 +1454,6 @@ function createBaseNextConfig(options = {}) {
1452
1454
  const baseConfig = {
1453
1455
  reactStrictMode: true,
1454
1456
  trailingSlash: true,
1455
- // Turbopack config (empty to silence Next.js 16 warning about webpack config)
1456
- // Webpack config is still used for dev startup plugin and compression
1457
- turbopack: {},
1458
1457
  // Static export configuration
1459
1458
  ...isStaticBuild && {
1460
1459
  output: "export",
@@ -1531,6 +1530,9 @@ function createBaseNextConfig(options = {}) {
1531
1530
  ...options.experimental
1532
1531
  },
1533
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.
1534
1536
  webpack: (config, webpackOptions) => {
1535
1537
  const { isServer, dev } = webpackOptions;
1536
1538
  if (dev && !isServer) {