nuxt / typescript

TypeScript Support for Nuxt 2
https://typescript.nuxtjs.org
MIT License
570 stars 124 forks source link

Allow for specifying TypeScript configuration #301

Closed Roms1383 closed 4 years ago

Roms1383 commented 4 years ago

Is your feature request related to a problem? Please describe. I tried to implement a project in a micro-service / micro-frontend way, having sourcecode for the app part in./src/app (using for example Vue.js / Nuxt.js / Vuex / Storybook) and sourcecode for the server part in ./src/server (using for example Nest.js / Serverless) respectively.

Currently I can't override on the fly my ./tsconfig.json directly in nuxt.config.ts (I tried different approaches, dug into the sourcecode, no matter how changes were ignored), neither was I able to directly specify the path to a different file, e.g. ./tsconfig.app.json.

The reason why I need this is that I need to transpile them differently : app part

{
  "compilerOptions": {
    "rootDir": "src/app",
    "outDir": "dist",
    "target": "es2018",
    "module": "esnext",
    ...
    "types" : ["node", "@types/jest", "@nuxt/types","@nuxt/vue-app","@nuxtjs/vuetify"],
    ...
  },
  "exclude": [
    "**/*.spec.ts",
    "**/*.test.ts",
    "node_modules",
    "lib",
    "dist",
    "nuxt.config.ts",
    "src/app/**/*.stories.[tj]s"
  ]
}

server part

{
  "compilerOptions": {
    "rootDir": "src/server",
    "outDir": "lib",
    "target": "es6",
    "module": "commonjs",
    ...
    "types" : ["node", "@types/jest", "@types/joi", "@types/mongoose"],
    ...
  },
  "exclude": [
    "**/*.spec.ts",
    "**/*.test.ts",
    "node_modules",
    "lib",
    "dist",
    "nuxt.config.ts",
    "src/server/seeds/**",
    "src/server/generate/**"
  ]
}

Describe the solution you'd like IMHO nuxt-ts should provide the same mechanism as TypeScript already offers to override transpilation options (e.g. support for compilerOptions, --project and so on). It should also be available without having to hook a custom Webpack configuration.

Describe alternatives you've considered My current solution was to use ./tsconfig.json for the app part while specifying a tsconfig.server.json for the server part (this works like a charm), but I'm not quite satisfied with it (it could actually bring more confusion in a real-world project with teams of multiple people).

Additional context Not that I'm thinking of.

kevinmarrec commented 4 years ago

@Roms1383 Sorry if it's likely not documented, but you can try --tsconfig [path/to/file] : https://github.com/nuxt/typescript/blob/master/packages/typescript-runtime/src/index.ts#L7

Roms1383 commented 4 years ago

Thanks @kevinmarrec but I've already tried and there's still some plugin / webpack thingy messin' up somewhere.

I can guess from the stacktrace that it's probably something easy to fix, but I'm just beginning with both Nuxt and Webpack :

$ yarn nuxt-ts --tsconfig tsconfig.app.json
...                                                                                                                                                                              
 ERROR  Cannot find "/Users/*****/development/sample-project/tsconfig.json" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration.

Possible errors: 
  - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in fork plugin configuration)
  - wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)

  Possible errors:
  - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in fork plugin configuration)
  - wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)
  at ForkTsCheckerWebpackPlugin.apply (node_modules/fork-ts-checker-webpack-plugin/lib/index.ts:294:13)
  at webpack (node_modules/webpack/lib/webpack.js:51:13)
  at compilers.webpackConfigs.map (node_modules/@nuxt/webpack/dist/webpack.js:5255:24)
  at Array.map (<anonymous>)
  at WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5254:37)

I went so far as to try many combos in nuxt.config.js and also output my webpack context to the console but I can't find the remaining setting pointing out to tsconfig.json yet.

Roms1383 commented 4 years ago

Wouldn't it be related to https://github.com/nuxt/typescript/blob/826234b5ff24a90e771d10b1029d1adabd8de6fb/packages/typescript-build/src/index.ts#L79 ?

Original error points out here https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/blob/d083fc854389ef9c9f6c430e4345afde24c0bc7a/src/index.ts#L294

Roms1383 commented 4 years ago

Actually the error is here https://github.com/nuxt/typescript/blob/826234b5ff24a90e771d10b1029d1adabd8de6fb/packages/typescript-build/src/index.ts#L79 : tsconfig setting is not provided to the plugin.

Roms1383 commented 4 years ago

Switched to Bug report : Issue with custom TypeScript file