UNPKG

2.88 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const path_1 = __importDefault(require("path"));
7const defu_1 = require("defu");
8const consola_1 = __importDefault(require("consola"));
9const defaults = {
10 ignoreNotFoundWarnings: false,
11 typeCheck: true
12};
13const tsModule = function (moduleOptions) {
14 // Combine options
15 const options = (0, defu_1.defu)(this.options.typescript, moduleOptions, defaults);
16 // Change color of CLI banner
17 this.options.cli.bannerColor = 'blue';
18 if (!this.options.extensions.includes('ts')) {
19 this.options.extensions.push('ts');
20 }
21 // Extend Builder to handle .ts/.tsx files as routes and watch them
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 // eslint-disable-next-line @typescript-eslint/no-var-requires
42 const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
43 const logger = consola_1.default.withTag('nuxt:typescript');
44 /* istanbul ignore next */
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};
64exports.default = tsModule;
65//# sourceMappingURL=index.js.map
\No newline at end of file