1
1
import path from 'path'
2
2
import { defu } from 'defu'
3
- import consola from 'consola'
4
3
import type { Module } from '@nuxt/types'
5
4
import type { Options as TsLoaderOptions } from 'ts-loader'
6
5
import type { ForkTsCheckerWebpackPluginOptions as TsCheckerOptions } from 'fork-ts-checker-webpack-plugin/lib/ForkTsCheckerWebpackPluginOptions'
7
- import type TsCheckerLogger from 'fork-ts-checker-webpack-plugin/lib/logger/Logger'
8
6
import type { RuleSetUseItem } from 'webpack'
9
7
import { NormalModuleReplacementPlugin } from 'webpack'
10
8
@@ -48,7 +46,7 @@ const tsModule: Module<Options> = function (moduleOptions) {
48
46
)
49
47
}
50
48
51
- this . extendBuild ( ( config , { isClient , isModern } ) => {
49
+ this . extendBuild ( ( config , { _isClient , _isModern } ) => {
52
50
config . resolve ! . extensions ! . push ( '.ts' , '.tsx' )
53
51
54
52
// Add alias for @babel /runtime/helpers
@@ -61,7 +59,68 @@ const tsModule: Module<Options> = function (moduleOptions) {
61
59
const babelLoader = jsxRuleLoaders [ jsxRuleLoaders . length - 1 ]
62
60
63
61
config . module ! . rules . push ( ...( [ 'ts' , 'tsx' ] as const ) . map ( ext => ( {
64
- test : new RegExp ( `\.${ ext } $` ) ,
62
+ test : new RegExp ( `\.${ ext } import path from 'path '
63
+ import { defu } from 'defu '
64
+ import type { Module } from '@nuxt/types'
65
+ import type { Options as TsLoaderOptions } from 'ts-loader'
66
+ import type { ForkTsCheckerWebpackPluginOptions as TsCheckerOptions } from 'fork-ts-checker-webpack-plugin/lib/ForkTsCheckerWebpackPluginOptions'
67
+ import type { RuleSetUseItem } from 'webpack'
68
+ import { NormalModuleReplacementPlugin } from 'webpack'
69
+
70
+ export interface Options {
71
+ ignoreNotFoundWarnings ?: boolean
72
+ loaders ?: {
73
+ ts ?: Partial < TsLoaderOptions >
74
+ tsx ?: Partial < TsLoaderOptions >
75
+ }
76
+ typeCheck ?: TsCheckerOptions | boolean
77
+ }
78
+
79
+ declare module '@nuxt/types' {
80
+ interface NuxtOptions {
81
+ typescript : Options
82
+ }
83
+ }
84
+
85
+ const defaults : Options = {
86
+ ignoreNotFoundWarnings : false ,
87
+ typeCheck : true
88
+ }
89
+
90
+ const tsModule : Module < Options > = function ( moduleOptions ) {
91
+ // Combine options
92
+ const options = defu ( this . options . typescript , moduleOptions , defaults )
93
+
94
+ // Change color of CLI banner
95
+ this . options . cli . bannerColor = 'blue'
96
+
97
+ if ( ! this . options . extensions . includes ( 'ts' ) ) {
98
+ this . options . extensions . push ( 'ts' )
99
+ }
100
+
101
+ // Extend Builder to handle .ts/.tsx files as routes and watch them
102
+ this . options . build . additionalExtensions = [ 'ts' , 'tsx' ]
103
+
104
+ if ( options . ignoreNotFoundWarnings ) {
105
+ this . options . build . warningIgnoreFilters ! . push ( warn =>
106
+ warn . name === 'ModuleDependencyWarning' && / e x p o r t .* w a s n o t f o u n d i n / . test ( warn . message )
107
+ )
108
+ }
109
+
110
+ this . extendBuild ( ( config , { _isClient, _isModern } ) => {
111
+ config . resolve ! . extensions ! . push ( '.ts' , '.tsx' )
112
+
113
+ // Add alias for @babel /runtime/helpers
114
+ config . resolve ! . alias = {
115
+ ...config . resolve ! . alias ,
116
+ '@babel/runtime/helpers' : path . resolve ( this . options . rootDir ! , 'node_modules/@babel/runtime/helpers' )
117
+ }
118
+
119
+ const jsxRuleLoaders = config . module ! . rules . find ( r => ( r . test as RegExp ) . test ( '.jsx' ) ) ! . use as RuleSetUseItem [ ]
120
+ const babelLoader = jsxRuleLoaders [ jsxRuleLoaders . length - 1 ]
121
+
122
+ config . module ! . rules . push ( ...( [ 'ts' , 'tsx' ] as const ) . map ( ext => ( {
123
+ ) ,
65
124
use : [
66
125
babelLoader ,
67
126
{
@@ -88,4 +147,6 @@ const tsModule: Module<Options> = function (moduleOptions) {
88
147
}
89
148
}
90
149
) )
91
- }
150
+ }
151
+ } )
152
+ }
0 commit comments