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