1 Star 1 Fork 0

星辰编程理财/istock-shell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
星辰编程理财 提交于 2024-07-22 10:37 +08:00 . fix: pwa支持引入路径问题
import { resolve } from 'path';
import { defineConfig, loadEnv, type PluginOption } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import typescript from '@rollup/plugin-typescript';
import eslint from 'vite-plugin-eslint';
import { VitePWA } from 'vite-plugin-pwa';
import { pwaConfig } from './pwa.config';
const tsPlugin: PluginOption = typescript({
include: ['src/worker/domains/**/*'],
}) as any;
// https://vitejs.dev/config/
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd());
return defineConfig({
base: './',
plugins: [
svelte(),
tsPlugin,
eslint(),
VitePWA(pwaConfig),
{
name: 'html-transform',
transformIndexHtml(html) {
if (env.VITE_SITE_BAIDU_ANALYSIS !== 'true') return html;
const index = html.indexOf('</head>');
const baidu = `<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?dfec2bfb0d9f6e4c9e142271e4c34a1e";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
`;
return html.substring(0, index) + baidu + html.substring(index);
},
},
],
worker: {
format: 'es',
plugins: () => [tsPlugin],
},
resolve: {
alias: {
'@root': __dirname,
'@': resolve(__dirname, 'src'),
'@domains': resolve(__dirname, 'src/worker/domains'),
},
},
server: {
proxy: {
'/api': {
target: env.VITE_PROXY ?? 'https://istock.red',
changeOrigin: true,
secure: false,
rewrite: (path) => path,
},
},
},
build: {
// minify: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('/node_modules/@antv/')) {
return 'antv';
}
if (id.includes('/node_modules/')) {
return 'lib';
}
},
},
},
},
});
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/xcbclc/istock-shell.git
git@gitee.com:xcbclc/istock-shell.git
xcbclc
istock-shell
istock-shell
main

搜索帮助