Skip to content

Commit 883460d

Browse files
authored
docs: Clearify the browser startup guide (#110)
1 parent a16c96a commit 883460d

10 files changed

+157
-125
lines changed

docs/config/plugin-options.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
22
lang: en-US
3-
title: Plugin Options
3+
title: Plugin Configuration Options
44
---
55

6-
# Plugin Options
7-
8-
These options are available when adding the plugin in your `vite.config.ts`
6+
# Plugin Configuration Options
97

108
```ts
119
import { defineConfig } from "vite";
@@ -26,15 +24,15 @@ export default defineConfig({
2624
additionalInputs?: string[]
2725
```
2826

29-
A list of paths relative to Vite's root directory that should be built along with the inputs listed in your manifest.
27+
An array of paths relative to Vite's root directory that should be built along with the inputs listed in your manifest.
3028

31-
Usually, this is additional HTML files that aren't listed in your manifest, but still want to show, like an onboarding page. It also accepts stylesheets (CSS, SCSS, Stylus, etc) and scripts (JS or TS), essentially everything that Vite knows how to build.
29+
This generally involves additional HTML files not listed in your manifest but which you still want to display, such as an onboarding page. It also accepts stylesheets (CSS, SCSS, Stylus, etc.) and scripts (JS or TS) - basically, anything that Vite can build.
3230

33-
Depending on the type of file listed, it will be built at different times:
31+
Depending on the type of file provided, it will be built at different stages:
3432

35-
- HTML files are built in the same step along side the other HTML files listed in the manifest.
36-
- JS files are bundled individually in the order listed.
37-
- CSS files are also bundled individually in the order listed.
33+
- HTML files are built in the same step alongside the other HTML files listed in the manifest.
34+
- JS files are bundled individually in the order specified.
35+
- CSS files are also bundled individually in the order given.
3836

3937
## `browser`
4038

@@ -46,30 +44,30 @@ browser?: string
4644
const browser = "{{browser}}"
4745
</script>
4846

49-
When using <code>{{browser}}.</code> prefixes in your manifest template, setting this field will cause only the matching tags to be in the `<outDir>/manifest.json`.
47+
When using <code>{{browser}}.</code> prefixes in your manifest template, defining this field ensures that only matching tags are included in the `<outDir>/manifest.json`.
5048

51-
See [Supporting Multiple Browsers](/guide/supporting-multiple-browsers) to learn more about how to use the `browser` option in combination with manifest templates.
49+
Refer to [Multibrowser Support](/guide/supporting-multiple-browsers) for more details on how to use this option with manifest templates.
5250

5351
## `disableAutoLaunch`
5452

5553
```ts
5654
disableAutoLaunch?: boolean;
5755
```
5856

59-
Setting to `true` will prevent the browser from opening when starting the dev server or running the extension in watch mode.
57+
Setting this to `true` prevents the browser from launching when starting the development server or running the extension in watch mode.
6058

61-
This can be useful in setups where opening the browser is impossible, like in the WSL/WSL2. In this case, the linux shell can't communicate with the Window's browser, and it crashes. Setting `disableAutoLaunch: true` will trigger rebuild's when you save a file, and you can open an install the extension manually.
59+
This is useful in setups where opening the browser isn't possible, such as in WSL/WSL2. In these scenarios, the Linux shell can't communicate with the Windows browser, leading to crashes. Setting `disableAutoLaunch: true` will trigger rebuilds when you save a file, and you can manually open and install the extension.
6260

6361
## `htmlViteConfig`
6462

6563
```ts
6664
htmlViteConfig?: import('vite').InlineConfig
6765
```
6866

69-
You can provide additional Vite config to the HTML multipage build step by setting it here.
67+
You can supply additional Vite configuration to the HTML multipage build step here.
7068

7169
::: warning
72-
Use with caution, I have not tested the compatibility of every single Vite build option with the HTML build process. Submit an issue if you have any problems.
70+
Exercise caution with this option. Not every one of Vite's build options have been tested for compatibility. If something doesn't work for you, please open an issue.
7371
:::
7472

7573
## `manifest`
@@ -78,33 +76,34 @@ Use with caution, I have not tested the compatibility of every single Vite build
7876
manifest?: string | (() => any) | (() => Promise<any>)
7977
```
8078

81-
The manifest can either be:
79+
The manifest can be:
8280

83-
- The path relative to Vite's root directory to a file containing a manifest template
84-
- A function that returns the manifest template as a JSON object.
81+
- A path relative to Vite's root directory pointing to a file containing a manifest template.
82+
- An absolute path pointing to a file containing a manifest template.
83+
- A function returning the manifest template as a JSON object.
8584

86-
When not provided, it defaults to `"manifest.json"`, and the plugin looks for a template at `<viteRoot>/manifest.json`.
85+
When not provided, it defaults to `"manifest.json"`, and the plugin searches for a template at `<viteRoot>/manifest.json`.
8786

88-
See [Supporting Multiple Browsers](/guide/supporting-multiple-browsers) to learn more about how to use manifest templates.
87+
Refer to [Multibrowser Support](/guide/supporting-multiple-browsers) for more information on how to use manifest templates.
8988

9089
## `printSummary`
9190

9291
```ts
9392
printSummary?: boolean
9493
```
9594

96-
Defaults to `true`. When `true`, the plugin will print a summary of what files are being built in what order.
95+
Defaults to `true`. When set to `true`, the plugin will provide a summary of what files are being built and in what order.
9796

9897
## `scriptViteConfig`
9998

10099
```ts
101100
scriptViteConfig?: import('vite').InlineConfig
102101
```
103102

104-
You can provide additional Vite config to the individually bundled JS files by setting it here.
103+
You can provide additional Vite config to individually bundled JS files here.
105104

106105
::: warning
107-
Use with caution, I have not tested the compatibility of every single Vite build option with the HTML build process. Submit an issue if you have any problems.
106+
Exercise caution with this option. Not every one of Vite's build options have been tested for compatibility. If something doesn't work for you, please open an issue.
108107
:::
109108

110109
## `skipManifestValidation`
@@ -113,30 +112,26 @@ Use with caution, I have not tested the compatibility of every single Vite build
113112
skipManifestValidation?: boolean
114113
```
115114

116-
By default, the `<outDir>/manifest.json` will be validated against Google's JSON schema: <https://json.schemastore.org/chrome-manifest>.
115+
By default, the `<outDir>/manifest.json` undergoes validation against Google's JSON schema at <https://json.schemastore.org/chrome-manifest>.
117116

118-
Setting this to `true` will skip validation.
117+
Setting this to `true` skips the validation step.
119118

120-
> The validation process downloads the schema from the above URL. If you are working offline, this step will be skipped automatically.
119+
> The validation process downloads the schema from the given URL. If you are working offline, this step will automatically be skipped.
121120
122121
## `watchFilePaths`
123122

124123
```ts
125124
watchFilePaths?: string[]
126125
```
127126

128-
A list of paths relative to Vite's root directory that cause a full rebuild of the extension during development. When one of these files is saved, the browser will be shut down, manifest regenerated, and the browser will open again.
127+
An array of paths relative to Vite's root directory that triggers a complete rebuild of the extension during development. When one of these files is saved, the browser will be closed, the manifest regenerated, and the browser will relaunch.
129128

130-
If the `manifest` field was a string, it will be added to this list automatically. If the `manifest` field is a function, you should add any files that are used to generate the manifest (like `package.json`).
129+
If the [`manifest` field](#manifest) was a string, it will be automatically added to this list. If the [`manifest` field](#manifest) is a function, you should add any files used to generate the manifest (like package.json).
131130

132131
## `webExtConfig`
133132

134133
```ts
135134
webExtConfig?: any
136135
```
137136

138-
Configure the startup behavior of the browser.
139-
140-
See [`web-ext`'s source code](https://github.com/mozilla/web-ext/blob/666886f40a967b515d43cf38fc9aec67ad744d89/src/program.js#L559) for possible options.
141-
142-
See [Configure Browser Startup](/guide/configure-browser-startup.md) for alteratives and more details on how this field is used.
137+
This option allows you to pass configuration into `web-ext` when launching the browser. For more details, refer to [Browser Startup Configuration](/guide/configure-browser-startup.md).

docs/guide/building-for-production.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
---
22
lang: en-US
3-
title: Building for Production
3+
title: Generating a Production Build
44
---
55

6-
# Building for Production
6+
# Generating a Production Build
77

8-
## Overview
8+
## Introduction
99

10-
Like with a regular Vite project, just run the build command:
10+
Creating a production build with Vite is as straightforward as running the build command, just like you would with a standard Vite project:
1111

1212
```bash
1313
vite build
1414
```
1515

16-
Then look in your `dist/` directory. You should find a fully functioning browser extension! You can load it into Chrome or Firefox as an unpacked extension.
16+
After running the above command, go to your `dist/` directory. There, you'll find a fully functional web extension! You can proceed to load this extension into Chrome or Firefox as an unpacked extension for testing.
1717

18-
## Zipping
18+
## Uploading to a Store
1919

20-
To publish your extension to the store, you simply need to zip up the files inside your output directory. You can do this manually, or use a package like [`zip-a-folder`](https://www.npmjs.com/package/zip-a-folder) to automate it.
20+
When you're ready to publish your extension to the store, you'll need to zip up the files contained in your output directory. This can be done manually or automated with a package such as [`zip-a-folder`](https://www.npmjs.com/package/zip-a-folder).
2121

22-
```ts
23-
import { zip } from "zip-a-folder";
24-
25-
await zip("dist", "extension.zip");
26-
```
22+
> The following is an example of how to use `zip-a-folder`:
23+
>
24+
> ```ts
25+
> import { zip } from "zip-a-folder";
26+
>
27+
> await zip("dist", "extension.zip");
28+
> ```
29+
>
30+
> This script will zip the contents of the `dist` directory and save it as `extension.zip`.
Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
22
lang: en-US
3-
title: Configure Browser Startup
3+
title: Browser Startup Configuration
44
---
55

6-
# Configure Browser Startup
6+
# Browser Startup Configuration
77

8-
Internally, `vite-plugin-web-extension` uses [`web-ext`](https://www.npmjs.com/package/web-ext) by Mozilla to open the browser and install the extension during development. It can open any Chromium-based browser (Chrome, Edge, etc) and Firefox.
8+
## Overview
99

10-
You can configure it's startup behavior in two ways:
10+
Internally, `vite-plugin-web-extension` uses the JS API provided by [`web-ext`](https://www.npmjs.com/package/web-ext) to launch the browser and install the extension during development. It's capable of opening any Chromium-based browser (such as Chrome or Edge) and Firefox.
1111

12-
1. Pass [`webExtConfig`](/config/plugin-options#webextconfig) option into the plugin
13-
2. Use config files
12+
There are two approaches to configure browser startup:
1413

15-
## Pass `webExtConfig`
14+
1. Using the [`webExtConfig`](/config/plugin-options#webextconfig) option within the plugin
15+
2. Creating config files
1616

17-
This is a good option if you're OK with checking the config into version control (since you will have to list the config in `vite.config.ts`), or if you need to set something based on a runtime value, like an environment variable.
17+
## The `webExtConfig` Option
18+
19+
This method is ideal for config that needs to be committed to version control (as it will be defined in `vite.config.ts`), or if a configuration based on a runtime value, like an environment variable, is required.
1820

1921
```ts
2022
import { defineConfig } from "vite";
@@ -25,18 +27,18 @@ export default defineConfig({
2527
webExtension({
2628
// ...
2729
webExtConfig: {
28-
startUrl: ["https://google.com"],
30+
startUrl: process.env.START_URL.split(","),
2931
},
3032
}),
3133
],
3234
});
3335
```
3436

35-
## Use Config Files
37+
## Config Files
3638

37-
The plugin will automatically discover config files on your filesystem. Below are the paths that the plugin will look for config files at. When multiple files are found, they are merged into a single config.
39+
The plugin will automatically discover config files on your filesystem. The plugin searches for config files at the paths listed below. When multiple files are found, they are merged into a single configuration.
3840

39-
The higher priority files (top of this list) are will override fields set by the lower priority files (bottom of the list).
41+
Higher priority files (top of the list) will override fields set by lower priority files (bottom of the list).
4042

4143
1. `webExtConfig` option
4244
1. `<viteRoot>/.webextrc`
@@ -46,9 +48,9 @@ The higher priority files (top of this list) are will override fields set by the
4648
1. `~/.webextrc`
4749
1. `~/.webextrc.(json|json5|yml|yaml)`
4850

49-
> Array fields are overwritten, not combined in any way.
51+
> Array fields are overwritten, they are not combined.
5052
51-
Here's an example: You prefer to use Chrome Beta and Firefox Developer Edition, so you want one of those to open during development. You can create a `.webextrc` file in your home directory, and any project that uses `vite-plugin-web-extension` will know to use those versions instead of the default versions!
53+
Here's an example: Suppose you prefer to use Chrome Beta and Firefox Developer Edition, and you want one of these to open during development. You can create a `.webextrc` file in your home directory, and any project using `vite-plugin-web-extension` will use those versions instead of the default ones!
5254

5355
```json
5456
// ~/.webextrc
@@ -57,3 +59,23 @@ Here's an example: You prefer to use Chrome Beta and Firefox Developer Edition,
5759
"firefox": "firefoxdeveloperedition"
5860
}
5961
```
62+
63+
## Available Options
64+
65+
Refer to Mozilla's [`web-ext run` CLI reference](https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#web-ext-run) for a complete list of available options.
66+
67+
Just convert each `--kebab-case` flag to `camelCase` and include them in your configuration.
68+
69+
For instance, if you want to use Microsoft Edge, use the default user profile, customize the starting URLs, and alter the initial window size, your config file would look like:
70+
71+
<!-- prettier-ignore -->
72+
```yml
73+
# ./.webextrc.yml
74+
chromiumBinary: /absolute/path/to/edge # from --chromium-binary
75+
chromiumProfile: /absolute/path/to/edge/profile # from --chromium-profile
76+
startUrl: # from --start-url
77+
- https://google.com
78+
- https://duckduckgo.com
79+
args: # from --args
80+
- --window-size=400x300
81+
```

docs/guide/development.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
11
---
22
lang: en-US
3-
title: Development
3+
title: Development Cycle
44
---
55

6-
# Development Cycle
6+
# Understanding the Development Cycle
77

8-
You have two ways to run the extension during development:
8+
While developing your browser extension, there are two ways to run it:
99

10-
- Dev Mode
10+
- Development Mode
1111
- Watch Mode
1212

13-
Both will automatically open a browser window and install the extension automatically.
13+
Both methods will automatically open a new browser window and install the extension for you.
1414

1515
::: info
16-
Dev mode is recommended because it will let you iterate faster as your project grows in size.
16+
For most use cases, Development Mode is recommended as it can significantly speed up the development process, especially as your project scales.
1717
:::
1818

19-
## Dev Mode
19+
## Development Mode
20+
21+
To start the extension in development mode, run the following command:
2022

2123
```sh
2224
vite dev
2325
```
2426

25-
Just run Vite like you would a normal project. This will spin up the dev server, and you'll have HMR for all the HTML pages in your extension!
27+
This command starts the Vite development server, similar to how you would for any other Vite project. Notably, you will have Hot Module Replacement (HMR) enabled for all HTML pages in your extension!
2628

27-
Unfortunately, content scripts do not work with HMR. Instead, they are built using watch mode, see below. When you save a file used by a content script, it will cause the entire extension to reload once the file has finished building.
29+
However, please note that content scripts do not support HMR. They are built using [Watch Mode](#watch-mode), see below. Thus, when you modify and save a file associated with a content script, it will trigger a full reload of the extension once the file has finished building.
2830

2931
::: warning HMR requires Chrome v110 or above
30-
31-
Make sure your browser is up to date, or it won't work. Chrome v110 was released Feb 13, 2023.
32+
Ensure your browser is up to date. HMR functionality is only supported in Chrome v110 or later versions, which was released on February 13, 2023.
3233
:::
3334

3435
## Watch Mode
3536

37+
To start the extension in watch mode, run the following command:
38+
3639
```sh
3740
vite build --watch --mode development
3841
```
3942

40-
Rather than starting the dev server, using Vite's `--watch` flag will cause it to rebuild the extension when a file is saved.
43+
Instead of launching the development server, using the `--watch` flag with Vite will instruct it to rebuild the extension each time you save a file.
4144

42-
If you can't use dev mode, watch mode will be easier than installing and reloading the extension by hand. Be aware that, as an extension grows larger, watch mode can get very slow since it's doing a full production build with minimal caching.
45+
If [Development Mode](#development-mode) does not work for you, Watch Mode can be a convenient alternative. However, be aware that as an extension grows in complexity, Watch Mode may become significantly slower as it completes a full production build with minimal caching, after each change.

0 commit comments

Comments
 (0)