vite.config.js 1.59 KB
import {defineConfig, loadEnv} from 'vite';
import vue from '@vitejs/plugin-vue';
import {vitePluginForArco} from '@arco-plugins/vite-vue'
import vitePluginOss from 'vite-plugin-oss';
import laravel from "./vite-laravel-plugin";


const ossPath = `asset${new Date()
    .toLocaleString('zh')
    .slice(0, 20)
    .replace(/[\s/:]/g, '')}`

const config = loadEnv("", "");

export default defineConfig({
    plugins: [
        laravel({
            assetUrl: config.VITE_ASSET_URL,
            buildDirectory: 'vendor/web',
            input: ['resources/js/app.ts'],
            css: {preprocessorOptions: {less: {math: "always", relativeUrls: true, javascriptEnabled: true}}},
            refresh: true
        }),
        vue({
            template: {transformAssetUrls: {base: null, includeAbsolute: false}},
            script: {defineModel: true}
        }),
        vitePluginForArco({style: 'css'}),
        vitePluginOss({
            from: `./public/vendor/web/${ossPath}/**`,
            dist: `vendor/web`,
            accessKeyId: config.VITE_OSS_ACCESS_KEY,
            accessKeySecret: config.VITE_OSS_ACCESS_SECRET,
            bucket: config.VITE_OSS_BUCKET,
            region: config.VITE_OSS_REGION.replace('.aliyuncs.com', ''),
            quitWpOnError: true,
            deleteOrigin: true,
            deleteEmptyDir: true
        }),
    ],
    resolve: {
        alias: {
            '@image': '/resources/image',
            '@css': '/resources/css'
        },
    },
    server: {
        https: false
    },
    build: {
        chunkSizeWarningLimit: 1024,
        assetsDir: ossPath,
    },
});