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