vite#PluginOption TypeScript Examples
The following examples show how to use
vite#PluginOption.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From vite-react-ts with MIT License | 6 votes |
export function createVitePlugins(viteEnv: string, isBuild: boolean) {
const vitePlugins: (PluginOption | PluginOption[])[] = [
// have to
react(),
];
// @vitejs/plugin-legacy
VITE_APP_LEGACY && isBuild && vitePlugins.push(legacy());
// vite-plugin-mock
VITE_APP_MOCK && vitePlugins.push(configMockPlugin(isBuild));
// vite-plugin-style-import
// vitePlugins.push(configStyleImportPlugin(isBuild));
// rollup-plugin-visualizer
VITE_APP_ANALYZE && vitePlugins.push(configVisualizerPlugin());
//vite-plugin-theme
// vitePlugins.push(configThemePlugin(isBuild));
// The following plugins only work in the production environment
if (isBuild) {
// rollup-plugin-gzip
VITE_APP_COMPRESS_GZIP &&
vitePlugins.push(
viteCompression({ deleteOriginFile: VITE_APP_COMPRESS_GZIP_DELETE_FILE }),
);
}
return vitePlugins;
}
Example #2
Source File: index.ts From vite-plugin-md-preview with MIT License | 5 votes |
export function MarkdownVuePreview(options: MarkdownVuePreviewOptions = {}): PluginOption[] {
const { highlighter, shiki: shikiOptions } = options
const plugin: Plugin = {
name: 'vite:md-vue',
enforce: 'pre',
async configResolved(config) {
const shiki = await getHighlighter({
theme: 'github-light',
langs: ['vue'],
...shikiOptions,
})
transformOptions.highlighter =
highlighter ||
((code: string) => {
return shiki.codeToHtml(code, { lang: 'vue' })
})
transformOptions.root = config.root
// vuePlugin = resolvedConfig.plugins.find((p) => p.name === 'vite:vue');
},
resolveId(id) {
if (VUE_CODE_REGEXP.test(id)) {
return `${id}`
}
},
load(id) {
if (VUE_CODE_REGEXP.test(id)) {
const code = vueBlockMap.get(id)
return code
}
},
async handleHotUpdate(ctx) {
const { file, server } = ctx
const { moduleGraph, ws } = server
if (/\.md$/.test(file)) {
const updates: Update[] = []
for (const [name] of vueBlockMap) {
const mods = [...(moduleGraph.getModulesByFile(name) || new Set())]
moduleGraph.onFileChange(name)
// console.log(mods);
for (const mod of mods) {
updates.push({
type: `js-update`,
timestamp: mod.lastInvalidationTimestamp,
path: `${mod.url}`,
acceptedPath: `${mod.url}`,
})
}
}
ws.send({
type: 'update',
updates,
})
}
},
}
return [plugin]
}
Example #3
Source File: main.ts From frontend with BSD 3-Clause "New" or "Revised" License | 5 votes |
config: StorybookConfig & { viteFinal: (viteConfig: UserConfig) => Promise<UserConfig> } = {
stories: [
'../components/**/*.stories.mdx',
'../components/**/*.stories.@(js|jsx|ts|tsx)',
'../../icons/index.stories.tsx'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials'
],
framework: '@storybook/react',
viteFinal: async (viteConfig) => {
// workaround for vite build
// Refs: https://github.com/eirslett/storybook-builder-vite/issues/55#issuecomment-871800293
viteConfig.root = dirname(require.resolve('storybook-builder-vite'))
/*
* About auto-generated component docs:
* Please use FC<Props> instead of React.FC<Props> to declare component.
* https://github.com/styleguidist/react-docgen-typescript/issues/323
* https://github.com/styleguidist/react-docgen-typescript/issues/393
* */
!viteConfig.plugins && (viteConfig.plugins = [])
viteConfig.plugins.push(reactDocgenTypescript())
/* WIP: Temporary patch for style */
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
viteConfig.plugins.push({
transform (source, id) {
if (id.endsWith('.stories.tsx') && id.includes('components')) {
return `${source}
import './style'`
}
return source
}
} as PluginOption)
viteConfig.plugins.push(svgr())
return viteConfig
},
core: {
builder: 'storybook-builder-vite'
}
}