unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.84k stars 352 forks source link

nuxt 3 component witdh storybook no components found #207

Open productdevbook opened 3 years ago

productdevbook commented 3 years ago

[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',
                },
            }
        }
    }
}
antfu commented 3 years ago

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

productdevbook commented 3 years ago

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 commented 3 years ago
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',
                },
            }
        }
    }
}
medairbit commented 2 years ago

@productdevbook did you find a workaround for this?

productdevbook commented 2 years ago

@productdevbook did you find a workaround for this?

No