(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:
access: developer
paths:
- '.nuxt/tsconfig.json'
- '.output'
- 'locale'
- 'migrations'
@ -129,7 +128,6 @@ build:
- 'package.json'
- 'pnpm-lock.yaml'
- 'run-wrapper.sh'
- 'tsconfig.json'
exclude:
- 'locale/*/docs/*'
- 'locale/*/img/*'

View File

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

View File

@ -61,11 +61,9 @@ if (process.platform === 'win32') {
__dirname = __dirname.slice(1);
}
const tsConfig = {
compilerOptions: {
allowImportingTsExtensions: true,
noUncheckedIndexedAccess: false,
},
const compilerOptions = {
allowImportingTsExtensions: true,
noUncheckedIndexedAccess: false,
};
const esBuildOptions = {
@ -128,7 +126,9 @@ export default defineNuxtConfig({
compatibilityDate: '2024-07-06',
nitro: {
typescript: {
tsConfig,
tsConfig: {
compilerOptions,
},
},
rollupConfig: {
external: [
@ -230,7 +230,24 @@ export default defineNuxtConfig({
typescript: {
typeCheck: !process.env.RUN_SNAPSHOT_TESTS &&
(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: {
plugins: {
@ -240,11 +257,6 @@ export default defineNuxtConfig({
},
},
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) {
for (const code of codes) {
for (const subroute of configByLocale[code].nouns.subroutes || []) {

View File

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