Created
June 21, 2022 15:29
-
-
Save sujit-baniya/759104dbbd9fa76d20a042108bad0f78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import {defineConfig, splitVendorChunkPlugin} from 'vite' | |
import Vue from '@vitejs/plugin-vue' | |
import Pages from 'vite-plugin-pages' | |
import Layouts from 'vite-plugin-vue-layouts' | |
import Icons from 'unplugin-icons/vite' | |
import IconsResolver from 'unplugin-icons/resolver' | |
import Components from 'unplugin-vue-components/vite' | |
import AutoImport from 'unplugin-auto-import/vite' | |
import Markdown from 'vite-plugin-md' | |
import WindiCSS from 'vite-plugin-windicss' | |
import { VitePWA } from 'vite-plugin-pwa' | |
import VueI18n from '@intlify/vite-plugin-vue-i18n' | |
import Inspect from 'vite-plugin-inspect' | |
import Prism from 'markdown-it-prism' | |
import LinkAttributes from 'markdown-it-link-attributes' | |
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'; | |
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'; | |
import rollupNodePolyFill from 'rollup-plugin-node-polyfills' | |
import OptimizationPersist from 'vite-plugin-optimize-persist' | |
import PkgConfig from 'vite-plugin-package-config' | |
const markdownWrapperClasses = 'prose prose-sm m-auto text-left' | |
export default defineConfig({ | |
define: { | |
'process.env': {} | |
}, | |
build: { | |
rollupOptions: { | |
plugins: [ | |
rollupNodePolyFill() | |
] | |
} | |
}, | |
base: '', | |
resolve: { | |
alias: { | |
'~/': `${path.resolve(__dirname, 'src')}/`, | |
// This Rollup aliases are extracted from @esbuild-plugins/node-modules-polyfill, | |
// see https://github.com/remorses/esbuild-plugins/blob/master/node-modules-polyfill/src/polyfills.ts | |
// process and buffer are excluded because already managed | |
// by node-globals-polyfill | |
util: 'rollup-plugin-node-polyfills/polyfills/util', | |
sys: 'util', | |
events: 'rollup-plugin-node-polyfills/polyfills/events', | |
stream: 'stream-browserify', | |
path: 'rollup-plugin-node-polyfills/polyfills/path', | |
querystring: 'rollup-plugin-node-polyfills/polyfills/qs', | |
punycode: 'rollup-plugin-node-polyfills/polyfills/punycode', | |
url: 'rollup-plugin-node-polyfills/polyfills/url', | |
http: 'rollup-plugin-node-polyfills/polyfills/http', | |
https: 'rollup-plugin-node-polyfills/polyfills/http', | |
os: 'rollup-plugin-node-polyfills/polyfills/os', | |
assert: 'rollup-plugin-node-polyfills/polyfills/assert', | |
constants: 'rollup-plugin-node-polyfills/polyfills/constants', | |
_stream_duplex: | |
'rollup-plugin-node-polyfills/polyfills/readable-stream/duplex', | |
_stream_passthrough: | |
'rollup-plugin-node-polyfills/polyfills/readable-stream/passthrough', | |
_stream_readable: | |
'rollup-plugin-node-polyfills/polyfills/readable-stream/readable', | |
_stream_writable: | |
'rollup-plugin-node-polyfills/polyfills/readable-stream/writable', | |
_stream_transform: | |
'rollup-plugin-node-polyfills/polyfills/readable-stream/transform', | |
timers: 'rollup-plugin-node-polyfills/polyfills/timers', | |
console: 'rollup-plugin-node-polyfills/polyfills/console', | |
vm: 'rollup-plugin-node-polyfills/polyfills/vm', | |
zlib: 'rollup-plugin-node-polyfills/polyfills/zlib', | |
tty: 'rollup-plugin-node-polyfills/polyfills/tty', | |
domain: 'rollup-plugin-node-polyfills/polyfills/domain' | |
}, | |
}, | |
plugins: [ | |
splitVendorChunkPlugin(), | |
PkgConfig(), | |
OptimizationPersist(), | |
Vue({ | |
include: [/\.vue$/, /\.md$/], | |
reactivityTransform: true, | |
}), | |
// https://github.com/hannoeru/vite-plugin-pages | |
Pages({ | |
dirs: [ | |
{ dir: 'src/pages', baseRoute: '' }, | |
], | |
extensions: ['vue', 'md'], | |
importMode() { | |
// Load about page synchronously, all other pages are async. | |
return 'async' | |
}, | |
}), | |
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts | |
Layouts(), | |
// https://github.com/antfu/unplugin-auto-import | |
AutoImport({ | |
imports: [ | |
'vue', | |
'vue-router', | |
'vue-i18n', | |
'@vueuse/head', | |
'@vueuse/core', | |
], | |
dts: 'src/auto-imports.d.ts', | |
}), | |
// https://github.com/antfu/unplugin-vue-components | |
Components({ | |
// allow auto load markdown components under `./src/components/` | |
extensions: ['vue', 'md'], | |
// allow auto import and register components used in markdown | |
include: [/\.vue$/, /\.vue\?vue/, /\.md$/], | |
// custom resolvers | |
resolvers: [ | |
// auto import icons | |
// https://github.com/antfu/unplugin-icons | |
IconsResolver({ | |
prefix: false, | |
// enabledCollections: ['carbon'] | |
}), | |
], | |
dts: 'src/components.d.ts', | |
}), | |
// https://github.com/antfu/unplugin-icons | |
Icons({ | |
autoInstall: true, | |
}), | |
// https://github.com/antfu/vite-plugin-windicss | |
WindiCSS({ | |
safelist: markdownWrapperClasses, | |
}), | |
// https://github.com/antfu/vite-plugin-md | |
Markdown({ | |
wrapperClasses: markdownWrapperClasses, | |
headEnabled: true, | |
markdownItSetup(md) { | |
// https://prismjs.com/ | |
md.use(Prism) | |
md.use(LinkAttributes, { | |
matcher: (link: string) => /^https?:\/\//.test(link), | |
attrs: { | |
target: '_blank', | |
rel: 'noopener', | |
}, | |
}) | |
}, | |
}), | |
// https://github.com/antfu/vite-plugin-pwa | |
VitePWA({ | |
registerType: 'autoUpdate', | |
includeAssets: [ | |
'/favicon.svg', | |
'/robots.txt', | |
'/safari-pinned-tab.svg', | |
], | |
manifest: { | |
name: 'Verify', | |
short_name: 'Verify', | |
theme_color: '#ffffff', | |
icons: [ | |
{ | |
src: '/pwa-192x192.png', | |
sizes: '192x192', | |
type: 'image/png', | |
}, | |
{ | |
src: '/pwa-512x512.png', | |
sizes: '512x512', | |
type: 'image/png', | |
}, | |
{ | |
src: '/pwa-512x512.png', | |
sizes: '512x512', | |
type: 'image/png', | |
purpose: 'any maskable', | |
}, | |
], | |
}, | |
}), | |
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n | |
VueI18n({ | |
runtimeOnly: true, | |
compositionOnly: true, | |
include: [path.resolve(__dirname, 'locales/**')], | |
}), | |
// https://github.com/antfu/vite-plugin-inspect | |
Inspect({ | |
// change this to enable inspect for debugging | |
enabled: false, | |
}), | |
], | |
server: { | |
fs: { | |
strict: true, | |
}, | |
}, | |
optimizeDeps: { | |
include: ['vue', 'vue-router', '@vueuse/core', '@vueuse/head'], | |
exclude: ['vue-demi'], | |
esbuildOptions: { | |
// Node.js global to browser globalThis | |
define: { | |
global: 'globalThis' | |
}, | |
// Enable esbuild polyfill plugins | |
plugins: [ | |
NodeGlobalsPolyfillPlugin({ | |
process: true, | |
buffer: true | |
}), | |
NodeModulesPolyfillPlugin() | |
] | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment