diff --git a/build/plugins/index.ts b/build/plugins/index.ts index 97fc3e2d..a85d4cad 100644 --- a/build/plugins/index.ts +++ b/build/plugins/index.ts @@ -1,9 +1,9 @@ import type { PluginOption } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; -import unocss from '@unocss/vite'; -import progress from 'vite-plugin-progress'; -import VueDevtools from 'vite-plugin-vue-devtools'; +// import unocss from '@unocss/vite'; +// import progress from 'vite-plugin-progress'; +// import VueDevtools from 'vite-plugin-vue-devtools'; import pageRoute from '@soybeanjs/vite-plugin-vue-page-route'; import unplugin from './unplugin'; import mock from './mock'; @@ -17,20 +17,28 @@ import pwa from './pwa'; */ export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | PluginOption[])[] { const plugins = [ - vue({ - script: { - defineModel: true - } + () => ({ + vitePlugin: vue({ + script: { + defineModel: true + } + }), + filters: ['\\.vue$', '\\\\0.+'] }), - vueJsx(), - VueDevtools(), + () => ({ + vitePlugin: vueJsx(), + filters: ['\\.vue$', '\\\\0.+'] + }), + // VueDevtools(), ...unplugin(viteEnv), - unocss(), - mock(viteEnv), - progress() + // unocss(), + mock(viteEnv) + // progress() ]; if (viteEnv.VITE_VISUALIZER === 'Y') { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore plugins.push(visualizer as PluginOption); } if (viteEnv.VITE_COMPRESS === 'Y') { @@ -42,6 +50,7 @@ export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | Plugin if (viteEnv.VITE_SOYBEAN_ROUTE_PLUGIN === 'Y') { plugins.push(pageRoute()); } - + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore return plugins; } diff --git a/build/plugins/unplugin.ts b/build/plugins/unplugin.ts index e42a81d1..37fc4a66 100644 --- a/build/plugins/unplugin.ts +++ b/build/plugins/unplugin.ts @@ -1,9 +1,9 @@ import Icons from 'unplugin-icons/vite'; import IconsResolver from 'unplugin-icons/resolver'; -import Components from 'unplugin-vue-components/vite'; +import Components from 'unplugin-vue-components/rollup'; import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'; import { FileSystemIconLoader } from 'unplugin-icons/loaders'; -import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; +// import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; import { getSrcPath } from '../utils'; export default function unplugin(viteEnv: ImportMetaEnv) { @@ -33,12 +33,12 @@ export default function unplugin(viteEnv: ImportMetaEnv) { NaiveUiResolver(), IconsResolver({ customCollections: [collectionName], componentPrefix: VITE_ICON_PREFIX }) ] - }), - createSvgIconsPlugin({ - iconDirs: [localIconPath], - symbolId: `${VITE_ICON_LOCAL_PREFIX}-[dir]-[name]`, - inject: 'body-last', - customDomId: '__SVG_ICON_LOCAL__' }) + // createSvgIconsPlugin({ + // iconDirs: [localIconPath], + // symbolId: `${VITE_ICON_LOCAL_PREFIX}-[dir]-[name]`, + // inject: 'body-last', + // customDomId: '__SVG_ICON_LOCAL__' + // }) ]; } diff --git a/farm.config.ts b/farm.config.ts new file mode 100644 index 00000000..00d14412 --- /dev/null +++ b/farm.config.ts @@ -0,0 +1,79 @@ +import type { UserConfig } from '@farmfe/core'; +import { loadEnv } from 'vite'; +// import vue from '@farmfe/js-plugin-vue'; +import postcss from '@farmfe/js-plugin-postcss'; +import { createViteProxy, getRootPath, getSrcPath, setupVitePlugins, viteDefine } from './build'; +import { getServiceEnvConfig } from './.env-config'; + +function defineConfig(config: UserConfig) { + return config; +} + +const mode = process.env.NODE_ENV as string; +const viteEnv = loadEnv(mode, process.cwd()) as unknown as ImportMetaEnv; + +const rootPath = getRootPath(); +const srcPath = getSrcPath(); + +const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'Y'; +const envConfig = getServiceEnvConfig(viteEnv); + +export default defineConfig({ + root: rootPath, + compilation: { + resolve: { + alias: { + '~': rootPath, + '@': srcPath + // 'socket.io-parser': 'socket.io-parser/build/esm', + // 'engine.io-parser': 'engine.io-parser/build/esm' + } + }, + define: viteDefine, + sourcemap: true + }, + vitePlugins: setupVitePlugins(viteEnv) as object[], + plugins: [['@farmfe/plugin-sass', { additionalData: `@use "@/styles/scss/global.scss" as *;` }], postcss()], + server: { + // host: '0.0.0.0', + port: 3200, + // open: true, + proxy: createViteProxy(isOpenProxy, envConfig) as any + } +}); + +// css: { +// preprocessorOptions: { +// scss: { +// additionalData: `@use "./src/styles/scss/global.scss" as *;` +// } +// } +// }, +// server: { +// host: '0.0.0.0', +// port: 3200, +// open: true, +// proxy: createViteProxy(isOpenProxy, envConfig) +// }, +// optimizeDeps: { +// include: [ +// '@antv/data-set', +// '@antv/g2', +// '@better-scroll/core', +// 'echarts', +// 'swiper', +// 'swiper/vue', +// 'vditor', +// 'wangeditor', +// 'xgplayer' +// ] +// }, +// build: { +// reportCompressedSize: false, +// sourcemap: false, +// commonjsOptions: { +// ignoreTryCatch: false +// } +// } +// }; +// }); diff --git a/index.html b/index.html index 0b1834be..a49945a4 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,6 @@