1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const path_1 = __importDefault(require("path"));
|
7 | const consola_1 = __importDefault(require("consola"));
|
8 | const defaults = {
|
9 | ignoreNotFoundWarnings: false,
|
10 | typeCheck: true
|
11 | };
|
12 | const tsModule = function (moduleOptions) {
|
13 |
|
14 | const options = Object.assign(defaults, this.options.typescript, moduleOptions);
|
15 |
|
16 | this.options.cli.bannerColor = 'blue';
|
17 | if (!this.options.extensions.includes('ts')) {
|
18 | this.options.extensions.push('ts');
|
19 | }
|
20 |
|
21 | this.options.build.additionalExtensions = ['ts', 'tsx'];
|
22 | if (options.ignoreNotFoundWarnings) {
|
23 | this.options.build.warningIgnoreFilters.push(warn => warn.name === 'ModuleDependencyWarning' && /export .* was not found in /.test(warn.message));
|
24 | }
|
25 | this.extendBuild((config, { isClient, isModern }) => {
|
26 | config.resolve.extensions.push('.ts', '.tsx');
|
27 | const jsxRuleLoaders = config.module.rules.find(r => r.test.test('.jsx')).use;
|
28 | const babelLoader = jsxRuleLoaders[jsxRuleLoaders.length - 1];
|
29 | config.module.rules.push(...['ts', 'tsx'].map(ext => ({
|
30 | test: new RegExp(`\\.${ext}$`, 'i'),
|
31 | use: [
|
32 | babelLoader,
|
33 | {
|
34 | loader: 'ts-loader',
|
35 | options: Object.assign({ transpileOnly: true, appendTsxSuffixTo: ext === 'tsx' ? [/\.vue$/] : [] }, (options.loaders && options.loaders[ext]))
|
36 | }
|
37 | ]
|
38 | })));
|
39 | if (options.typeCheck && isClient && !isModern) {
|
40 | const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
41 | config.plugins.push(new ForkTsCheckerWebpackPlugin(Object.assign({
|
42 | typescript: {
|
43 | configFile: path_1.default.resolve(this.options.rootDir, 'tsconfig.json'),
|
44 | extensions: {
|
45 | vue: true
|
46 | }
|
47 | },
|
48 | logger: consola_1.default.withScope('nuxt:typescript')
|
49 | }, options.typeCheck)));
|
50 | }
|
51 | });
|
52 | };
|
53 | exports.default = tsModule;
|
54 |
|
\ | No newline at end of file |