title: Try to create a plugin to auto load all components in nuxt.js
body: <p>I try to load and define globally all my components under nuxt.js.</p>
  
  <p>When I try to load the *.vue file, I get the following error: "Cannot find module ....".</p>
  
  <p>But the file is present in the specified location...</p>
  
  <p>Here is the loading plugin :</p>
  
  <pre><code>import Vue from 'vue'
  import fs from 'fs'
  import path from 'path'
  
  const componentDirectory = `.${path.sep}src${path.sep}components`;
  const componentTypes = ['atom','molecule','organism'];
  
  function getComponentType(componentName) {
  
      let compGroup = ( componentName || '' ).toLowerCase().split('.');
  
      if (compGroup.length &lt; 3 || compGroup[ compGroup.length - 1 ] !== 'vue' ) {
          return null;
      }
  
      return compGroup[ compGroup.length - 2 ];
  }
  
  function allowedComponentType(componentFileName) {
      return componentTypes.indexOf(getComponentType(componentFileName)) !== -1;
  }
  
  // List all files in a directory in Node.js recursively in a synchronous fashion
  var walkSync = function(dir, filelist) {
      var files = fs.readdirSync(dir);
      filelist = filelist || [];
  
      files.forEach(function (file) {        
          if (fs.statSync(dir + path.sep + file).isDirectory()) {
              filelist = walkSync(dir + path.sep + file, filelist);
          } else if (allowedComponentType(file) ) {
              filelist.push(dir + path.sep + file);
          }
      });
  
      return filelist;
  };
  
  walkSync(componentDirectory).forEach(componentFileName =&gt; {
      try {
          let componentPath = path.resolve(path.resolve(), componentFileName);
  
          console.log('Component name : ', componentPath)
          const component = require(componentPath).default;
          Vue.component(component.name, component);
      }
      catch (e) {
          console.log('Error : ' , e )
      }
  });
  
  </code></pre>
  
  <p>P.S .: I will replace functions by a regular expression once the problem is solved.</p>