123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import path from 'node:path'
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue2'
- import WindiCSS from 'vite-plugin-windicss'
- import Components from 'unplugin-vue-components/vite'
- import Icons from 'unplugin-icons/vite'
- import IconsResolver from 'unplugin-icons/resolver'
- import AutoImport from 'unplugin-auto-import/vite'
- import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
- import prefixer from 'postcss-prefix-selector'
- import basicSsl from '@vitejs/plugin-basic-ssl'
- const buildMap = {
- // 抽取vue等库
- external: {
- lib: {
- entry: path.resolve(__dirname, 'src/lib/main.ts'),
- name: 'JyLogin',
- fileName: 'jy-login-mini'
- },
- rollupOptions: {
- external: ['vue'],
- output: {
- globals: {
- vue: 'Vue'
- }
- }
- }
- },
- // 不抽取vue等库,全部打包到一起
- internal: {
- lib: {
- entry: path.resolve(__dirname, 'src/lib/main.ts'),
- name: 'JyLogin',
- fileName: 'jy-login'
- }
- }
- }
- // 参数 { mode: 'external', command: 'build', ssrBuild: false }
- export default ({ mode, command }) => {
- const buildDiff = buildMap[mode] || {}
- return defineConfig({
- resolve: {
- alias: {
- '@': `${path.resolve(__dirname, 'src')}`
- }
- },
- build: {
- target: 'chrome58',
- cssTarget: 'chrome58',
- minify: true,
- emptyOutDir: false,
- ...buildDiff
- },
- define: {
- 'process.env.NODE_ENV': '"production"'
- },
- css: {
- postcss: {
- plugins: [
- prefixer({
- prefix: '.plugin-login-auth-container',
- transform(prefix, selector, prefixedSelector, filePath, rule) {
- if (selector.match(/^(html|body)/))
- return selector.replace(/^([^\s]*)/, `$1 ${prefix}`)
- if (filePath.match(/node_modules/)) return selector
- const annotation = rule.prev()
- if (
- annotation?.type === 'comment' &&
- annotation.text.trim() === 'no-prefix'
- )
- return selector // Do not prefix style rules that are preceded by: /* no-prefix */
- return prefixedSelector
- }
- })
- ]
- }
- },
- plugins: [
- basicSsl(),
- vue(),
- WindiCSS(),
- Components({
- resolvers: [
- IconsResolver({
- componentPrefix: ''
- })
- ],
- dts: 'src/components.d.ts'
- }),
- Icons(),
- cssInjectedByJsPlugin(),
- AutoImport({
- imports: ['@vueuse/core'],
- dts: 'src/auto-imports.d.ts'
- })
- ],
- server: {
- https: true,
- host: true,
- port: 3333,
- proxy: {
- '/aiChat': {
- target: 'https://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true
- },
- '/jyapi': {
- target: 'https://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true
- },
- '/api': {
- target: 'https://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, '')
- },
- '/front': {
- target: 'https://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true
- },
- '/aiChat/ws': {
- target: 'ws://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true,
- ws: true
- },
- '/ws': {
- target: 'wss://jybx3-webtest.jydev.jianyu360.com',
- changeOrigin: true,
- ws: true
- }
- }
- }
- })
- }
|