Update static handling for vite
This commit is contained in:
parent
5bcaaec858
commit
35044f092b
|
|
@ -1,33 +1,35 @@
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import gql from '@rollup/plugin-graphql';
|
import gql from '@rollup/plugin-graphql'
|
||||||
import path from 'path';
|
import path from 'path'
|
||||||
|
|
||||||
|
|
||||||
const getFlavorConfig = () => {
|
const getFlavorConfig = () => {
|
||||||
switch (process.env.APP_FLAVOR) {
|
switch (process.env.APP_FLAVOR) {
|
||||||
case 'my-kv':
|
case 'my-kv':
|
||||||
return require('./config/prod-my-kv.env.js').default;
|
return require('./config/prod-my-kv.env.js').default
|
||||||
case 'my-dhf':
|
case 'my-dhf':
|
||||||
return require('./config/prod-dhf.env.js').default;
|
return require('./config/prod-dhf.env.js').default
|
||||||
case 'my-dha':
|
case 'my-dha':
|
||||||
return require('./config/prod-dha.env.js').default;
|
return require('./config/prod-dha.env.js').default
|
||||||
}
|
}
|
||||||
return {};
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function resolve(dir: string) {
|
function resolve(dir: string) {
|
||||||
return path.join(__dirname, dir);
|
return path.join(__dirname, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
const define = {
|
const define = {
|
||||||
'import.meta.env.HEP_URL': JSON.stringify(process.env.HEP_URL),
|
'import.meta.env.HEP_URL': JSON.stringify(process.env.HEP_URL),
|
||||||
'import.meta.env.MATOMO_HOST': JSON.stringify(process.env.MATOMO_HOST),
|
'import.meta.env.MATOMO_HOST': JSON.stringify(process.env.MATOMO_HOST),
|
||||||
'import.meta.env.MATOMO_SITE_ID': JSON.stringify(process.env.MATOMO_SITE_ID),
|
'import.meta.env.MATOMO_SITE_ID': JSON.stringify(process.env.MATOMO_SITE_ID),
|
||||||
'import.meta.env.LOGOUT_REDIRECT_URL': JSON.stringify(process.env.LOGOUT_REDIRECT_URL),
|
'import.meta.env.LOGOUT_REDIRECT_URL': JSON.stringify(
|
||||||
|
process.env.LOGOUT_REDIRECT_URL
|
||||||
|
),
|
||||||
'import.meta.env.VUE_APP_FLAVOR': JSON.stringify(process.env.APP_FLAVOR),
|
'import.meta.env.VUE_APP_FLAVOR': JSON.stringify(process.env.APP_FLAVOR),
|
||||||
'import.meta.env.SENTRY_DSN': JSON.stringify(process.env.SENTRY_JAVASCRIPT_DSN),
|
'import.meta.env.SENTRY_DSN': JSON.stringify(
|
||||||
|
process.env.SENTRY_JAVASCRIPT_DSN
|
||||||
|
),
|
||||||
'import.meta.env.SENTRY_ENVIRONMENT': JSON.stringify(process.env.SENTRY_ENV),
|
'import.meta.env.SENTRY_ENVIRONMENT': JSON.stringify(process.env.SENTRY_ENV),
|
||||||
/*
|
/*
|
||||||
* ENV variables used in JS code need to be stringyfied, as they will be replaced (in place) in the code,
|
* ENV variables used in JS code need to be stringyfied, as they will be replaced (in place) in the code,
|
||||||
|
|
@ -35,56 +37,54 @@ const define = {
|
||||||
* see https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code
|
* see https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code
|
||||||
*/
|
*/
|
||||||
'import.meta.env.VUE_APP_ENABLE_SPELLCHECK': !!process.env.TASKBASE_BASEURL,
|
'import.meta.env.VUE_APP_ENABLE_SPELLCHECK': !!process.env.TASKBASE_BASEURL,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const flavorConfig = getFlavorConfig();
|
const flavorConfig = getFlavorConfig()
|
||||||
|
|
||||||
const htmlPlugin = () => {
|
const htmlPlugin = () => {
|
||||||
return {
|
return {
|
||||||
name: 'html-transform',
|
name: 'html-transform',
|
||||||
transformIndexHtml(html: string) {
|
transformIndexHtml(html: string) {
|
||||||
return html.replace(
|
return html
|
||||||
/_APP_TITLE_/,
|
.replace(/_APP_TITLE_/, flavorConfig.VUE_APP_TITLE || 'mySkillbox')
|
||||||
flavorConfig.VUE_APP_TITLE || 'mySkillbox'
|
.replace(
|
||||||
).replace(
|
/_FAVICON_16_/,
|
||||||
/_FAVICON_16_/,
|
flavorConfig.VUE_APP_FAVICON_16 || '/static/favicon-16x16.png'
|
||||||
flavorConfig.VUE_APP_FAVICON_16 || '/static/favicon-16x16.png'
|
)
|
||||||
).replace(
|
.replace(
|
||||||
/_FAVICON_32_/,
|
/_FAVICON_32_/,
|
||||||
flavorConfig.VUE_APP_FAVICON_32 || '/static/favicon-32x32.png'
|
flavorConfig.VUE_APP_FAVICON_32 || '/static/favicon-32x32.png'
|
||||||
);
|
)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: '/static/',
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
scss: {
|
scss: {
|
||||||
additionalData: process.env.THEME ? `@import "styles/themes/_${process.env.THEME}.scss";` : '',
|
additionalData: process.env.THEME
|
||||||
}
|
? `@import "styles/themes/_${process.env.THEME}.scss";`
|
||||||
|
: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devSourcemap: true
|
devSourcemap: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve('./src'),
|
'@': resolve('./src'),
|
||||||
styles: resolve('./src/styles'),
|
styles: resolve('./src/styles'),
|
||||||
gql: resolve('./src/graphql/gql'),
|
gql: resolve('./src/graphql/gql'),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
port: 8080,
|
port: 8080,
|
||||||
hmr: {
|
hmr: {
|
||||||
clientPort: 8080
|
clientPort: 8080,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [gql(), vue(), htmlPlugin()],
|
||||||
gql(),
|
define,
|
||||||
vue(),
|
|
||||||
htmlPlugin()
|
|
||||||
],
|
|
||||||
define
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
|
|
||||||
STATICFILES_DIRS = (
|
STATICFILES_DIRS = (
|
||||||
os.path.join(BASE_DIR, "..", "client/dist/static"),
|
os.path.join(BASE_DIR, "..", "client/dist"),
|
||||||
os.path.join(BASE_DIR, "..", "client/src/assets"),
|
os.path.join(BASE_DIR, "..", "client/src/assets"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue