(ts) reference multiple configuration files for better separation between app, server and shared

This commit is contained in:
Valentyne Stigloher 2025-07-23 16:09:46 +02:00
parent 72d574a039
commit d6fa269699
4 changed files with 40 additions and 25 deletions

View File

@ -112,7 +112,6 @@ build:
artifacts: artifacts:
access: developer access: developer
paths: paths:
- '.nuxt/tsconfig.json'
- '.output' - '.output'
- 'locale' - 'locale'
- 'migrations' - 'migrations'
@ -129,7 +128,6 @@ build:
- 'package.json' - 'package.json'
- 'pnpm-lock.yaml' - 'pnpm-lock.yaml'
- 'run-wrapper.sh' - 'run-wrapper.sh'
- 'tsconfig.json'
exclude: exclude:
- 'locale/*/docs/*' - 'locale/*/docs/*'
- 'locale/*/img/*' - 'locale/*/img/*'

View File

@ -11,7 +11,7 @@ const __dirname = new URL('.', import.meta.url).pathname;
const generateJsonSchema = async (path: string, typeName: string) => { const generateJsonSchema = async (path: string, typeName: string) => {
const schema = createGenerator({ const schema = createGenerator({
path, path,
tsconfig: `${__dirname}/../tsconfig.json`, tsconfig: `${__dirname}/../.nuxt/tsconfig.node.json`,
strictTuples: true, strictTuples: true,
markdownDescription: true, markdownDescription: true,
// speed up schema generation; type checking happens separately // speed up schema generation; type checking happens separately

View File

@ -61,11 +61,9 @@ if (process.platform === 'win32') {
__dirname = __dirname.slice(1); __dirname = __dirname.slice(1);
} }
const tsConfig = { const compilerOptions = {
compilerOptions: {
allowImportingTsExtensions: true, allowImportingTsExtensions: true,
noUncheckedIndexedAccess: false, noUncheckedIndexedAccess: false,
},
}; };
const esBuildOptions = { const esBuildOptions = {
@ -128,7 +126,9 @@ export default defineNuxtConfig({
compatibilityDate: '2024-07-06', compatibilityDate: '2024-07-06',
nitro: { nitro: {
typescript: { typescript: {
tsConfig, tsConfig: {
compilerOptions,
},
}, },
rollupConfig: { rollupConfig: {
external: [ external: [
@ -230,7 +230,24 @@ export default defineNuxtConfig({
typescript: { typescript: {
typeCheck: !process.env.RUN_SNAPSHOT_TESTS && typeCheck: !process.env.RUN_SNAPSHOT_TESTS &&
(process.env.APP_ENV || process.env.NODE_ENV) !== 'production', (process.env.APP_ENV || process.env.NODE_ENV) !== 'production',
tsConfig, tsConfig: {
compilerOptions,
include: ['../locale/**/*.vue'],
},
nodeTsConfig: {
compilerOptions: {
...compilerOptions,
paths: {
'~~/*': ['../*'],
},
},
include: ['../eslint.config.ts', '../vitest.config.ts', '../shared/types/*.d.ts'],
},
sharedTsConfig: {
compilerOptions,
include: ['../locale/**/*'],
exclude: ['../locale/**/*.vue'],
},
}, },
postcss: { postcss: {
plugins: { plugins: {
@ -240,11 +257,6 @@ export default defineNuxtConfig({
}, },
}, },
hooks: { hooks: {
'prepare:types'({ nodeTsConfig, sharedTsConfig }) {
// somewhy, allowImportingTsExtensions is ignored in Nuxt
nodeTsConfig.compilerOptions = { ...nodeTsConfig.compilerOptions, ...tsConfig.compilerOptions };
sharedTsConfig.compilerOptions = { ...sharedTsConfig.compilerOptions, ...tsConfig.compilerOptions };
},
async 'pages:extend'(routes) { async 'pages:extend'(routes) {
for (const code of codes) { for (const code of codes) {
for (const subroute of configByLocale[code].nouns.subroutes || []) { for (const subroute of configByLocale[code].nouns.subroutes || []) {

View File

@ -1,12 +1,17 @@
{ {
"extends": "./.nuxt/tsconfig.json", "files": [],
"exclude": [ "references": [
"new", {
"logs", "path": "./.nuxt/tsconfig.app.json"
"census" },
], {
"ts-node": { "path": "./.nuxt/tsconfig.server.json"
// skip type checking as it causes some problems with CommonJS dependencies; type checking happens separately },
"transpileOnly": true {
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
} }
]
} }