docs: Add eslintrc info to auto-imports page
This commit is contained in:
@@ -76,3 +76,27 @@ export default defineConfig({
|
||||
imports: false,
|
||||
});
|
||||
```
|
||||
|
||||
## ESLint
|
||||
|
||||
ESLint doesn't understand auto-imports; it thinks all auto-imported variables are undeclared globals and will report lint errors for each. To fix this, extend the ESLint file generated inside the `.wxt` directory:
|
||||
|
||||
```js
|
||||
// .eslintrc.js
|
||||
module.exports = {
|
||||
extends: ['./.wxt/eslintrc-auto-import.json'],
|
||||
};
|
||||
```
|
||||
|
||||
By default, this file will be generated when ESLint is a direct dependency. If ESLint is a subdependency or your project is a monorepo, it may not be generated automatically. In this case, you can tell WXT to generate it:
|
||||
|
||||
```ts
|
||||
// wxt.config.ts
|
||||
export default defineConfig({
|
||||
imports: {
|
||||
eslintrc: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -42,7 +42,7 @@ Lets go over a few approaches:
|
||||
(browser.action ?? browser.browserAction).setBadgeColor('red');
|
||||
```
|
||||
|
||||
2. **Check the browser**: WXT provides environment variables about which browser is being targetted.
|
||||
2. **Check the browser**: WXT provides environment variables about which browser is being targeted.
|
||||
```ts
|
||||
if (!import.meta.env.SAFARI) {
|
||||
// Safari doesn't implement `onStartup` correctly, so we need a custom solution
|
||||
@@ -51,7 +51,7 @@ Lets go over a few approaches:
|
||||
browser.runtime.onStartup.addListener(...)
|
||||
}
|
||||
```
|
||||
3. **Check the manifest version**: WXT provides environment variables about which manifest version is being targetted.
|
||||
3. **Check the manifest version**: WXT provides environment variables about which manifest version is being targeted.
|
||||
```ts
|
||||
if (import.meta.env.MANIFEST_VERSION === 3) {
|
||||
// MV3 only code...
|
||||
|
||||
@@ -1203,7 +1203,11 @@ export interface ResolvedEslintrc {
|
||||
|
||||
export type WxtUnimportOptions = Partial<UnimportOptions> & {
|
||||
/**
|
||||
* When eslint is installed,
|
||||
* When using ESLint, auto-imported variables are linted as "undeclared
|
||||
* globals". This option lets you configure a base eslintrc that, when
|
||||
* extended, fixes these lint errors.
|
||||
*
|
||||
* See <https://wxt.dev/guide/key-concepts/auto-imports.html#eslint>
|
||||
*/
|
||||
eslintrc?: Eslintrc;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user