Skip to content

Commit a55e86b

Browse files
authored
docs: remove horizontal scrollbars in code blocks (vitejs#18567)
1 parent f0f6659 commit a55e86b

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

docs/config/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ import { defineConfig, loadEnv } from 'vite'
105105

106106
export default defineConfig(({ command, mode }) => {
107107
// Load env file based on `mode` in the current working directory.
108-
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
108+
// Set the third parameter to '' to load all env regardless of the
109+
// `VITE_` prefix.
109110
const env = loadEnv(mode, process.cwd(), '')
110111
return {
111112
// vite config

docs/config/server-options.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,21 @@ In some cases, you might also want to configure the underlying dev server (e.g.
101101
export default defineConfig({
102102
server: {
103103
proxy: {
104-
// string shorthand: http://localhost:5173/foo -> http://localhost:4567/foo
104+
// string shorthand:
105+
// http://localhost:5173/foo
106+
// -> http://localhost:4567/foo
105107
'/foo': 'http://localhost:4567',
106-
// with options: http://localhost:5173/api/bar-> http://jsonplaceholder.typicode.com/bar
108+
// with options:
109+
// http://localhost:5173/api/bar
110+
// -> http://jsonplaceholder.typicode.com/bar
107111
'/api': {
108112
target: 'http://jsonplaceholder.typicode.com',
109113
changeOrigin: true,
110114
rewrite: (path) => path.replace(/^\/api/, ''),
111115
},
112-
// with RegExp: http://localhost:5173/fallback/ -> http://jsonplaceholder.typicode.com/
116+
// with RegExp:
117+
// http://localhost:5173/fallback/
118+
// -> http://jsonplaceholder.typicode.com/
113119
'^/fallback/.*': {
114120
target: 'http://jsonplaceholder.typicode.com',
115121
changeOrigin: true,
@@ -123,8 +129,11 @@ export default defineConfig({
123129
// proxy will be an instance of 'http-proxy'
124130
},
125131
},
126-
// Proxying websockets or socket.io: ws://localhost:5173/socket.io -> ws://localhost:5174/socket.io
127-
// Exercise caution using `rewriteWsOrigin` as it can leave the proxying open to CSRF attacks.
132+
// Proxying websockets or socket.io:
133+
// ws://localhost:5173/socket.io
134+
// -> ws://localhost:5174/socket.io
135+
// Exercise caution using `rewriteWsOrigin` as it can leave the
136+
// proxying open to CSRF attacks.
128137
'/socket.io': {
129138
target: 'ws://localhost:5174',
130139
ws: true,
@@ -251,15 +260,16 @@ async function createServer() {
251260
// Create Vite server in middleware mode
252261
const vite = await createViteServer({
253262
server: { middlewareMode: true },
254-
appType: 'custom', // don't include Vite's default HTML handling middlewares
263+
// don't include Vite's default HTML handling middlewares
264+
appType: 'custom',
255265
})
256266
// Use vite's connect instance as middleware
257267
app.use(vite.middlewares)
258268

259269
app.use('*', async (req, res) => {
260270
// Since `appType` is `'custom'`, should serve response here.
261-
// Note: if `appType` is `'spa'` or `'mpa'`, Vite includes middlewares to handle
262-
// HTML requests and 404s so user middlewares should be added
271+
// Note: if `appType` is `'spa'` or `'mpa'`, Vite includes middlewares
272+
// to handle HTML requests and 404s so user middlewares should be added
263273
// before Vite's middlewares to take effect instead
264274
})
265275
}

docs/guide/api-environment-frameworks.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class RunnableDevEnvironment extends DevEnvironment {
2222

2323
class ModuleRunner {
2424
/**
25-
* URL to execute. Accepts file path, server path, or id relative to the root.
25+
* URL to execute.
26+
* Accepts file path, server path, or id relative to the root.
2627
* Returns an instantiated module (same as in ssrLoadModule)
2728
*/
2829
public async import(url: string): Promise<Record<string, any>>
@@ -52,20 +53,21 @@ const server = await createServer({
5253
appType: 'custom',
5354
environments: {
5455
server: {
55-
// by default, the modules are run in the same process as the vite dev server during dev
56+
// by default, modules are run in the same process as the vite server
5657
},
5758
},
5859
})
5960

60-
// You might need to cast this to RunnableDevEnvironment in TypeScript or use
61-
// the "isRunnableDevEnvironment" function to guard the access to the runner
61+
// You might need to cast this to RunnableDevEnvironment in TypeScript or
62+
// use isRunnableDevEnvironment to guard the access to the runner
6263
const environment = server.environments.node
6364

6465
app.use('*', async (req, res, next) => {
6566
const url = req.originalUrl
6667

6768
// 1. Read index.html
68-
let template = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf-8')
69+
const indexHtmlPath = path.resolve(__dirname, 'index.html')
70+
let template = fs.readFileSync(indexHtmlPath, 'utf-8')
6971

7072
// 2. Apply Vite HTML transforms. This injects the Vite HMR client,
7173
// and also applies HTML transforms from Vite plugins, e.g. global
@@ -112,7 +114,7 @@ const server = createServer()
112114
const ssrEnvironment = server.environment.ssr
113115
const input = {}
114116

115-
const { createHandler } = await ssrEnvironment.runner.import('./entrypoint.js')
117+
const { createHandler } = await ssrEnvironment.runner.import('./entry.js')
116118
const handler = createHandler(input)
117119
const response = handler(new Request('/'))
118120

@@ -186,10 +188,10 @@ function vitePluginVirtualIndexHtml(): Plugin {
186188
let html: string
187189
if (server) {
188190
this.addWatchFile('index.html')
189-
html = await fs.promises.readFile('index.html', 'utf-8')
191+
html = fs.readFileSync('index.html', 'utf-8')
190192
html = await server.transformIndexHtml('/', html)
191193
} else {
192-
html = await fs.promises.readFile('dist/client/index.html', 'utf-8')
194+
html = fs.readFileSync('dist/client/index.html', 'utf-8')
193195
}
194196
return `export default ${JSON.stringify(html)}`
195197
}

docs/guide/api-environment-instances.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class DevEnvironment {
7474

7575
/**
7676
* Register a request to be processed with low priority. This is useful
77-
* to avoid waterfalls. The Vite server has information about the imported
78-
* modules by other requests, so it can warmup the module graph so the
79-
* modules are already processed when they are requested.
77+
* to avoid waterfalls. The Vite server has information about the
78+
* imported modules by other requests, so it can warmup the module graph
79+
* so the modules are already processed when they are requested.
8080
*/
8181
async warmupRequest(url: string): void
8282
}

docs/guide/api-environment-plugins.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ const UnoCssPlugin = () => {
135135
// shared global state
136136
return {
137137
buildStart() {
138-
// init per environment state with WeakMap<Environment,Data>, this.environment
138+
// init per environment state with WeakMap<Environment,Data>
139+
// using this.environment
139140
},
140141
configureServer() {
141142
// use global hooks normally
142143
},
143144
applyToEnvironment(environment) {
144145
// return true if this plugin should be active in this environment
145-
// if the function isn't provided, the plugin is active in all environments
146+
// if the hook is not used, the plugin is active in all environments
146147
},
147148
resolveId(id, importer) {
148149
// only called for environments this plugin apply to

docs/guide/api-environment-runtimes.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ One of the goals of this feature is to provide a customizable API to process and
8484
```ts
8585
import { DevEnvironment, RemoteEnvironmentTransport } from 'vite'
8686

87-
function createWorkerdDevEnvironment(name: string, config: ResolvedConfig, context: DevEnvironmentContext) {
87+
function createWorkerdDevEnvironment(
88+
name: string,
89+
config: ResolvedConfig,
90+
context: DevEnvironmentContext
91+
) {
8892
const hot = /* ... */
8993
const connection = /* ... */
9094
const transport = new RemoteEnvironmentTransport({
@@ -120,20 +124,21 @@ export class ModuleRunner {
120124
private debug?: ModuleRunnerDebugger,
121125
) {}
122126
/**
123-
* URL to execute. Accepts file path, server path, or id relative to the root.
127+
* URL to execute.
128+
* Accepts file path, server path, or id relative to the root.
124129
*/
125130
public async import<T = any>(url: string): Promise<T>
126131
/**
127132
* Clear all caches including HMR listeners.
128133
*/
129134
public clearCache(): void
130135
/**
131-
* Clears all caches, removes all HMR listeners, and resets source map support.
136+
* Clear all caches, remove all HMR listeners, reset sourcemap support.
132137
* This method doesn't stop the HMR connection.
133138
*/
134139
public async close(): Promise<void>
135140
/**
136-
* Returns `true` if the runner has been closed by calling `close()` method.
141+
* Returns `true` if the runner has been closed by calling `close()`.
137142
*/
138143
public isClosed(): boolean
139144
}
@@ -174,9 +179,12 @@ export interface ModuleRunnerOptions {
174179
*/
175180
transport: RunnerTransport
176181
/**
177-
* Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
178-
* Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
179-
* You can provide an object to configure how file contents and source maps are resolved for files that were not processed by Vite.
182+
* Configure how source maps are resolved.
183+
* Prefers `node` if `process.setSourceMapsEnabled` is available.
184+
* Otherwise it will use `prepareStackTrace` by default which overrides
185+
* `Error.prepareStackTrace` method.
186+
* You can provide an object to configure how file contents and
187+
* source maps are resolved for files that were not processed by Vite.
180188
*/
181189
sourcemapInterceptor?:
182190
| false
@@ -190,7 +198,7 @@ export interface ModuleRunnerOptions {
190198
| false
191199
| {
192200
/**
193-
* Configure how HMR communicates between the client and the server.
201+
* Configure how HMR communicates between client and server.
194202
*/
195203
connection: ModuleRunnerHMRConnection
196204
/**
@@ -199,7 +207,8 @@ export interface ModuleRunnerOptions {
199207
logger?: false | HMRLogger
200208
}
201209
/**
202-
* Custom module cache. If not provided, it creates a separate module cache for each module runner instance.
210+
* Custom module cache. If not provided, it creates a separate module
211+
* cache for each module runner instance.
203212
*/
204213
evaluatedModules?: EvaluatedModules
205214
}
@@ -344,7 +353,8 @@ export interface ModuleRunnerHMRConnection {
344353
send(payload: HotPayload): void
345354
/**
346355
* Configure how HMR is handled when this connection triggers an update.
347-
* This method expects that the connection will start listening for HMR updates and call this callback when it's received.
356+
* This method expects that the connection will start listening for HMR
357+
* updates and call this callback when it's received.
348358
*/
349359
onUpdate(callback: (payload: HotPayload) => void): void
350360
}

docs/guide/build.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ experimental: {
337337
if (type === 'public') {
338338
return 'https://www.domain.com/' + filename
339339
} else if (path.extname(hostId) === '.js') {
340-
return { runtime: `window.__assetsPath(${JSON.stringify(filename)})` }
340+
return {
341+
runtime: `window.__assetsPath(${JSON.stringify(filename)})`
342+
}
341343
} else {
342344
return 'https://cdn.domain.com/assets/' + filename
343345
}

0 commit comments

Comments
 (0)