Skip to content

Commit

Permalink
feat: additionalInputs plugin option (#88)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The webAccessibleScripts option has been removed and replaced by the additionalInputs option. For similar functionality, move scripts to additionalInputs.scripts and html files to additionalInputs.html. Check the README for detailed usage instructions.

* refactor!: rename useDynamicUrlContentScripts option to useDynamicUrlWebAccessibleResources
  • Loading branch information
samrum authored Apr 9, 2023
1 parent 49db181 commit cd9590e
Show file tree
Hide file tree
Showing 119 changed files with 3,721 additions and 1,664 deletions.
2 changes: 2 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
## Version 3.x.x to 4.0.0

- Dev mode HTML transforms are no longer applied by default. Enable via the new devHtmlTransform option if still needed.
- The useDynamicUrlContentScripts option has been renamed to useDynamicUrlWebAccessibleResources
- The webAccessibleScripts option has been removed and replaced by the additionalInputs option. For similar functionality, move scripts to additionalInputs.scripts and html files to additionalInputs.html. Check the README for detailed usage instructions.

## Version 2.x.x to 3.0.0

Expand Down
87 changes: 73 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ export default defineConfig({
There are two configurations an extension needs to make for experimental manifest V3 support:

1. Background service workers are not supported, so you are required to use a background script.
2. The `use_dynamic_url` property is not supported for web accessible resources. In the plugin options, set `useDynamicUrlContentScripts` to false:
2. The `use_dynamic_url` property is not supported for web accessible resources. In the plugin options, set `useDynamicUrlWebAccessibleResources` to false:

```js
webExtension({
...
useDynamicUrlContentScripts: false,
useDynamicUrlWebAccessibleResources: false,
}),
```

Expand Down Expand Up @@ -161,25 +161,84 @@ manifest
- The [manifest](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) definition for your extension
- All manifest property file names should be relative to the root of the project.

useDynamicUrlContentScripts: boolean (optional)
useDynamicUrlWebAccessibleResources (optional)

- Adds the `use_dynamic_url` property to web accessible resources generated by the plugin
- Type: `boolean`
- Default: `true`
- Adds the `use_dynamic_url` property to web accessible resources generated by the plugin

devHtmlTransform: boolean (optional)
devHtmlTransform (optional)

- In dev mode, apply Vite plugins to manifest HTML files by calling transformIndexHtml on them
- Type: `boolean`
- Default: `false`
- In dev mode, apply Vite plugins to manifest HTML files by calling transformIndexHtml on them

webAccessibleScripts: [rollup filter](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) (optional)
additionalInputs (optional)

- Type:

```ts
type AdditionalInput =
| string
| {
fileName: string;
webAccessible?:
| boolean
| {
matches: string[];
extensionIds?: string[];
excludeEntryFile?: boolean;
}
| {
matches?: string[];
extensionIds: string[];
excludeEntryFile?: boolean;
};
};
additionalInputs?: {
scripts?: AdditionalInput[];
html?: AdditionalInput[];
styles?: AdditionalInput[];
};
```

- A filter that will be applied to `web_accessible_resources` entries in the provided manifest. When the filter matches a resource, it will be parsed by the plugin and treated as a content script. This can be useful to generate content scripts that will be manually injected at runtime.
- Default:
```js
{
include: /\.([cem]?js|ts)$/,
exclude: "",
}
- Additional input files that should be processed and treated as web extension inputs.
- Useful for dynamically injected scripts or dynamically opened HTML pages.
- The webAccessible option configures whether the input file and its dependencies are included in the manifest `web_accessible_resources` property. Defaults to true.
- When set to `true`, defaults to:
```ts
{
matches: ['<all_urls>'],
excludeEntryFile: false,
}
```
- The `excludeEntryFile` option prevents the entry file from being added as a web accessible resource. Defaults to false.
- Example
```ts
webExtension({
manifest: ...,
additionalInputs: {
scripts: [
'src/entries/webAccessibleScript.js', // defaults to webAccessible: true
{
fileName: 'src/entries/webAccessibleScript2.js',
webAccessible: true,
},
{
fileName: 'src/entries/privateScript.js', // entry file and dependencies are not web accessible
webAccessible: false,
},
{
fileName: 'src/entries/entryFileExcluded.js', // entry file is not web accessible and dependencies are
webAccessible: {
matches: ['<all_urls>'],
excludeEntryFile: true,
},
},
],
},
})
```

### Content Scripts
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"lint-staged": "^13.1.0",
"prettier": "2.4.1",
"rollup": "^3.9.0",
"sass": "^1.60.0",
"standard-version": "^9.5.0",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
Expand All @@ -76,7 +77,7 @@
]
},
"dependencies": {
"@types/chrome": "^0.0.206",
"@types/chrome": "^0.0.227",
"@types/etag": "^1.8.1",
"content-security-policy-parser": "^0.4.1",
"etag": "^1.8.1",
Expand Down
Loading

0 comments on commit cd9590e

Please sign in to comment.