Last active
November 17, 2021 16:07
-
-
Save exreplay/04487c693d7f4589c4514343705061d8 to your computer and use it in GitHub Desktop.
nuxt3 generate eslint globals
This file contains hidden or 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
// eslint-disable-next-line @typescript-eslint/no-var-requires | |
const globals = require('.nuxt/eslint-globals'); | |
// @ts-check | |
/** @type {import('eslint').Linter.Config} */ | |
module.exports = { | |
...globals, | |
//... other rules | |
}; |
This file contains hidden or 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
import { defineNuxtModule } from '@nuxt/kit'; | |
import fs from 'fs'; | |
import path from 'path'; | |
export default defineNuxtModule({ | |
name: 'eslint-globals', | |
configKey: 'eslint-globals', | |
setup(_, nuxt) { | |
nuxt.hook('autoImports:extend', (autoImports) => { | |
const eslintFile = ` | |
module.exports = { | |
globals: { | |
${autoImports.map((a) => `${a.as}: 'readonly'`).join(',\n\t\t')} | |
} | |
} | |
`.trim(); | |
fs.writeFileSync( | |
path.resolve(nuxt.options.rootDir, './.nuxt/eslint-globals.js'), | |
eslintFile, | |
'utf-8' | |
); | |
}); | |
} | |
}); |
This file contains hidden or 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
import { defineNuxtConfig } from 'nuxt3'; | |
export default defineNuxtConfig({ | |
buildModules: [ | |
'./modules/eslint-globals.ts' | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment