87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
/*
|
|
* @Author: zhaojinfeng 121016171@qq.com
|
|
* @Date: 2023-06-15 13:22:59
|
|
* @LastEditors: zhaojinfeng 121016171@qq.com
|
|
* @LastEditTime: 2023-08-22 02:38:25
|
|
* @FilePath: \vue3\.storybook\main.ts
|
|
* @Description:
|
|
*/
|
|
import type { StorybookConfig } from '@storybook/vue3-vite'
|
|
import Unocss from 'unocss/vite'
|
|
import externalGlobals from 'rollup-plugin-external-globals'
|
|
import { createHtmlPlugin } from 'vite-plugin-html'
|
|
|
|
const externalGlobalsObj = {
|
|
'vue': 'Vue',
|
|
'vue-demi': 'VueDemi',
|
|
'vue-router': 'VueRouter',
|
|
'element-plus': 'ElementPlus',
|
|
// 'react': 'React',
|
|
// 'react-dom': 'ReactDom',
|
|
// 'VueOfficeDocx': 'vue-office-docx',
|
|
// 'VueOfficeExcel': 'vue-office-excel',
|
|
// 'VueOfficePdf': 'vue-office-pdf',
|
|
}
|
|
|
|
const cdn = {
|
|
css: [
|
|
'https://registry.npmmirror.com/element-plus/2.3.6/dist/index.css',
|
|
],
|
|
js: [
|
|
// 'https://registry.npmmirror.com/react/18.2.0/files/umd/react.production.min.js',
|
|
// 'https://registry.npmmirror.com/react-dom/18.2.0/files/umd/react-dom.production.min.js',
|
|
'https://registry.npmmirror.com/vue/3.2.47/files/dist/vue.global.prod.js',
|
|
'https://registry.npmmirror.com/vue-demi/0.14.0/files/lib/index.iife.js',
|
|
'https://registry.npmmirror.com/vue-router/4.1.6/files/dist/vue-router.global.js',
|
|
'https://registry.npmmirror.com/element-plus/2.3.6/files/dist/index.full.min.js',
|
|
],
|
|
}
|
|
|
|
const config: StorybookConfig = {
|
|
stories: ['../stories/*.stories.@(js|jsx|ts|tsx)'],
|
|
addons: [
|
|
'@storybook/addon-links',
|
|
'@storybook/addon-essentials',
|
|
'@storybook/addon-interactions',
|
|
],
|
|
framework: {
|
|
name: '@storybook/vue3-vite',
|
|
options: {},
|
|
},
|
|
docs: {
|
|
autodocs: 'tag',
|
|
defaultName: '文档',
|
|
},
|
|
viteFinal(config) {
|
|
const { build, plugins = [] } = config
|
|
plugins.push(Unocss())
|
|
if (!config.server) {
|
|
plugins.push(
|
|
{
|
|
...externalGlobals(externalGlobalsObj),
|
|
enforce: 'post',
|
|
apply: 'build',
|
|
},
|
|
createHtmlPlugin({
|
|
minify: true,
|
|
inject: {
|
|
tags: [
|
|
...cdn.css.map(href => ({ tag: 'link', attrs: { href } })),
|
|
...cdn.js.map(src => ({ tag: 'script', attrs: { src } })),
|
|
],
|
|
},
|
|
}),
|
|
)
|
|
if (Array.isArray(build.rollupOptions?.external))
|
|
build.rollupOptions.external.push(...Object.keys(externalGlobalsObj))
|
|
}
|
|
|
|
config.plugins = plugins
|
|
|
|
// Add other configuration here depending on your use case
|
|
return config
|
|
},
|
|
}
|
|
|
|
export default config
|