Skip to content

Commit 4c175f8

Browse files
committed
fix: vite doc formatting
1 parent 421672b commit 4c175f8

File tree

1 file changed

+75
-77
lines changed

1 file changed

+75
-77
lines changed

content/configuration/vite.md

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Make sure your `nativescript.config.ts` includes the following to use Vite as th
2626
```ts
2727
export default {
2828
// ...
29-
bundler: "vite",
30-
bundlerConfigPath: "vite.config.ts",
29+
bundler: 'vite',
30+
bundlerConfigPath: 'vite.config.ts',
3131
// ...
32-
};
32+
}
3333
```
3434

3535
### 2. Init the config
@@ -44,12 +44,12 @@ This will:
4444

4545
- Generate a `vite.config.ts` using the detected project flavor (Angular, Vue, React, Solid, TypeScript, or JavaScript) and the corresponding helper from `@nativescript/vite`.
4646
- Add (or update) the following npm scripts in your app `package.json`:
47-
- `dev:ios`
48-
- `dev:android`
49-
- `dev:server:ios`
50-
- `dev:server:android`
51-
- `ios`
52-
- `android`
47+
- `dev:ios`
48+
- `dev:android`
49+
- `dev:server:ios`
50+
- `dev:server:android`
51+
- `ios`
52+
- `android`
5353
- Add the devDependencies `concurrently` and `wait-on`.
5454
- Add the dependency `@valor/nativescript-websockets`.
5555
- Append `.ns-vite-build` to `.gitignore` if it is not already present.
@@ -76,70 +76,70 @@ The plugin comes with several framework integrations.
7676
### Vue
7777

7878
```ts
79-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
80-
import { vueConfig } from '@nativescript/vite';
79+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
80+
import { vueConfig } from '@nativescript/vite'
8181

8282
export default defineConfig(({ mode }): UserConfig => {
83-
return mergeConfig(vueConfig({ mode }), {});
84-
});
83+
return mergeConfig(vueConfig({ mode }), {})
84+
})
8585
```
8686

8787
### Angular
8888

8989
```ts
90-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
91-
import { angularConfig } from '@nativescript/vite';
90+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
91+
import { angularConfig } from '@nativescript/vite'
9292

9393
export default defineConfig(({ mode }): UserConfig => {
94-
return mergeConfig(angularConfig({ mode }), {});
95-
});
94+
return mergeConfig(angularConfig({ mode }), {})
95+
})
9696
```
9797

9898
### Solid
9999

100100
```ts
101-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
102-
import { solidConfig } from '@nativescript/vite';
101+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
102+
import { solidConfig } from '@nativescript/vite'
103103

104104
export default defineConfig(({ mode }): UserConfig => {
105-
return mergeConfig(solidConfig({ mode }), {});
106-
});
105+
return mergeConfig(solidConfig({ mode }), {})
106+
})
107107
```
108108

109109
### Svelte
110110

111111
```ts
112-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
113-
import { solidConfig } from '@nativescript/vite';
112+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
113+
import { solidConfig } from '@nativescript/vite'
114114

115115
export default defineConfig(({ mode }): UserConfig => {
116-
return mergeConfig(solidConfig({ mode }), {});
117-
});
116+
return mergeConfig(solidConfig({ mode }), {})
117+
})
118118
```
119119

120120
### React
121121

122122
```ts
123-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
124-
import { reactConfig } from '@nativescript/vite';
123+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
124+
import { reactConfig } from '@nativescript/vite'
125125

126126
export default defineConfig(({ mode }): UserConfig => {
127-
return mergeConfig(reactConfig({ mode }), {});
128-
});
127+
return mergeConfig(reactConfig({ mode }), {})
128+
})
129129
```
130130

131131
### TypeScript (XML view)
132132

133133
```ts
134-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
135-
import { typescriptConfig } from '@nativescript/vite';
134+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
135+
import { typescriptConfig } from '@nativescript/vite'
136136

137137
export default defineConfig(({ mode }): UserConfig => {
138-
return mergeConfig(typescriptConfig({ mode }), {});
139-
});
138+
return mergeConfig(typescriptConfig({ mode }), {})
139+
})
140140
```
141141

142-
The above config configures most things required to bundle a NativeScript application.
142+
The above config configures most things required to bundle a NativeScript application.
143143

144144
This page contains examples of common things you might want to change in the [Examples of configurations section](#configuration-examples) - for anything else not mentioned here, refer to the [Vite documentation](https://vite.dev/config/).
145145

@@ -153,18 +153,18 @@ When using the HMR workflow (for example `npm run dev:ios` / `npm run dev:androi
153153
import {
154154
onHmrUpdate,
155155
offHmrUpdate,
156-
} from '@nativescript/vite/hmr/shared/runtime/hooks';
156+
} from '@nativescript/vite/hmr/shared/runtime/hooks'
157157

158158
// Use a stable id so the handler is replaced across hmr updates
159-
const id = 'my-app:name-of-module-or-feature';
159+
const id = 'my-app:name-of-module-or-feature'
160160

161161
onHmrUpdate(({ type, version, changedIds, raw }) => {
162162
// type: "full-graph" | "delta"
163163
// version: monotonically increasing batch id
164164
// changedIds: module ids affected in this batch
165165
// raw: original websocket message payload
166-
console.log('[HMR]', { type, version, changedIds });
167-
}, id);
166+
console.log('[HMR]', { type, version, changedIds })
167+
}, id)
168168

169169
// Optional: unregister when you no longer need it
170170
// offHmrUpdate(id);
@@ -181,37 +181,37 @@ Notes:
181181

182182
### Example: Persisting data across hmr updates
183183

184-
If you need a stable runtime reference across HMR (for example, a singleton that other modules hold onto), a common pattern is to store the data or instance on [import.meta.hot.data](https://vite.dev/guide/api-hmr#hot-data).
184+
If you need a stable runtime reference across HMR (for example, a singleton that other modules hold onto), a common pattern is to store the data or instance on [import.meta.hot.data](https://vite.dev/guide/api-hmr#hot-data).
185185

186186
You could also store it on `global` and update it on module re-evaluation by swapping its prototype. Let's explore this global approach with an example of a hypothetical `TabCustomizer` singleton that needs to reset some state on each HMR update.
187187

188188
```ts
189-
import { onHmrUpdate } from '@nativescript/vite/hmr/shared/runtime/hooks';
189+
import { onHmrUpdate } from '@nativescript/vite/hmr/shared/runtime/hooks'
190190

191191
class TabCustomizer {
192192
resetAccessory(payload?: any) {
193-
console.log('payload.changedIds:', payload?.changedIds);
193+
console.log('payload.changedIds:', payload?.changedIds)
194194
// ...your reset logic
195195
}
196196
}
197197

198198
// Keep a stable singleton for runtime references, but make it HMR-updatable by
199199
// swapping its prototype on module re-evaluation.
200-
const g = global as any;
201-
const existing = g.tabCustomizer as TabCustomizer | undefined;
200+
const g = global as any
201+
const existing = g.tabCustomizer as TabCustomizer | undefined
202202

203203
if (existing) {
204-
Object.setPrototypeOf(existing as any, TabCustomizer.prototype);
204+
Object.setPrototypeOf(existing as any, TabCustomizer.prototype)
205205
} else {
206-
g.tabCustomizer = new TabCustomizer();
206+
g.tabCustomizer = new TabCustomizer()
207207
}
208208

209-
export const tabCustomizer = g.tabCustomizer as TabCustomizer;
209+
export const tabCustomizer = g.tabCustomizer as TabCustomizer
210210

211211
onHmrUpdate((payload) => {
212212
// Prefer calling into the stable singleton so the handler remains valid.
213-
tabCustomizer.resetAccessory(payload);
214-
}, 'tab-customize');
213+
tabCustomizer.resetAccessory(payload)
214+
}, 'tab-customize')
215215
```
216216

217217
Tip: if you only care about specific updates, you can inspect `payload.changedIds` and return early when the batch doesn’t include the modules you care about.
@@ -285,24 +285,23 @@ Here are some common examples of things you may want to do in your `vite.config.
285285
### Adding a copy rule
286286

287287
```ts
288-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
289-
import { typescriptConfig } from '@nativescript/vite';
290-
import path from 'path';
291-
import { viteStaticCopy } from 'vite-plugin-static-copy';
288+
import { defineConfig, mergeConfig, UserConfig } from 'vite'
289+
import { typescriptConfig } from '@nativescript/vite'
290+
import path from 'path'
291+
import { viteStaticCopy } from 'vite-plugin-static-copy'
292292

293293
export default defineConfig(({ mode }): UserConfig => {
294-
const base = typescriptConfig({ mode });
295-
const projectRoot = path.resolve(__dirname);
296-
const testImagePath = path.resolve(projectRoot, 'src/ui/image/700x50.png');
297-
return mergeConfig(base, {
298-
plugins: [
294+
const base = typescriptConfig({ mode })
295+
const projectRoot = path.resolve(__dirname)
296+
const testImagePath = path.resolve(projectRoot, 'src/ui/image/700x50.png')
297+
return mergeConfig(base, {
298+
plugins: [
299299
viteStaticCopy({
300-
targets: [{ src: testImagePath, dest: 'ui/image' }],
301-
})
300+
targets: [{ src: testImagePath, dest: 'ui/image' }],
301+
}),
302302
],
303-
});
304-
});
305-
303+
})
304+
})
306305
```
307306

308307
## Plugin API
@@ -312,35 +311,34 @@ NativeScript plugins can provide a `nativescript.vite.mjs` file in their root fo
312311
For example, a plugin could return custom processing:
313312

314313
```js
315-
import { createRequire } from "module";
316-
const require = createRequire(import.meta.url);
314+
import { createRequire } from 'module'
315+
const require = createRequire(import.meta.url)
317316

318-
let postcssConfig = "./postcss.config.js";
317+
let postcssConfig = './postcss.config.js'
319318

320319
try {
321-
const twV4 = require("@tailwindcss/postcss");
322-
const nsTailwind = require("@nativescript/tailwind");
323-
postcssConfig = { plugins: [twV4, nsTailwind] };
320+
const twV4 = require('@tailwindcss/postcss')
321+
const nsTailwind = require('@nativescript/tailwind')
322+
postcssConfig = { plugins: [twV4, nsTailwind] }
324323
} catch (e2) {
325324
console.warn(
326-
"Inline PostCSS unavailable, falling back to ./postcss.config.js"
327-
);
325+
'Inline PostCSS unavailable, falling back to ./postcss.config.js',
326+
)
328327
}
329328

330329
export default () => {
331330
return {
332331
css: {
333332
postcss: postcssConfig,
334333
},
335-
};
336-
};
334+
}
335+
}
337336
```
338337
339338
## Android Notes
340339
341340
Be sure to have a proper security policy in place using something as follows:
342341
343-
344342
1. `App_Resources/Android/src/main/res/xml/network_security.xml`
345343
346344
```xml
@@ -380,8 +378,8 @@ If you see your app is not building with Vite, ensure that your `nativescript.co
380378
```ts
381379
export default {
382380
// ...
383-
bundler: "vite",
384-
bundlerConfigPath: "vite.config.ts",
381+
bundler: 'vite',
382+
bundlerConfigPath: 'vite.config.ts',
385383
// ...
386-
};
387-
```
384+
}
385+
```

0 commit comments

Comments
 (0)