-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document changing the webextension manifest name #1052
Open
mischnic
wants to merge
3
commits into
v2
Choose a base branch
from
webext-name
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,7 @@ First, install `@parcel/config-webextension` into your project: | |
yarn add @parcel/config-webextension --dev | ||
``` | ||
|
||
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. | ||
|
||
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. | ||
|
||
{% sample %} | ||
{% samplefile "manifest.json" %} | ||
|
@@ -32,10 +31,12 @@ Next, you'll need a [manifest.json](https://developer.mozilla.org/en-US/docs/Moz | |
"service_worker": "background.ts", | ||
"type": "module" | ||
}, | ||
"content_scripts": [{ | ||
"matches": ["*://github.com/parcel-bundler/*"], | ||
"js": ["parcel-content-script.ts"] | ||
}] | ||
"content_scripts": [ | ||
{ | ||
"matches": ["*://github.com/parcel-bundler/*"], | ||
"js": ["parcel-content-script.ts"] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
|
@@ -48,6 +49,12 @@ To build your extension, run Parcel using your `manifest.json` as an entry, and | |
parcel build manifest.json --config @parcel/config-webextension | ||
``` | ||
|
||
{% warning %} | ||
|
||
With the default Web Extension config, the manifest has to be called `manifest.json` (and cannot be just any file with a `json` extension). | ||
|
||
{% endwarning %} | ||
|
||
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. | ||
|
||
{% sample %} | ||
|
@@ -62,6 +69,26 @@ You can also create a `.parcelrc` file in your project extending `@parcel/config | |
{% endsamplefile %} | ||
{% endsample %} | ||
|
||
To make Parcel treat some other file as a manifest apart from `manifest.json`, add a few more lines to the `.parcelrc`: | ||
|
||
{% sample %} | ||
{% samplefile ".parcelrc" %} | ||
|
||
```json | ||
{ | ||
"extends": "@parcel/config-webextension", | ||
"transformers": { | ||
"some-other-manifest.json": ["@parcel/transformer-webextension"] | ||
}, | ||
"packagers": { | ||
"some-other-manifest.json": "@parcel/packager-webextension" | ||
} | ||
} | ||
``` | ||
|
||
{% endsamplefile %} | ||
{% endsample %} | ||
Comment on lines
+72
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the other change, everything else was caused by Prettier for some reason. |
||
|
||
## HMR | ||
|
||
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 | |
|
||
### Styling | ||
|
||
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. | ||
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. | ||
|
||
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. | ||
|
||
|
@@ -123,16 +150,16 @@ Additionally, content script CSS resolves links to the site they are injected in | |
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. | ||
|
||
### `web_accessible_resources` | ||
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: | ||
|
||
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: | ||
|
||
{% sample %} | ||
{% samplefile "content-script.js" %} | ||
|
||
```js | ||
import myImage from 'url:./image.png'; | ||
import myImage from "url:./image.png"; | ||
|
||
const injectedImage = document.createElement('img'); | ||
const injectedImage = document.createElement("img"); | ||
injectedImage.src = myImage; | ||
document.body.appendChild(injectedImage); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first actual change.