A webpack loader for treeshaking and auto importing Vue components.
- Based on and heavily inspired by vuetify-loader and @nuxt/components
- Works for every Vue project using webpack, no vuetify or nuxt needed!
- Scans and auto-imports components, no more
components: {}
! - May make your bundle smaller compared to global
Vue.registerComponent()
!
Create your components:
components/
ComponentFoo.vue
ComponentBar.vue
Use them whenever you want, they will be auto imported in .vue files :
<template>
<ComponentFoo />
<component-bar />
</template>
No need anymore to manually import them in the script section! The component name gets infered from the filename.
Add the plugin to your webpack.config.js
and configure where your Vue components can be found:
// webpack.config.js
const VueComponentsLoaderPlugin = require("vue-components-loader");
module.exports = {
...
plugins: [
new VueComponentsLoaderPlugin({
paths: ["./components/**/*.vue"]
})
],
...
};
- Type:
Array<String>
orPath
object (see below)
List of directories to scan, with customizable options when using Object syntax.
String items are shortcut to Object with only path provided :
"./src/**/*.vue" === { path: "./src/**/*.vue" };
- Type:
String
- Required
Path glob to your components. Must follow the node-glob pattern style.
- Type:
String
orArray<String>
Ignore glob patterns.
- Type:
String
Prefix component names.