// vite.config.js 利害浏览器自带的 es 动态导入,使项目冷启动 const { resolve } = require('path'); import { defineConfig, loadEnv } from 'vite' import { createVuePlugin } from "vite-plugin-vue2"; import vueJsx from '@vitejs/plugin-vue-jsx' import pageData from "vite-plugin-pagedata" // import vitefunc from './vite-plugin/vite-plugin-func' import { injectHtml } from 'vite-plugin-html'; const pkg = require("./package.json"); // https://vitejs.dev/config/ export default ({ mode }) => { process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; let aliases = {} let build = { sourcemap: false, //编译 //指定 多个 .html 文件作为入口点 rollupOptions: { // 请确保外部化那些你的库中不需要的依赖 // external: ['vue'], input: { main: resolve(__dirname, 'index.html'), nested: resolve(__dirname, 'nested/index.html') }, output: { format: 'umd', } } } if (mode == 'development') { aliases = { '@project': resolve(`${pkg.name == 'hi-vui-template' ? 'project' : pkg.name}`), '@main': resolve(`${pkg.name == 'hi-vui-template' ? 'project' : pkg.name}/hivuiMain`), } // console.log('aliases@main:', aliases['@main']); } else { } const postDataName = "scpRequestData"; return defineConfig({ build: build, css: { preprocessorOptions: { less: { javascriptEnabled: true, } }, }, resolve: { extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.dtvevt', '.dtv'], alias: aliases, }, plugins: [ // vitefunc({ // varName: postDataName, // htmlWebpackPlugin: { // vite: true // } // }), injectHtml({ // 向预览时注入变量,这个变量跟打包时 html-webpack-plugin 注入的一致,用户判断是否是编译状态 injectData: { htmlWebpackPlugin: { vite: true } } }), pageData({ varName: postDataName }), createVuePlugin(), vueJsx({ // options are passed on to @vue/babel-plugin-jsx }), ], optimizeDeps: { //vite 排除,并同时js 文件中不引用。如果有引用还是会取vite 模板缓存中的文件,这样就无法引用全局 exclude: ["vue", "element-ui"] }, devServer: { port: 227, proxy: 'http://192.168.1.183:5001/' } }) };