|
- import vue2 from '@vitejs/plugin-vue2';
- import gzip from 'rollup-plugin-gzip';
- import { fileURLToPath } from 'url';
- import path, { resolve } from 'path';
- import { createHtmlPlugin } from 'vite-plugin-html';
- import { defineConfig, loadEnv } from 'vite';
- import inject from 'rollup-plugin-inject';
-
- // 获取当前文件所在的目录
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
-
- // 读取 package.json 文件
- const pkg = require(path.resolve(__dirname, 'package.json'));
- const pathResolve = (dir) => {
- return resolve(__dirname, '.', dir);
- };
-
- const alias = {
- '/@': pathResolve('./src/')
- };
-
- const plugins = [vue2(), createHtmlPlugin({
- minify: true,
- inject: {
- data: {
- version: pkg.version
- }
- },
- })]
-
- const viteConfig = defineConfig((mode) => {
- const env = loadEnv(mode.mode, process.cwd());
- return {
- publicDir: 'src/static',
- plugins: mode.command === 'serve' ? plugins
- : plugins.concat([gzip()]),
- root: process.cwd(),
- resolve: { alias },
- base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
- server: {
- host: '0.0.0.0',
- port: 8888,
- open: false,
- hmr: true,
- headers: {
- 'Access-Control-Allow-Origin': '*'
- },
- proxy: {
- '/api': {
- target: 'https://admintest.malls.iformall.com/api',
- // target: 'https://admin.malls.iformall.com/api',
- ws: true,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ''),
- },
- },
- },
- build: {
- outDir: 'dist',
- chunkSizeWarningLimit: 1500,
- rollupOptions: {
- plugins: [
- inject({
- "echarts": 'echarts',
- 'vue-ueditor-wrap': 'vue-ueditor-wrap',
- })
- ],
- output: {
- entryFileNames: `assets/[name].[hash].js`,
- chunkFileNames: `assets/[name].[hash].js`,
- assetFileNames: `assets/[name].[hash].[ext]`,
- compact: true,
- manualChunks: {
- // vue: ['vue', 'vue-router'],
- // echarts: ['echarts'],
- },
- },
- },
- },
- css: {
- preprocessorOptions: {
- css: { charset: false }
- }
- },
- define: {
- __VUE_I18N_LEGACY_API__: JSON.stringify(false),
- __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
- __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
- __VERSION__: JSON.stringify(process.env.npm_package_version),
- },
- };
- });
-
- export default viteConfig;
|