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
Copy file name to clipboardexpand all lines: src/recipes/web-extension.md
+37-10
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,7 @@ First, install `@parcel/config-webextension` into your project:
17
17
yarn add @parcel/config-webextension --dev
18
18
```
19
19
20
-
Next, you'll need a [manifest.json](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file, which will be the entry point of your extension. See [this guide](https://developer.chrome.com/docs/extensions/mv3/getstarted/) for details on how to set it up. Both Manifest V2 and V3 are supported. You can use [TypeScript](</languages/typescript>), [Vue](</languages/vue>), and any other languages supported by Parcel within your web extension code.
21
-
20
+
Next, you'll need a [manifest.json](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file, which will be the entry point of your extension. See [this guide](https://developer.chrome.com/docs/extensions/mv3/getstarted/) for details on how to set it up. Both Manifest V2 and V3 are supported. You can use [TypeScript](/languages/typescript), [Vue](/languages/vue), and any other languages supported by Parcel within your web extension code.
22
21
23
22
{% sample %}
24
23
{% samplefile "manifest.json" %}
@@ -32,10 +31,12 @@ Next, you'll need a [manifest.json](https://developer.mozilla.org/en-US/docs/Moz
32
31
"service_worker": "background.ts",
33
32
"type": "module"
34
33
},
35
-
"content_scripts": [{
36
-
"matches": ["*://github.com/parcel-bundler/*"],
37
-
"js": ["parcel-content-script.ts"]
38
-
}]
34
+
"content_scripts": [
35
+
{
36
+
"matches": ["*://github.com/parcel-bundler/*"],
37
+
"js": ["parcel-content-script.ts"]
38
+
}
39
+
]
39
40
}
40
41
```
41
42
@@ -48,6 +49,12 @@ To build your extension, run Parcel using your `manifest.json` as an entry, and
With the default Web Extension config, the manifest has to be called `manifest.json` (and cannot be just any file with a `json` extension).
55
+
56
+
{% endwarning %}
57
+
51
58
You can also create a `.parcelrc` file in your project extending `@parcel/config-webextension`. This way you don't need to pass the `--config` option to the Parcel CLI every time.
52
59
53
60
{% sample %}
@@ -62,6 +69,26 @@ You can also create a `.parcelrc` file in your project extending `@parcel/config
62
69
{% endsamplefile %}
63
70
{% endsample %}
64
71
72
+
To make Parcel treat some other file as a manifest apart from `manifest.json`, add a few more lines to the `.parcelrc`:
Due to [restrictions on Content Security Policy](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy) in MV3, HMR is not supported, but updating your code will cause the extension to reload. For MV2, HMR is fully supported by default. Reloading pages with content scripts will reload the extension in both versions.
@@ -97,7 +124,7 @@ In development mode, your background scripts will receive a message event with t
97
124
98
125
### Styling
99
126
100
-
Any styles imported in a content script will be injected into the `css` property of that content script and will thus apply to the entire page. Usually this is what you want, but if not you can always use [CSS modules](</languages/css#css-modules>) to prevent the styles from applying to the original site.
127
+
Any styles imported in a content script will be injected into the `css` property of that content script and will thus apply to the entire page. Usually this is what you want, but if not you can always use [CSS modules](/languages/css#css-modules) to prevent the styles from applying to the original site.
101
128
102
129
Additionally, content script CSS resolves links to the site they are injected into, so you won't be able to reference local assets. You should [inline your bundles](</languages/css#url()>) to resolve this issue.
103
130
@@ -123,16 +150,16 @@ Additionally, content script CSS resolves links to the site they are injected in
123
150
Lastly, hot reload may not work when adding or removing CSS linked from inside an `import()` in content scripts, while synchronous `import` has no such issues. This is a known limitation and will be fixed in a future version.
124
151
125
152
### `web_accessible_resources`
126
-
Any resources you use in a content script will automatically be added into `web_accessible_resources`, so you don't usually need to specify anything in `web_accessible_resources` at all. For example, the following content script will work without issues:
127
153
154
+
Any resources you use in a content script will automatically be added into `web_accessible_resources`, so you don't usually need to specify anything in `web_accessible_resources` at all. For example, the following content script will work without issues:
0 commit comments