123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import { fileURLToPath, URL } from 'node:url';
- import path from 'path';
- import { defineConfig } from 'vite';
- import vue from '@vitejs/plugin-vue';
- import vueJsx from '@vitejs/plugin-vue-jsx';
- import { createHtmlPlugin } from 'vite-plugin-html';
- import AutoImport from 'unplugin-auto-import/vite';
- import Components from 'unplugin-vue-components/vite';
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
- const IS_PRODUCTION = process.env.NODE_ENV === 'production';
- // 当前场景
- const SCENE = process.env.VITE_APP_SCENE;
- // 是否离线包
- const OFFLINE = Boolean(Number(process.env.VITE_APP_OFFLINE));
- const extensions = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'];
- if (SCENE != null) {
- console.log('当前场景:', SCENE);
- extensions.unshift(
- `.${SCENE}.mjs`,
- `.${SCENE}.js`,
- `.${SCENE}.ts`,
- `.${SCENE}.jsx`,
- `.${SCENE}.tsx`,
- `.${SCENE}.json`,
- `.${SCENE}.vue`
- );
- if (OFFLINE) {
- extensions.unshift(
- `.${SCENE}.offline.mjs`,
- `.${SCENE}.offline.js`,
- `.${SCENE}.offline.ts`,
- `.${SCENE}.offline.jsx`,
- `.${SCENE}.offline.tsx`,
- `.${SCENE}.offline.json`,
- `.${SCENE}.offline.vue`
- );
- }
- }
- // https://vite.dev/config/
- export default defineConfig(() => {
- return {
- base: './',
- plugins: [
- createHtmlPlugin({
- inject: {
- data: {
- title: process.env.TITLE,
- },
- },
- }),
- vue(),
- vueJsx(),
- AutoImport({
- resolvers: [
- ElementPlusResolver({
- importStyle: 'sass',
- }),
- ],
- }),
- Components({
- resolvers: [
- ElementPlusResolver({
- importStyle: 'sass',
- }),
- ],
- }),
- ],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src/index', import.meta.url)),
- '@hotspot': fileURLToPath(new URL('./src/hotspot', import.meta.url)),
- },
- extensions,
- },
- server: {
- port: Number(process.env.PORT) || 80,
- host: '0.0.0.0',
- strictPort: true,
- cors: true,
- },
- build: {
- outDir: IS_PRODUCTION && SCENE ? `build/${SCENE}` : 'build',
- assetsDir: 'assets',
- sourcemap: process.env.SOURCE_MAP === 'true',
- rollupOptions: {
- input: {
- index: path.resolve(__dirname, 'index.html'),
- hotspot: path.resolve(__dirname, 'hotspot.html'),
- },
- output: {
- manualChunks: {
- vendors: ['vue', 'element-plus', 'swiper'],
- },
- },
- },
- },
- css: {
- preprocessorOptions: {
- scss: {
- api: 'modern-compiler',
- additionalData: `@use "@/assets/el${SCENE ? '.' + SCENE : ''}.scss" as *;`,
- },
- },
- },
- };
- });
|