question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Addon docs: Example configuration with Vue using SFC and TypeScript

See original GitHub issue

I have working configuration with Vue in TypeScript and SB5.2. I’d like use the new docs addon, but after half a day of trial and error with its configuration, it seems Vue isn’t really supported yet.

Vue development is most often done in Single File Components, using Vue’s default imports alias ‘@’ to ‘src’ folder, and with TypeScript now that Vue version 3 on approach…

First of all, I could not get the SCSS preset to work as vue-style-loader is not used there. Also sass-loader needs to configured with importing SCSS variables for SFC’s style blocks.

Request: Working example of SB Vue configured with SB 5.2 and docs addon, using Vue’s Single File Components written in TypeScript, and with SCSS variables preloading.

Also as a SB Vue user I should not be needing React as a dep, but I understand you have been on a schedule to get the docs addon out for React first.

Here is my working webpack.config.js for *.stories.ts files that are using Vue components:

const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const path = require('path')
const rootPath = path.resolve(__dirname, '../src')

// https://github.com/storybookjs/storybook/issues/6467

// https://github.com/storybookjs/storybook/issues/2792
module.exports = ({ config }) => {
  config.resolve.alias['@'] = rootPath;
  config.resolve.alias['~'] = rootPath;

  config.module.rules.push({
    test: /\.scss$/,
      use: [
        'vue-style-loader',
	'css-loader',
	{
	  loader: 'sass-loader',
	  options: {
	    data: '@import "@/assets/styles/abstracts/_variables.scss";'
	  }
        }
     ]
  });

  config.resolve.extensions.push(
    '.ts',
    '.vue',
    '.css',
    '.scss',
    '.html'
  );

  config.module.rules.push({
    test: /\.ts$/,
    exclude: /node_modules/,
    use: [
      {
        loader: 'ts-loader',
        options: {
          appendTsSuffixTo: [/\.vue$/],
          transpileOnly: true
        }
      }
    ]
  });

  config.plugins.push(new ForkTsCheckerWebpackPlugin());

  return config;
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
Aaron-Poolcommented, Oct 17, 2019

@envision Your wish is my command (Working Example)

My process:

  1. Init a typescript project with Vue-Cli (v4, which was just released)
  2. Add Vue Cli Storybook Plugin
  3. Disable Vue Jsx in the babel config (Vue Jsx is temporarily incompatible with addon-docs):
// babel.config.js
module.exports = {
  presets: [["@vue/cli-plugin-babel/preset", {
    jsx: false
  }]]
};
4reactions
ux-engineercommented, Nov 20, 2019

Forgot to post here earlier but got the setup working with your configurations, thanks a lot again Aaron 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use TypeScript with Vue Single File Components
In this tutorial, you will use @vue/cli to generate a new Vue.js 2.0 application with TypeScript and build a Single-File Component (SFC).
Read more >
Tooling - Vue.js
This command will install and execute create-vue, the official Vue project scaffolding tool. To learn more about Vite, check out the Vite docs....
Read more >
@vue/cli-plugin-typescript | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
vue-docgen-api - Vue Styleguidist
Every parser in docgen-api returns an instance of ComponentDoc or a ComponentDoc[] . ... When using SFC components, one can use `<docs>` blocks....
Read more >
vuelize - npm Package Health Analysis - Snyk
This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 `<script setup>` SFCs, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found