fix: yarn dev error

This commit is contained in:
chenos 2024-03-16 22:44:57 +08:00
parent 8278262728
commit c191f149f9
3 changed files with 21 additions and 18 deletions

View File

@ -16,27 +16,30 @@ const outputPluginPath = path.join(__dirname, 'src', '.plugins');
const indexGenerator = new IndexGenerator(outputPluginPath, pluginDirs);
indexGenerator.generate();
const isDevCmd = !!process.env.IS_DEV_CMD;
const appPublicPath = isDevCmd ? '/' : '{{env.APP_PUBLIC_PATH}}';
export default defineConfig({
title: 'Loading...',
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
favicons: [`{{env.APP_PUBLIC_PATH}}favicon/favicon.ico`],
favicons: [`${appPublicPath}favicon/favicon.ico`],
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
links: [
{ rel: 'apple-touch-icon', size: '180x180', ref: `{{env.APP_PUBLIC_PATH}}favicon/apple-touch-icon.png` },
{ rel: 'icon', type: 'image/png', size: '32x32', ref: `{{env.APP_PUBLIC_PATH}}favicon/favicon-32x32.png` },
{ rel: 'icon', type: 'image/png', size: '16x16', ref: `{{env.APP_PUBLIC_PATH}}favicon/favicon-16x16.png` },
{ rel: 'manifest', href: `{{env.APP_PUBLIC_PATH}}favicon/site.webmanifest` },
{ rel: 'stylesheet', href: `{{env.APP_PUBLIC_PATH}}global.css` },
{ 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` },
],
headScripts: [
{
src: `{{env.APP_PUBLIC_PATH}}browser-checker.js`,
src: `${appPublicPath}browser-checker.js`,
},
{
content: `
content: isDevCmd ? '' : `
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';
window['__nocobase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';
window['__nocobase_ws_url__'] = '{{env.WS_URL}}';
window['__nocobase_ws_path__'] = '{{env.WS_PATH}}';
`,

View File

@ -5,16 +5,16 @@ import devDynamicImport from '../.plugins/index';
export const app = new Application({
apiClient: {
// @ts-ignore
baseURL: window['__nocobase_api_base_url__'] || '/api/',
baseURL: window['__nocobase_api_base_url__'] || process.env.API_BASE_URL || '/api/',
},
// @ts-ignore
publicPath: window['__nocobase_public_path__'] || '/',
publicPath: window['__nocobase_public_path__'] || process.env.APP_PUBLIC_PATH || '/',
plugins: [NocoBaseClientPresetPlugin],
ws: {
// @ts-ignore
url: window['__nocobase_ws_url__'] || '',
url: window['__nocobase_ws_url__'] || process.env.WEBSOCKET_URL || '',
// @ts-ignore
basename: window['__nocobase_ws_path__'] || '/ws',
basename: window['__nocobase_ws_path__'] || process.env.WS_PATH || '/ws',
},
loadRemotePlugins: true,
devDynamicImport,

View File

@ -8,11 +8,11 @@ const path = require('path');
console.log('VERSION: ', packageJson.version);
function getUmiConfig() {
const { APP_PORT, API_BASE_URL } = process.env;
const { APP_PORT, API_BASE_URL, APP_PUBLIC_PATH } = process.env;
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
const LOCAL_STORAGE_BASE_URL = '/storage/uploads/';
const STATIC_PATH = '/static/';
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
const STATIC_PATH = 'static/';
function getLocalStorageProxy() {
if (LOCAL_STORAGE_BASE_URL.startsWith('http')) {
@ -20,11 +20,11 @@ function getUmiConfig() {
}
return {
[LOCAL_STORAGE_BASE_URL]: {
[APP_PUBLIC_PATH + LOCAL_STORAGE_BASE_URL]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
},
[STATIC_PATH]: {
[APP_PUBLIC_PATH + STATIC_PATH]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
},