create-nextify 0.1.13 → 0.1.15
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/dist/devServer.js +8 -5
- package/package.json +1 -1
package/dist/devServer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { createServer as createHttpServer } from 'node:http';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
4
5
|
const PORT = Number(process.env.PORT ?? 3000);
|
|
5
6
|
const PROJECT_ROOT = process.env.NEXTIFY_ROOT ?? process.cwd();
|
|
6
7
|
const PAGES_DIR = path.join(PROJECT_ROOT, 'pages');
|
|
@@ -79,16 +80,17 @@ function buildHtmlShell(routePath) {
|
|
|
79
80
|
export async function startDevServer(options = {}) {
|
|
80
81
|
const root = options.root ?? PROJECT_ROOT;
|
|
81
82
|
const port = options.port ?? PORT;
|
|
82
|
-
//
|
|
83
|
-
const vitePath = path.join(root, 'node_modules', 'vite', 'dist', 'node', 'index.js');
|
|
84
|
-
const reactPluginPath = path.join(root, 'node_modules', '@vitejs', 'plugin-react', 'dist', 'index.mjs');
|
|
83
|
+
// pathToFileURL converte C:\... para file:///C:/... — obrigatório no Windows
|
|
84
|
+
const vitePath = pathToFileURL(path.join(root, 'node_modules', 'vite', 'dist', 'node', 'index.js')).href;
|
|
85
|
+
const reactPluginPath = pathToFileURL(path.join(root, 'node_modules', '@vitejs', 'plugin-react', 'dist', 'index.mjs')).href;
|
|
85
86
|
let createViteServer, react;
|
|
86
87
|
try {
|
|
87
88
|
({ createServer: createViteServer } = await import(vitePath));
|
|
88
89
|
({ default: react } = await import(reactPluginPath));
|
|
89
90
|
}
|
|
90
91
|
catch (err) {
|
|
91
|
-
console.error('[nextify] Vite não encontrado. Rode
|
|
92
|
+
console.error('\n[nextify] Vite não encontrado. Rode dentro do projeto:\n');
|
|
93
|
+
console.error(' npm install vite @vitejs/plugin-react\n');
|
|
92
94
|
console.error(err.message);
|
|
93
95
|
process.exit(1);
|
|
94
96
|
}
|
|
@@ -107,7 +109,8 @@ export async function startDevServer(options = {}) {
|
|
|
107
109
|
const server = createHttpServer(async (req, res) => {
|
|
108
110
|
const host = req.headers.host ?? `localhost:${port}`;
|
|
109
111
|
const pathname = new URL(`http://${host}${req.url}`).pathname;
|
|
110
|
-
if (pathname.startsWith('/@') ||
|
|
112
|
+
if (pathname.startsWith('/@') ||
|
|
113
|
+
pathname.startsWith('/node_modules') ||
|
|
111
114
|
/\.(js|ts|tsx|jsx|css|svg|png|ico|woff2?|map)$/.test(pathname)) {
|
|
112
115
|
vite.middlewares(req, res, () => { res.statusCode = 404; res.end(); });
|
|
113
116
|
return;
|