1 Star 0 Fork 40

小喵逗鱼 / stepin-template

forked from stepui / stepin-template 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vite.config.ts 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
iczer 提交于 2023-04-02 15:21 . 新增:增加生产环境编译配置;
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import { AntdvLessPlugin, AntdvModifyVars } from 'stepin/lib/style/plugins';
const timestamp = new Date().getTime();
const prodRollupOptions = {
output: {
chunkFileNames: (chunk) => {
return 'assets/' + chunk.name + '.[hash]' + '.' + timestamp + '.js';
},
assetFileNames: (asset) => {
const name = asset.name;
if (name && (name.endsWith('.css') || name.endsWith('.js'))) {
const names = name.split('.');
const extname = names.splice(names.length - 1, 1)[0];
return `assets/${names.join('.')}.[hash].${timestamp}.${extname}`;
}
return 'assets/' + asset.name;
},
},
};
// vite 配置
export default ({ command, mode }) => {
// 获取环境变量
const env = loadEnv(mode, process.cwd());
console.log(mode);
return defineConfig({
server: {
proxy: {
'/api': {
target: env.VITE_API_URL,
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
hmr: true,
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
build: {
sourcemap: true,
chunkSizeWarningLimit: 2048,
rollupOptions: mode === 'production' ? prodRollupOptions : {},
},
plugins: [
vue({
template: {
transformAssetUrls: {
img: ['src'],
'a-avatar': ['src'],
'stepin-view': ['logo-src', 'presetThemeList'],
'a-card': ['cover'],
},
},
}),
Components({
resolvers: [AntDesignVueResolver({ importStyle: mode === 'development' ? false : 'less' })],
}),
],
css: {
preprocessorOptions: {
less: {
plugins: [AntdvLessPlugin],
modifyVars: AntdvModifyVars,
javascriptEnabled: true,
},
},
},
base: env.VITE_BASE_URL,
});
};
1
https://gitee.com/little_mew_amusing_fish/stepin-template.git
git@gitee.com:little_mew_amusing_fish/stepin-template.git
little_mew_amusing_fish
stepin-template
stepin-template
main

搜索帮助