PebbleRoad / cobblestone

Modern static site generator
4 stars 0 forks source link

Vue components are available globally without registering in Storybook #26

Closed AaronKow closed 5 years ago

kyleoliveiro commented 5 years ago

It has been set up this way for convenience:

.storybook/config.js:

///
// Dynamically register all Vue components from `src/components/`
///
const requireComponent = require.context("../src/components", true, /\.vue$/);
requireComponent.keys().forEach(filePath => {
  // Get component filename
  const fileName = `./${filePath.split("/").pop()}`;

  // Get component config
  const componentConfig = requireComponent(filePath);

  // Get PascalCase name of component
  const componentName = upperFirst(
    camelCase(
      // Strip the leading `./` and extension from the filename
      fileName.replace(/^\.\/(.*)\.\w+$/, "$1")
    )
  );

  // Register component globally
  Vue.component(
    componentName,
    // Look for the component options on `.default`, which will
    // exist if the component was exported with `export default`,
    // otherwise fall back to module's root.
    componentConfig.default || componentConfig
  );
});

Is there a reason to change this? @AaronKow

AaronKow commented 5 years ago

Nope, this is nice and convenient. Thanks.