Typescript: ts-loader options.

Created on 22 Aug 2019  路  3Comments  路  Source: nuxt/typescript

I'm using express + nuxt with full stack Typescript.

In tsconfig.json I must set compilerOptions -> module to "commonjs" , In this case express will working properly, but not fit for nuxt.

Before nuxt < 2.8.x, I will override ts-loader options in nuxt.config.ts build.loaders.ts.compilerOptions or build.loaders.ts.configFile to use different typescript rules.

But now I migrated Nuxt from 2.8.x to 2.9.x, follow https://typescript.nuxtjs.org/migration.html instruction, As mentioned previously way is not working anymore (because typescript-build is way behind default settings?).

So I checked that typescript-build module, no any options can pass to ts-loader.

This is my modify version:
ex.
nuxt.config.ts

typescript: {
    typeCheck: true,
    loaderOptions: {
      compileOptions: {
             target: "esnext",
             module: "commonjs"
      }
    }
  },

ex.
typescript-build/lib/module.js

config.module.rules.push(...['ts', 'tsx'].map(ext =>
      ({
        test: new RegExp(`\\.${ext}$`, 'i'),
        use: [
          babelLoader,
          {
            loader: 'ts-loader',
            ...Object.assign({}, {
              transpileOnly: true,
              [`append${ext.charAt(0).toUpperCase() + ext.slice(1)}SuffixTo`]: [/\.vue$/]
            }, loaderOptions)
          }
        ]
      })
    ))

Or any better way can do?

feature request has PR build

Most helpful comment

Indeed, in Nuxt 2.8.x , the ts & tsx loaders (build.loaders.x) were registered in core, so the options could be customizable through configuration file, it's indeed not possible anymore.

So yes you're right, the module should provide options to customize them.
Not only ts loader but also tsx one.

I'll take care having this feature available as soon as possible (~within next 6 hours~ this end of week), as it makes setups like yours not able to use Nuxt 2.9 if i'm right.

All 3 comments

Indeed, in Nuxt 2.8.x , the ts & tsx loaders (build.loaders.x) were registered in core, so the options could be customizable through configuration file, it's indeed not possible anymore.

So yes you're right, the module should provide options to customize them.
Not only ts loader but also tsx one.

I'll take care having this feature available as soon as possible (~within next 6 hours~ this end of week), as it makes setups like yours not able to use Nuxt 2.9 if i'm right.

Great!!! thank you.

@steven0811 Could you quick check https://github.com/nuxt/typescript/pull/93 ?

Was this page helpful?
0 / 5 - 0 ratings