[{"id":"viteadvanced-001","courseId":"vite-advanced","domain":"dev-server-and-hmr","topic":"Barrel file import cost","prompt":"A component writes import { slash } from './utils'. The utils folder's index.js re-exports three files with export *. Under the Vite dev server, what does that one import cost on page load?","hint":"Think about what must be loaded before the one name can be used, not just that name.","explain":"A module that re-exports from other modules pulls them into the graph whether or not you use them. Each pulled-in file must be requested, transformed and run, and a file can run code just by being loaded.","source":"https://vite.dev/guide/performance","interaction":{"type":"single"},"options":[{"id":"a","text":"Every file the barrel re-exports gets fetched and transformed, since any of them could hold slash or run side effects.","why":"All files behind a barrel must be fetched and transformed, because any of them may hold the API or run code on initialization."},{"id":"b","text":"Only slash.js gets fetched, because named imports are trimmed to one file before the browser sees them.","whyNot":"Vite does not trim the barrel; the browser requests index.js and then every file it re-exports."},{"id":"c","text":"Nothing extra: the barrel is a lookup table that is resolved away before any file is fetched.","whyNot":"A barrel stays a real module in the browser, so its re-exports are requested as it loads."},{"id":"d","text":"Only index.js gets fetched, because re-exports are cached together as a single unit.","whyNot":"Each re-exported file is a separate module with its own request and transform, not one cached unit."}],"answer":"a","explanation":"A barrel file re-exports other modules, so importing one name still requires loading every module it re-exports, along with any side effects those modules run on initialization.","concept":"A barrel file re-exports other modules, so importing one name still requires loading every module it re-exports, along with any side effects those modules run on initialization.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"// src/utils/index.js\nexport * from './color.js'\nexport * from './dom.js'\nexport * from './slash.js'","takeaways":["Importing one name from a barrel can load every file behind it.","Import from the individual file to skip the rest of the barrel."]},{"id":"viteadvanced-002","courseId":"vite-advanced","domain":"dev-server-and-hmr","topic":"Pre-bundle caching in dev","prompt":"In the Vite dev server, ticking Disable cache in the browser's DevTools speeds up full-page reloads, because it forces fresh pre-bundled dependencies.","hint":"Ask whether the server is built to be served from the browser's stored copies.","explain":"Dev servers can lean on the browser's own storage to make repeat loads cheap. Whether a DevTools setting helps depends on how the server expects its responses to be cached and revalidated.","source":"https://vite.dev/guide/performance","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Disable Cache makes the browser skip its stored copies, which works against the dev server's hard caching and fast 304 replies, so reloads slow down."},{"id":"b","text":"False","why":"The dev server relies on caching: it hard-caches pre-bundles and answers source requests with fast 304s, so disabling the cache slows startup and reloads."}],"answer":"b","explanation":"The Vite dev server hard-caches pre-bundled dependencies and returns fast 304 responses for source code, so leaving the browser's Disable Cache option on removes that speed-up.","concept":"The Vite dev server hard-caches pre-bundled dependencies and returns fast 304 responses for source code, so leaving the browser's Disable Cache option on removes that speed-up.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Keep Disable Cache off in DevTools while you work with the Vite dev server.","The dev server hard-caches pre-bundled dependencies."]},{"id":"viteadvanced-003","courseId":"vite-advanced","domain":"dev-server-and-hmr","topic":"fs.strict file access limits","prompt":"Vite's dev server uses the default server.fs.strict setting. Which TWO statements about how it limits file access are correct?","hint":"Consider which list wins when two settings conflict, and what happens to a file that no list mentions.","explain":"By default the dev server refuses to serve files beyond its workspace scope. The two lists that adjust access are not equal in strength, and one can override the other.","source":"https://vite.dev/config/server-options","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A file outside the allow list gets a 403, unless an allowed file imports it.","why":"Strict mode refuses paths outside the allow scope with a 403, except for files that an allowed file imports."},{"id":"b","text":"server.fs.deny still blocks .env and key files inside a folder that server.fs.allow permits.","why":"The deny list has higher priority than allow, so sensitive files stay blocked even inside an allowed folder."},{"id":"c","text":"Files in the public directory are checked against server.fs.deny, so a .env file there gets blocked.","whyNot":"The deny blocklist does not apply to the public directory; those files are served without filtering."},{"id":"d","text":"Once server.fs.allow is set, Vite still searches for a workspace root and adds it to the list.","whyNot":"Setting allow turns off the automatic workspace search; the list you give is used as it is."},{"id":"e","text":"The only way to serve a file from the parent folder is to set server.fs.strict to false.","whyNot":"You can list the parent folder in server.fs.allow, such as '..', and keep strict on."},{"id":"f","text":"Because allow is checked first, any folder listed in server.fs.allow exposes the files deny matches.","whyNot":"Deny has higher priority than allow, so a denied file stays blocked even in an allowed folder."}],"answer":"ab","explanation":"server.fs.strict is on by default and limits serving to the workspace; files outside fs.allow get a 403 unless an allowed file imports them, and fs.deny outranks fs.allow and skips the public directory.","concept":"server.fs.strict is on by default and limits serving to the workspace; files outside fs.allow get a 403 unless an allowed file imports them, and fs.deny outranks fs.allow and skips the public directory.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["fs.deny outranks fs.allow, and the public directory is not filtered by it.","Allow a parent folder with fs.allow instead of turning fs.strict off."]},{"id":"viteadvanced-004","courseId":"vite-advanced","domain":"dev-server-and-hmr","topic":"Workspace root default for fs.allow","prompt":"A project lives at packages/app inside a pnpm monorepo, and the monorepo root contains pnpm-workspace.yaml. The Vite config does not set server.fs.allow. Which directory is the default allowed root?","hint":"Look at what sits above the project and which marker files it declares.","explain":"Whether a project belongs to a larger repository decides the default access scope. Vite checks the folders above the project for a declared workspace marker, and uses the project folder when none turns up.","source":"https://vite.dev/config/server-options","interaction":{"type":"single"},"options":[{"id":"a","text":"The monorepo root that holds pnpm-workspace.yaml, found by searching up from the project","why":"Vite searches upward for a valid workspace root and uses it when fs.allow is unset, and pnpm-workspace.yaml counts as a marker."},{"id":"b","text":"The packages/app project folder, because the default is always the project root.","whyNot":"The project root is only the fallback, used when no valid workspace root is found above it."},{"id":"c","text":"The filesystem root, so every path on the machine is readable by default.","whyNot":"Vite does not open the whole disk; it stops at a workspace root or at the project root."},{"id":"d","text":"The first folder above the project that has a package.json, whichever it is.","whyNot":"A plain package.json is not enough; a workspace root needs a workspaces field, lerna.json, or pnpm-workspace.yaml."}],"answer":"a","explanation":"When server.fs.allow is unset, Vite searches upward for a workspace root marked by a workspaces field, lerna.json or pnpm-workspace.yaml, and falls back to the project root.","concept":"When server.fs.allow is unset, Vite searches upward for a workspace root marked by a workspaces field, lerna.json or pnpm-workspace.yaml, and falls back to the project root.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Setting server.fs.allow turns off the automatic workspace search.","searchForWorkspaceRoot lets you keep that search and add your own paths."]},{"id":"viteadvanced-005","courseId":"vite-advanced","domain":"dev-server-and-hmr","topic":"Middleware mode server","prompt":"You mount Vite inside your own Node http server using middleware mode. The Vite config also proxies WebSocket traffic on /ws to another service. What should middlewareMode be set to?","hint":"Think about which object receives the upgrade request when a connection switches to WebSocket.","explain":"Middleware mode lets Vite run inside a server you already own. A WebSocket proxy has to attach to the server that receives the upgrade requests, so the setting must reference that server.","source":"https://vite.dev/guide/api-javascript","interaction":{"type":"single"},"options":[{"id":"a","text":"{ server: parentServer }, where parentServer is your existing http server","why":"Passing your parent http server lets the WebSocket proxy bind to the server that receives the upgrades."},{"id":"b","text":"true, which is enough once a proxy is configured","whyNot":"A plain true enables middleware mode but does not give the proxy the server it needs to bind to."},{"id":"c","text":"{ server: { port: 3000 } }, so Vite listens on that port itself","whyNot":"The server option takes an http.Server object, not a port number, and middleware mode does not open a listener of its own."},{"id":"d","text":"A second Vite server on another port, passed in as the middleware","whyNot":"Running a second server does not bind the proxy; the parent http server is what must be passed."}],"answer":"a","explanation":"In middleware mode, a WebSocket proxy needs the parent http server passed as middlewareMode.server, so the proxy binds to the server that receives the upgrade requests.","concept":"In middleware mode, a WebSocket proxy needs the parent http server passed as middlewareMode.server, so the proxy binds to the server that receives the upgrade requests.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Pass your parent http server to middlewareMode when you proxy WebSockets.","appType controls HTML and 404 handling; it is separate from WebSocket binding."]}]