Skip to content

Commit 4451a53

Browse files
committed
Document changing the manifest name
1 parent 4e10784 commit 4451a53

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

src/recipes/web-extension.md

+37-10
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ First, install `@parcel/config-webextension` into your project:
1717
yarn add @parcel/config-webextension --dev
1818
```
1919

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.
2221

2322
{% sample %}
2423
{% samplefile "manifest.json" %}
@@ -32,10 +31,12 @@ Next, you'll need a [manifest.json](https://developer.mozilla.org/en-US/docs/Moz
3231
"service_worker": "background.ts",
3332
"type": "module"
3433
},
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+
]
3940
}
4041
```
4142

@@ -48,6 +49,12 @@ To build your extension, run Parcel using your `manifest.json` as an entry, and
4849
parcel build manifest.json --config @parcel/config-webextension
4950
```
5051

52+
{% warning %}
53+
54+
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+
5158
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.
5259

5360
{% sample %}
@@ -62,6 +69,26 @@ You can also create a `.parcelrc` file in your project extending `@parcel/config
6269
{% endsamplefile %}
6370
{% endsample %}
6471

72+
To make Parcel treat some other file as a manifest apart from `manifest.json`, add a few more lines to the `.parcelrc`:
73+
74+
{% sample %}
75+
{% samplefile ".parcelrc" %}
76+
77+
```json
78+
{
79+
"extends": "@parcel/config-webextension",
80+
"transformers": {
81+
"some-other-manifest.json": ["@parcel/transformer-webextension"]
82+
},
83+
"packagers": {
84+
"some-other-manifest.json": "@parcel/packager-webextension"
85+
}
86+
}
87+
```
88+
89+
{% endsamplefile %}
90+
{% endsample %}
91+
6592
## HMR
6693

6794
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
97124

98125
### Styling
99126

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.
101128

102129
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.
103130

@@ -123,16 +150,16 @@ Additionally, content script CSS resolves links to the site they are injected in
123150
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.
124151

125152
### `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:
127153

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:
128155

129156
{% sample %}
130157
{% samplefile "content-script.js" %}
131158

132159
```js
133-
import myImage from 'url:./image.png';
160+
import myImage from "url:./image.png";
134161

135-
const injectedImage = document.createElement('img');
162+
const injectedImage = document.createElement("img");
136163
injectedImage.src = myImage;
137164
document.body.appendChild(injectedImage);
138165
```

0 commit comments

Comments
 (0)