Skip to content

Commit

Permalink
fix(qwikcity dev): do not serve dist/ during dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Jul 18, 2024
1 parent 0b6752d commit 5595af1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-dolphins-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik-city': patch
---

During dev mode, qwik-city will no longer serve files from `dist/`, which are very likely to be stale/incorrect. Furthermore, query parameters are taken into account when serving files (like production servers would do).
2 changes: 1 addition & 1 deletion packages/qwik-city/buildtime/vite/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export function staticDistMiddleware({ config }: ViteDevServer) {
return;
}

const relPath = url.pathname.slice(1);
const relPath = `${url.pathname.slice(1)}${url.search}`;

const ext = getExtension(relPath);
const contentType = STATIC_CONTENT_TYPES[ext];
Expand Down
19 changes: 11 additions & 8 deletions packages/qwik-city/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {

ctx = createBuildContext(rootDir!, config.base, userOpts, target);

ctx.isDevServer = config.command === 'serve';
ctx.isDevServer = config.command === 'serve' && config.mode !== 'production';
ctx.isDevServerClientOnly = ctx.isDevServer && config.mode !== 'ssr';

await validatePlugin(ctx.opts);
Expand All @@ -105,14 +105,17 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {

configureServer(server) {
return () => {
// handles static files physically found in the dist directory
server.middlewares.use(staticDistMiddleware(server));
if (ctx) {
// qwik city middleware injected BEFORE vite internal middlewares
// and BEFORE @builder.io/qwik/optimizer/vite middlewares
// handles only known user defined routes
server.middlewares.use(ssrDevMiddleware(ctx, server));
if (!ctx) {
throw new Error('configureServer: Missing ctx from configResolved');
}
if (!ctx.isDevServer) {
// preview server: serve static files from the dist directory
server.middlewares.use(staticDistMiddleware(server));
}
// qwik city middleware injected BEFORE vite internal middlewares
// and BEFORE @builder.io/qwik/optimizer/vite middlewares
// handles only known user defined routes
server.middlewares.use(ssrDevMiddleware(ctx, server));
};
},

Expand Down

0 comments on commit 5595af1

Please sign in to comment.