Skip to content

Instantly share code, notes, and snippets.

@exreplay
Last active November 17, 2021 16:07
Show Gist options
  • Save exreplay/04487c693d7f4589c4514343705061d8 to your computer and use it in GitHub Desktop.
Save exreplay/04487c693d7f4589c4514343705061d8 to your computer and use it in GitHub Desktop.
nuxt3 generate eslint globals
// 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
};
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'
);
});
}
});
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