You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These options are available when adding the plugin in your `vite.config.ts`
6
+
# Plugin Configuration Options
9
7
10
8
```ts
11
9
import { defineConfig } from"vite";
@@ -26,15 +24,15 @@ export default defineConfig({
26
24
additionalInputs?:string[]
27
25
```
28
26
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.
30
28
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.
32
30
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:
34
32
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.
38
36
39
37
## `browser`
40
38
@@ -46,30 +44,30 @@ browser?: string
46
44
constbrowser="{{browser}}"
47
45
</script>
48
46
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`.
50
48
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.
52
50
53
51
## `disableAutoLaunch`
54
52
55
53
```ts
56
54
disableAutoLaunch?:boolean;
57
55
```
58
56
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.
60
58
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.
62
60
63
61
## `htmlViteConfig`
64
62
65
63
```ts
66
64
htmlViteConfig?:import('vite').InlineConfig
67
65
```
68
66
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.
70
68
71
69
::: 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.
73
71
:::
74
72
75
73
## `manifest`
@@ -78,33 +76,34 @@ Use with caution, I have not tested the compatibility of every single Vite build
- 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.
85
84
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`.
87
86
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.
89
88
90
89
## `printSummary`
91
90
92
91
```ts
93
92
printSummary?:boolean
94
93
```
95
94
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.
97
96
98
97
## `scriptViteConfig`
99
98
100
99
```ts
101
100
scriptViteConfig?:import('vite').InlineConfig
102
101
```
103
102
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.
105
104
106
105
::: 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.
108
107
:::
109
108
110
109
## `skipManifestValidation`
@@ -113,30 +112,26 @@ Use with caution, I have not tested the compatibility of every single Vite build
113
112
skipManifestValidation?:boolean
114
113
```
115
114
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>.
117
116
118
-
Setting this to `true`will skip validation.
117
+
Setting this to `true`skips the validation step.
119
118
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.
121
120
122
121
## `watchFilePaths`
123
122
124
123
```ts
125
124
watchFilePaths?:string[]
126
125
```
127
126
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.
129
128
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).
131
130
132
131
## `webExtConfig`
133
132
134
133
```ts
135
134
webExtConfig?:any
136
135
```
137
136
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).
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:
11
11
12
12
```bash
13
13
vite build
14
14
```
15
15
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.
17
17
18
-
## Zipping
18
+
## Uploading to a Store
19
19
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).
21
21
22
-
```ts
23
-
import { zip } from"zip-a-folder";
24
-
25
-
awaitzip("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
+
>awaitzip("dist", "extension.zip");
28
+
>```
29
+
>
30
+
> This script will zip the contents of the `dist` directory and save it as `extension.zip`.
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
9
9
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.
11
11
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:
14
13
15
-
## Pass `webExtConfig`
14
+
1. Using the [`webExtConfig`](/config/plugin-options#webextconfig) option within the plugin
15
+
2. Creating config files
16
16
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.
18
20
19
21
```ts
20
22
import { defineConfig } from"vite";
@@ -25,18 +27,18 @@ export default defineConfig({
25
27
webExtension({
26
28
// ...
27
29
webExtConfig: {
28
-
startUrl: ["https://google.com"],
30
+
startUrl: process.env.START_URL.split(","),
29
31
},
30
32
}),
31
33
],
32
34
});
33
35
```
34
36
35
-
## Use Config Files
37
+
## Config Files
36
38
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.
38
40
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).
40
42
41
43
1.`webExtConfig` option
42
44
1.`<viteRoot>/.webextrc`
@@ -46,9 +48,9 @@ The higher priority files (top of this list) are will override fields set by the
46
48
1.`~/.webextrc`
47
49
1.`~/.webextrc.(json|json5|yml|yaml)`
48
50
49
-
> Array fields are overwritten, not combined in any way.
51
+
> Array fields are overwritten, they are not combined.
50
52
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!
52
54
53
55
```json
54
56
// ~/.webextrc
@@ -57,3 +59,23 @@ Here's an example: You prefer to use Chrome Beta and Firefox Developer Edition,
57
59
"firefox": "firefoxdeveloperedition"
58
60
}
59
61
```
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
You have two ways to run the extension during development:
8
+
While developing your browser extension, there are two ways to run it:
9
9
10
-
-Dev Mode
10
+
-Development Mode
11
11
- Watch Mode
12
12
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.
14
14
15
15
::: 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.
17
17
:::
18
18
19
-
## Dev Mode
19
+
## Development Mode
20
+
21
+
To start the extension in development mode, run the following command:
20
22
21
23
```sh
22
24
vite dev
23
25
```
24
26
25
-
Just run Vite like you would a normal project. This will spin up the dev server, and you'll have HMRfor 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!
26
28
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.
28
30
29
31
::: 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.
32
33
:::
33
34
34
35
## Watch Mode
35
36
37
+
To start the extension in watch mode, run the following command:
38
+
36
39
```sh
37
40
vite build --watch --mode development
38
41
```
39
42
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.
41
44
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