mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-19 23:40:07 +00:00
refactor: split tauri config into module
This commit is contained in:
parent
44cf8aa89c
commit
2d49074242
5 changed files with 43 additions and 27 deletions
1
app.vue
1
app.vue
|
@ -1,6 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
setupI18n()
|
||||
setupLogging()
|
||||
setupPageHeader()
|
||||
provideGlobalCommands()
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import * as log from 'tauri-plugin-log-api'
|
||||
|
||||
// When running inside Tauri, catch all logs from 3rd party packages and direct them to the unified logging stream
|
||||
export function setupLogging() {
|
||||
if (import.meta.env.TAURI_PLATFORM) {
|
||||
// eslint-disable-next-line no-global-assign
|
||||
console = {
|
||||
...console,
|
||||
trace: log.trace,
|
||||
debug: log.debug,
|
||||
log: log.info,
|
||||
warn: log.warn,
|
||||
error: log.error,
|
||||
}
|
||||
|
||||
window.addEventListener('unhandledrejection', err =>
|
||||
log.error(err.reason),
|
||||
)
|
||||
window.addEventListener('error', err => log.error(err.error), true)
|
||||
}
|
||||
}
|
21
modules/tauri/index.ts
Normal file
21
modules/tauri/index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { addPlugin, createResolver, defineNuxtModule, useNuxt } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: {
|
||||
name: 'tauri',
|
||||
},
|
||||
setup() {
|
||||
const nuxt = useNuxt()
|
||||
const { resolve } = createResolver(import.meta.url)
|
||||
|
||||
if (!process.env.TAURI_PLATFORM)
|
||||
return
|
||||
|
||||
nuxt.hook('vite:extend', ({ config }) => {
|
||||
config.build!.target = ['es2021', 'chrome100', 'safari13']
|
||||
config.envPrefix = [...config.envPrefix || [], 'VITE_', 'TAURI_']
|
||||
})
|
||||
|
||||
addPlugin(resolve('./runtime/logging.client'))
|
||||
},
|
||||
})
|
19
modules/tauri/runtime/logging.client.ts
Normal file
19
modules/tauri/runtime/logging.client.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import * as log from 'tauri-plugin-log-api'
|
||||
|
||||
// When running inside Tauri, catch all logs from 3rd party packages and direct them to the unified logging stream
|
||||
export default defineNuxtPlugin(() => {
|
||||
// eslint-disable-next-line no-global-assign
|
||||
console = {
|
||||
...console,
|
||||
trace: log.trace,
|
||||
debug: log.debug,
|
||||
log: log.info,
|
||||
warn: log.warn,
|
||||
error: log.error,
|
||||
}
|
||||
|
||||
window.addEventListener('unhandledrejection', err =>
|
||||
log.error(err.reason),
|
||||
)
|
||||
window.addEventListener('error', err => log.error(err.error), true)
|
||||
})
|
|
@ -21,8 +21,10 @@ export default defineNuxtConfig({
|
|||
'~/modules/purge-comments',
|
||||
'~/modules/setup-components',
|
||||
'~/modules/pwa/index', // change to '@vite-pwa/nuxt' once released and remove pwa module
|
||||
'~/modules/tauri/index',
|
||||
],
|
||||
experimental: {
|
||||
payloadExtraction: false,
|
||||
reactivityTransform: true,
|
||||
inlineSSRStyles: false,
|
||||
},
|
||||
|
@ -38,10 +40,6 @@ export default defineNuxtConfig({
|
|||
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
|
||||
},
|
||||
vite: {
|
||||
// to make use of `TAURI_PLATFORM`, `TAURI_ARCH`, `TAURI_FAMILY`,
|
||||
// `TAURI_PLATFORM_VERSION`, `TAURI_PLATFORM_TYPE` and `TAURI_DEBUG`
|
||||
// env variables
|
||||
envPrefix: ['VITE_', 'TAURI_'],
|
||||
define: {
|
||||
'import.meta.env.__BUILD_TIME__': JSON.stringify(new Date().toISOString()),
|
||||
'import.meta.env.__BUILD_COMMIT__': JSON.stringify(process.env.COMMIT_REF || ''),
|
||||
|
@ -49,7 +47,7 @@ export default defineNuxtConfig({
|
|||
'process.mock': ((!isCI || isPreview) && process.env.MOCK_USER) || 'false',
|
||||
},
|
||||
build: {
|
||||
target: process.env.TAURI_PLATFORM ? ['es2021', 'chrome100', 'safari13'] : 'esnext',
|
||||
target: 'esnext',
|
||||
},
|
||||
plugins: [
|
||||
Inspect(),
|
||||
|
|
Loading…
Reference in a new issue