You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If one generates the dist folder with npm run build and then serve it with npx live-server dist --port=4000 --no-browser, one can find that requests to routes work as expected (e.g. /hi/foo -> src/pages/hi/[name].vue).
(this is what the "Build and Serve" command of Vite plugin for VSCode does)
However, how that works is magic to me.
I know that provide --entry-file=index.html to live-server can achieve that, but this command-line option is not there.
I ask about this because after I have removed vite-plugin-pages from my project and wrote routes manually, things doesn't work this way anymore. Every request to a route will respond with Cannot GET /path/to/that/route.
Now each time I build my site, I have to manually run npx live-server dist --port=4000 --no-browser --entry-file=index.html to make it work correctly.
I wonder if there is a way to make that work automatically again.
In Mandarin
虽然看得懂英语,但我不太会用英文做表达,以防万一用中文再说明一遍:
正常来说,用 npm run build 生成的 dist 文件夹,用 npx live-server dist --port=4000 --no-browser 来 serve,router 能正常运作(比如请求 /hi/foo 会路由到 src/pages/hi/[name].vue 来处理)。
(以上两条命令也即 VSCode Vite 插件 "Build and Serve" 执行的内容)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello.
If one generates the
dist
folder withnpm run build
and then serve it withnpx live-server dist --port=4000 --no-browser
, one can find that requests to routes work as expected (e.g./hi/foo
->src/pages/hi/[name].vue
).(this is what the "Build and Serve" command of Vite plugin for VSCode does)
However, how that works is magic to me.
I know that provide
--entry-file=index.html
tolive-server
can achieve that, but this command-line option is not there.I ask about this because after I have removed
vite-plugin-pages
from my project and wrote routes manually, things doesn't work this way anymore. Every request to a route will respond withCannot GET /path/to/that/route
.Now each time I build my site, I have to manually run
npx live-server dist --port=4000 --no-browser --entry-file=index.html
to make it work correctly.I wonder if there is a way to make that work automatically again.
In Mandarin
虽然看得懂英语,但我不太会用英文做表达,以防万一用中文再说明一遍:
正常来说,用
npm run build
生成的dist
文件夹,用npx live-server dist --port=4000 --no-browser
来 serve,router 能正常运作(比如请求/hi/foo
会路由到src/pages/hi/[name].vue
来处理)。(以上两条命令也即 VSCode Vite 插件 "Build and Serve" 执行的内容)
但我不明白其运作方式。
我只知道为
live-server
加上--entry-file=index.html
参数可以让 SPA 的路由运作,但这条参数并不存在。我把
vite-plugin-pages
去掉并替换为手动的路由后,一切魔法都消失了。现在我访问任何物理上不存在的路径,都会直接响应 404,页面内容提示
Cannot GET /path/to/that/route
。我只好每次生成 dist 后手动执行
npx live-server dist --port=4000 --no-browser --entry-file=index.html
来使 SPA 正常运作。我想知道有没有办法能让 VSCode Vite 插件的 "Build and Serve" 命令能重新自动地运作起来,而不需要每次手动执行上述命令。
感谢。
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions