Cleanup: Define routerBasePath constant in nuxt.config.js

This commit is contained in:
mikiher 2024-10-12 11:46:44 +03:00
parent 69dd82d329
commit 99ffd3050c

View File

@ -1,19 +1,21 @@
const pkg = require('./package.json') const pkg = require('./package.json')
const routerBasePath = process.env.ROUTER_BASE_PATH || ''
module.exports = { module.exports = {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
ssr: false, ssr: false,
target: 'static', target: 'static',
dev: process.env.NODE_ENV !== 'production', dev: process.env.NODE_ENV !== 'production',
env: { env: {
serverUrl: process.env.NODE_ENV === 'production' ? process.env.ROUTER_BASE_PATH || '' : 'http://localhost:3333', serverUrl: process.env.NODE_ENV === 'production' ? routerBasePath : 'http://localhost:3333',
chromecastReceiver: 'FD1F76C5' chromecastReceiver: 'FD1F76C5'
}, },
telemetry: false, telemetry: false,
publicRuntimeConfig: { publicRuntimeConfig: {
version: pkg.version, version: pkg.version,
routerBasePath: process.env.ROUTER_BASE_PATH || '' routerBasePath
}, },
// Global page headers: https://go.nuxtjs.dev/config-head // Global page headers: https://go.nuxtjs.dev/config-head
@ -30,13 +32,13 @@ module.exports = {
], ],
script: [], script: [],
link: [ link: [
{ rel: 'icon', type: 'image/x-icon', href: (process.env.ROUTER_BASE_PATH || '') + '/favicon.ico' }, { rel: 'icon', type: 'image/x-icon', href: routerBasePath + '/favicon.ico' },
{ rel: 'apple-touch-icon', href: (process.env.ROUTER_BASE_PATH || '') + '/ios_icon.png' } { rel: 'apple-touch-icon', href: routerBasePath + '/ios_icon.png' }
] ]
}, },
router: { router: {
base: process.env.ROUTER_BASE_PATH || '' base: routerBasePath
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css
@ -72,7 +74,7 @@ module.exports = {
], ],
proxy: { proxy: {
[`${process.env.ROUTER_BASE_PATH || ''}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' } [`${routerBasePath}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' }
}, },
io: { io: {
@ -87,7 +89,7 @@ module.exports = {
// Axios module configuration: https://go.nuxtjs.dev/config-axios // Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: { axios: {
baseURL: process.env.ROUTER_BASE_PATH || '' baseURL: routerBasePath
}, },
// nuxt/pwa https://pwa.nuxtjs.org // nuxt/pwa https://pwa.nuxtjs.org
@ -107,11 +109,11 @@ module.exports = {
background_color: '#232323', background_color: '#232323',
icons: [ icons: [
{ {
src: (process.env.ROUTER_BASE_PATH || '') + '/icon.svg', src: routerBasePath + '/icon.svg',
sizes: 'any' sizes: 'any'
}, },
{ {
src: (process.env.ROUTER_BASE_PATH || '') + '/icon192.png', src: routerBasePath + '/icon192.png',
type: 'image/png', type: 'image/png',
sizes: 'any' sizes: 'any'
} }