
Product
Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.
nuxt-auto-import
Advanced tools
A module for automatically connecting prepared files found in the project and processing their data. Everything happens thanks to the connector files specified in the configuration.
This module works with Nuxt 3 only
Install the module:
npm install nuxt-auto-import
export default defineNuxtConfig({
modules: ["nuxt-auto-import"],
autoImport: {
// options
}
})
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| configStateKey | string | false | 'autoImportModule:config' | [In case of conflict]: assigns a key for storing connector data |
| connectors | string[] | true | The path to the connector relative to any nuxt.config |
export default defineConnector(config).export default defineNuxtConfig({
modules: ["nuxt-auto-import"],
autoImport: {
connectors: [
'./connectors/directives.ts'
]
}
})
You can use any imports and types in the connector file, they will be transferred to any define that concerns this connector.
type ModuleConnector = {
/* The viewed paths from which define will be loaded
* It supports both reading individual files and folders with multiple nesting
* */
watchedPaths: string[];
/* A function for generating generalized data */
dataBuilder: (files: ModuleFSReturnSuccess[]) => any;
/* A function for generating a generalized type */
typeContent: (data: any) => string | WriterFunction;
/* The trigger function that will be executed at the time of mounting the application
* Default: () => {}
* */
onAppCreating?: (vueApp: App<Element>, define: ModuleFSReturnSuccess) => void;
/* A function for generating a generalized type
* Default: {{file name}}
* */
name?: string;
/* Enables reading of subfolders
* Default: false
* */
deep?: boolean;
/* Adds the prefix of the folder name to the file name, with the deep option
* Default: true
* */
pathPrefix?: boolean;
/* Specifies the name of the type that contains the controller for typing defines
* Default: 'Define'
* */
defineConfigTypeName?: string;
/* Specifies whether to read index files in the directories being viewed by assigning them a folder name
* Default: false
* */
withRootIndexPrefix?: boolean;
};
// connectors/directives.ts
import type { Directive } from 'vue';
type Define = Directive<HTMLElement>;
export default defineConnector<Define>({
watchedPaths: [
'./directives'
],
dataBuilder(files): any {
/* All directives will be written to the object by their name
* and will be used in the client
* */
const resultObject: { [name: string]: any } = {};
files.forEach((file) => {
resultObject[file.name!.camelCase] = file.config!.data;
});
return resultObject;
},
typeContent(data): string {
/* All the names of the directives will be written to the type */
const resultObjectKeys = Object.keys(data);
return resultObjectKeys.length ? `\n | '${resultObjectKeys.join('\'\n | \'')}'` : ' {}';
},
onAppCreating(app, define) {
/* When mounting the application, the directives will be registered */
app.directive(define.name.camelCase, define.config.data);
},
name: 'directives',
deep: false,
pathPrefix: false,
defineConfigTypeName: 'Define',
withRootIndexPrefix: false
});
Created by the composable define connector:
P.s. Just an illustrative example of the final work of the connector, you do not need to create or edit this file.
import type { ModuleDefineConfig } from "../types";
import type { Directive } from "vue";
type Define = Directive<HTMLElement>;
export function defineDirectives(config: Define): ModuleDefineConfig {
return {
type: 'defineDirectives',
data: config,
dataBuilder(files) {
const resultObject = {};
files.forEach((file) => {
resultObject[file.name.camelCase] = file.config.data;
});
return resultObject;
},
onAppCreating(app, define) {
app.directive(define.name.camelCase, define.config.data);
}
};
}
Usage:
Define the function will be created in the format define{{connector.name }}.
// directives/outside.ts
export default defineDirectives({
mounted(el, binding) {
const mods = binding.modifiers;
const handler = (e: any) => {
if (!el.contains(e.target) && el !== e.target) {
binding.value(e);
}
};
(el as any).__ClickOutsideHandler__ = handler;
setTimeout(() => document.addEventListener('click', handler), mods.delay ? 50 : 0);
},
beforeUnmount(el) {
document.removeEventListener('click', (el as any).__ClickOutsideHandler__);
},
getSSRProps() {
return {};
}
});
defineDirectives has become a global function, which makes it easier to use, and the function also has a type set in Define, to facilitate configuration.
After launching the application, it became available to use v-outside more without any manipulation.
After initializing the connectors (npm run dev or nuxi prepare), global AutoImport{{connector.name}} format types will become available.
The Debug mode allows you to track in the server console which files have not been uploaded.
Just add AUTO_IMPORT_DEBUG=1 to your .env.
npm run dev:prepare to generate type stubs.npm run dev to start playground in development mode.Deploy the application on the Edge with NuxtHub on your Cloudflare account:
npm run deploy
Then checkout your server logs, analaytics and more in the NuxtHub Admin.
You can also deploy using Cloudflare Pages CI.
FAQs
Importing any data at the build stage into the client
We found that nuxt-auto-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.

Research
/Security News
A new npm package tests AI malware scanners with prompt injection, safety-triggering comments, context flooding, and obfuscated JavaScript.