unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

nuxt 3 component witdh storybook no components found

Open productdevbook opened this issue 2 years ago • 5 comments

[unplugin-vue-components] no components found

const path = require('path')
const Components = require('unplugin-vue-components/vite')
const AutoImport = require('unplugin-auto-import/vite')
const { loadConfigFromFile, mergeConfig } = require('vite')


module.exports = {
    stories: [
        '../stories/**/*.stories.mdx',
        '../stories/**/*.stories.ts',
        '../components/**/*.stories.ts',
    ],
    addons: [
        '@storybook/addon-links',
        '@storybook/addon-essentials',
        'storybook-dark-mode',
        {
            name: '@storybook/addon-postcss',
            options: {
                cssLoaderOptions: {
                    importLoaders: 1,
                },
                postcssLoaderOptions: {
                    implementation: require('postcss'),
                }
            }
        }
    ],
    core: {
        builder: 'storybook-builder-vite'
    },
    async viteFinal(config, { configType }) {
        config.plugins = config.plugins ?? []
        config.plugins.push(AutoImport({
            imports: [
                'vue',
                'vue-router',
            ],
            dts: '.nuxt/auto-imports.d.ts',
        }))
        config.plugins.push(Components({
            extensions: ['vue'],
            include: [/\.vue$/, /\.vue\?vue/],
            dts: '.nuxt/components.d.ts',
        }))
        return {
            ...config,
            resolve: {
                alias: {
                    '@': `${path.resolve(__dirname, '..')}/`,
                    '@/': `${path.resolve(__dirname, '..')}/`,
                    'vue': 'vue/dist/vue.esm-bundler.js',
                },
            }
        }
    }
}

productdevbook avatar Nov 09 '21 15:11 productdevbook

You'd better specify the dirs explicitly with absolute paths. Probably something relates to storybook's root integration

antfu avatar Nov 10 '21 05:11 antfu

dirs is problem fixed. Thank you. If nuxt reads the output components.d.ts file, it always creates itself. How do I do this?

productdevbook avatar Nov 13 '21 18:11 productdevbook

CleanShot 2021-11-14 at 21 18 01@2x

CleanShot 2021-11-14 at 21 18 23

const path = require('path')
const Components = require('unplugin-vue-components/vite')
const AutoImport = require('unplugin-auto-import/vite')
const { loadConfigFromFile, mergeConfig } = require('vite')



module.exports = {
    stories: [
        '../stories/**/*.stories.mdx',
        '../stories/**/*.stories.ts',
    ],
    addons: [
        '@storybook/addon-links',
        '@storybook/addon-essentials',
        'storybook-dark-mode',
        '@storybook/addon-a11y',
        {
            name: '@storybook/addon-postcss',
            options: {
                cssLoaderOptions: {
                    importLoaders: 1,
                },
                postcssLoaderOptions: {
                    implementation: require('postcss'),
                }
            }
        }
    ],
    framework: "@storybook/vue3",
    core: {
        builder: 'storybook-builder-vite'
    },
    async viteFinal(config, { configType }) {
        config.plugins = config.plugins ?? []
        config.plugins.push(AutoImport({
            imports: [
                'vue',
                'vue-router',
            ],
            dts: '.storybook/auto-imports.d.ts',
        }))
        config.plugins.push(Components({
            dirs: ['components'],
            directoryAsNamespace: true,
            dts: '.storybook/components.d.ts',
        }))
        return {
            ...config,
            resolve: {
                alias: {
                    ...config.resolve.alias,
                    '@': `${path.resolve(__dirname, '..')}/`,
                    'vue': 'vue/dist/vue.esm-bundler.js',
                },
            }
        }
    }
}

productdevbook avatar Nov 14 '21 18:11 productdevbook

@productdevbook did you find a workaround for this?

medairbit avatar Mar 10 '22 14:03 medairbit

@productdevbook did you find a workaround for this?

No

productdevbook avatar Mar 11 '22 06:03 productdevbook