Skip to content

Commit

Permalink
Merge pull request #1 from ConstantinRoss/develop
Browse files Browse the repository at this point in the history
v.0.0.4
  • Loading branch information
c0nst4ntin authored Sep 21, 2019
2 parents f105186 + cd8314c commit 81f153b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A Vue.js plugin to globally import all vue components

## Requirements
1. A Vue or Nuxt installation
2. Lodash as Node dependency

## Installation

### 1) Install the package using Node
Expand All @@ -12,22 +12,16 @@ A Vue.js plugin to globally import all vue components
$ npm i --save vue-component-importer
```

If you don't have Lodash installed yet, also run:
```shell
$ npm i --save lodash
```

### 2a) With Vue
In your `src/main.js` file also import lodash and the vue-component-importer
In your `src/main.js` file also import the vue-component-importer
```js
import lodash from 'lodash'
import importComponents from 'vue-component-importer'
```

Before the creation of your Vue instance add the following code:
```js
let components = require.context('@/components', true, /[a-zA-Z]\w+\.(vue)$/)
importComponents(lodash, Vue, components)
importComponents(Vue, components)

```
The first parameter is the folder you want to import your components from. If you just want to include some components you can change the path to just use a subdirectory of components like `@/components/slices`
Expand All @@ -39,11 +33,10 @@ Do not list the components imported by the plugin in the `components: {} `field.
Create a `plugins/componentimporter.js` file and add the following code:
```js
import Vue from 'vue'
import lodash from 'lodash'
import importComponents from 'vue-component-importer'

let components = require.context('@/components', true, /[a-zA-Z]\w+\.(vue)$/)
importComponents(lodash, Vue, components)
importComponents(Vue, components)

```
The first parameter is the folder you want to import your components from. If you just want to include some components you can change the path to just use a subdirectory of components like `@/components/slices`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "vue-component-importer",
"version": "0.0.3",
"version": "0.0.4",
"description": "A Vue.js plugin to globally import all vue components",
"author": "Constantin Ross",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const importComponents = (_, Vue, components) => {
_.forEach(components.keys(), (fileName) => {
const importComponents = (Vue, components) => {
components.keys().forEach((fileName) => {
const componentConfig = components(fileName);
const componentName = fileName.split('/').pop().split('.')[0];
Vue.component(componentName, componentConfig.default || componentConfig);
Expand Down

0 comments on commit 81f153b

Please sign in to comment.