2023-08-02 00:07:52 +08:00
|
|
|
import path from 'path';
|
2024-06-13 15:56:43 +08:00
|
|
|
import { getUmiConfig, IndexGenerator } from '@tachybase/devtools/umiConfig';
|
|
|
|
|
2022-02-10 18:37:16 +08:00
|
|
|
import { defineConfig } from 'umi';
|
2022-04-17 17:14:50 +08:00
|
|
|
|
|
|
|
const umiConfig = getUmiConfig();
|
2022-03-06 17:29:20 +08:00
|
|
|
|
2022-02-10 18:37:16 +08:00
|
|
|
process.env.MFSU_AD = 'none';
|
2023-06-20 11:48:02 +08:00
|
|
|
process.env.DID_YOU_KNOW = 'none';
|
2022-02-10 18:37:16 +08:00
|
|
|
|
2023-08-02 00:07:52 +08:00
|
|
|
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || '').split(',').filter((item) => !item.includes('preset')); // 因为现在 preset 是直接引入的,所以不能忽略,如果以后 preset 也是动态插件的形式引入,那么这里可以去掉
|
2023-09-03 10:59:33 +08:00
|
|
|
|
2023-11-24 15:49:37 +08:00
|
|
|
const pluginDirs = (process.env.PLUGIN_PATH || 'packages/plugins/,packages/samples/,packages/pro-plugins/')
|
2024-06-13 15:56:43 +08:00
|
|
|
.split(',')
|
|
|
|
.map((item) => path.join(process.cwd(), item));
|
2023-08-02 00:07:52 +08:00
|
|
|
|
2023-08-20 18:10:34 +08:00
|
|
|
const outputPluginPath = path.join(__dirname, 'src', '.plugins');
|
2023-08-02 00:07:52 +08:00
|
|
|
const indexGenerator = new IndexGenerator(outputPluginPath, pluginDirs);
|
|
|
|
indexGenerator.generate();
|
|
|
|
|
2024-03-16 22:44:57 +08:00
|
|
|
const isDevCmd = !!process.env.IS_DEV_CMD;
|
|
|
|
const appPublicPath = isDevCmd ? '/' : '{{env.APP_PUBLIC_PATH}}';
|
|
|
|
|
2022-02-10 18:37:16 +08:00
|
|
|
export default defineConfig({
|
2023-06-20 11:48:02 +08:00
|
|
|
title: 'Loading...',
|
2024-03-03 23:06:24 +08:00
|
|
|
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
|
2024-03-16 22:44:57 +08:00
|
|
|
favicons: [`${appPublicPath}favicon/favicon.ico`],
|
2023-08-02 00:07:52 +08:00
|
|
|
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
|
2023-06-20 11:48:02 +08:00
|
|
|
links: [
|
2024-03-16 22:44:57 +08:00
|
|
|
{ rel: 'apple-touch-icon', size: '180x180', ref: `${appPublicPath}favicon/apple-touch-icon.png` },
|
|
|
|
{ rel: 'icon', type: 'image/png', size: '32x32', ref: `${appPublicPath}favicon/favicon-32x32.png` },
|
|
|
|
{ rel: 'icon', type: 'image/png', size: '16x16', ref: `${appPublicPath}favicon/favicon-16x16.png` },
|
|
|
|
{ rel: 'manifest', href: `${appPublicPath}favicon/site.webmanifest` },
|
|
|
|
{ rel: 'stylesheet', href: `${appPublicPath}global.css` },
|
2024-03-16 20:01:34 +08:00
|
|
|
],
|
|
|
|
headScripts: [
|
|
|
|
{
|
2024-03-16 22:44:57 +08:00
|
|
|
src: `${appPublicPath}browser-checker.js`,
|
2024-03-16 20:01:34 +08:00
|
|
|
},
|
|
|
|
{
|
2024-06-13 15:56:43 +08:00
|
|
|
content: isDevCmd
|
|
|
|
? ''
|
|
|
|
: `
|
2024-03-16 20:01:34 +08:00
|
|
|
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
2024-05-24 13:06:59 +08:00
|
|
|
window['__tachybase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
|
|
|
window['__tachybase_api_base_url__'] = '{{env.API_BASE_URL}}';
|
|
|
|
window['__tachybase_ws_url__'] = '{{env.WS_URL}}';
|
|
|
|
window['__tachybase_ws_path__'] = '{{env.WS_PATH}}';
|
2024-03-16 20:01:34 +08:00
|
|
|
`,
|
|
|
|
},
|
2023-06-20 11:48:02 +08:00
|
|
|
],
|
2023-08-02 00:07:52 +08:00
|
|
|
outputPath: path.resolve(__dirname, '../dist/client'),
|
2022-03-21 21:37:35 +08:00
|
|
|
hash: true,
|
2023-06-20 11:48:02 +08:00
|
|
|
alias: {
|
|
|
|
...umiConfig.alias,
|
|
|
|
},
|
2022-03-06 17:29:20 +08:00
|
|
|
define: {
|
|
|
|
...umiConfig.define,
|
2023-08-02 00:07:52 +08:00
|
|
|
'process.env.USE_REMOTE_PLUGIN': process.env.USE_REMOTE_PLUGIN,
|
2024-08-14 14:32:14 +08:00
|
|
|
'process.env.SENTRY_DSN': process.env.SENTRY_DSN,
|
|
|
|
'process.env.SENTRY_TRACE_ENABLE': process.env.SENTRY_TRACE_ENABLE,
|
|
|
|
'process.env.SENTRY_TRACE_SAMPLE_RATE': process.env.SENTRY_TRACE_SAMPLE_RATE,
|
|
|
|
'process.env.SENTRY_TRACE_PROPAGATION_TARGETS': process.env.SENTRY_TRACE_PROPAGATION_TARGETS,
|
|
|
|
'process.env.SENTRY_SESSION_REPLAY_ENABLE': process.env.SENTRY_SESSION_REPLAY_ENABLE,
|
|
|
|
'process.env.SENTRY_SESSION_REPLAY_SAMPLE_RATE': process.env.SENTRY_SESSION_REPLAY_SAMPLE_RATE,
|
|
|
|
'process.env.SENTRY_SESSION_REPLAY_ONERROR_SAMPLE_RATE': process.env.SENTRY_SESSION_REPLAY_ONERROR_SAMPLE_RATE,
|
2022-03-06 17:29:20 +08:00
|
|
|
},
|
|
|
|
proxy: {
|
|
|
|
...umiConfig.proxy,
|
|
|
|
},
|
2023-06-20 11:48:02 +08:00
|
|
|
fastRefresh: false, // 热更新会导致 Context 丢失,不开启
|
|
|
|
mfsu: false,
|
|
|
|
esbuildMinifyIIFE: true,
|
|
|
|
// srcTranspiler: 'esbuild', // 不行,各种报错
|
|
|
|
// mfsu: {
|
|
|
|
// esbuild: true // 不行,各种报错
|
|
|
|
// },
|
|
|
|
// 浏览器兼容性,兼容到 2018 年的浏览器
|
|
|
|
targets: {
|
|
|
|
chrome: 69,
|
|
|
|
edge: 79,
|
|
|
|
safari: 12,
|
2022-02-10 18:37:16 +08:00
|
|
|
},
|
2023-09-03 10:59:33 +08:00
|
|
|
codeSplitting: {
|
2024-06-13 15:56:43 +08:00
|
|
|
jsStrategy: 'depPerChunk',
|
2023-09-03 10:59:33 +08:00
|
|
|
},
|
2023-08-02 00:07:52 +08:00
|
|
|
chainWebpack(config, { env }) {
|
|
|
|
if (env === 'production') {
|
2024-05-24 13:06:59 +08:00
|
|
|
config.plugin('ignore tachybase plugins').use(require('webpack').IgnorePlugin, [
|
2023-08-02 00:07:52 +08:00
|
|
|
{
|
|
|
|
resourceRegExp: new RegExp(pluginPrefix.join('|')),
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
},
|
2023-06-20 11:48:02 +08:00
|
|
|
routes: [{ path: '/*', component: 'index' }],
|
2022-02-10 18:37:16 +08:00
|
|
|
});
|