1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
10 | if (k2 === undefined) k2 = k;
|
---|
11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
12 | }) : (function(o, m, k, k2) {
|
---|
13 | if (k2 === undefined) k2 = k;
|
---|
14 | o[k2] = m[k];
|
---|
15 | }));
|
---|
16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
18 | }) : function(o, v) {
|
---|
19 | o["default"] = v;
|
---|
20 | });
|
---|
21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
22 | if (mod && mod.__esModule) return mod;
|
---|
23 | var result = {};
|
---|
24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
25 | __setModuleDefault(result, mod);
|
---|
26 | return result;
|
---|
27 | };
|
---|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
29 | exports.getTestConfig = void 0;
|
---|
30 | const glob = __importStar(require("glob"));
|
---|
31 | const path = __importStar(require("path"));
|
---|
32 | const typescript_1 = require("typescript");
|
---|
33 | const helpers_1 = require("../utils/helpers");
|
---|
34 | function getTestConfig(wco) {
|
---|
35 | const { buildOptions: { codeCoverage, codeCoverageExclude, main, sourceMap, webWorkerTsConfig }, root, sourceRoot, } = wco;
|
---|
36 | const extraRules = [];
|
---|
37 | const extraPlugins = [];
|
---|
38 | if (codeCoverage) {
|
---|
39 | const exclude = [/\.(e2e|spec)\.tsx?$/, /node_modules/];
|
---|
40 | if (codeCoverageExclude) {
|
---|
41 | for (const excludeGlob of codeCoverageExclude) {
|
---|
42 | glob
|
---|
43 | .sync(path.join(root, excludeGlob), { nodir: true })
|
---|
44 | .forEach((file) => exclude.push(path.normalize(file)));
|
---|
45 | }
|
---|
46 | }
|
---|
47 | extraRules.push({
|
---|
48 | test: /\.(jsx?|tsx?)$/,
|
---|
49 | loader: require.resolve('@jsdevtools/coverage-istanbul-loader'),
|
---|
50 | options: { esModules: true },
|
---|
51 | enforce: 'post',
|
---|
52 | exclude,
|
---|
53 | include: sourceRoot,
|
---|
54 | });
|
---|
55 | }
|
---|
56 | if (sourceMap.scripts || sourceMap.styles) {
|
---|
57 | extraPlugins.push(helpers_1.getSourceMapDevTool(sourceMap.scripts, sourceMap.styles, false, true));
|
---|
58 | }
|
---|
59 | return {
|
---|
60 | mode: 'development',
|
---|
61 | target: wco.tsConfig.options.target === typescript_1.ScriptTarget.ES5 ? ['web', 'es5'] : 'web',
|
---|
62 | resolve: {
|
---|
63 | mainFields: ['es2015', 'browser', 'module', 'main'],
|
---|
64 | conditionNames: ['es2015', '...'],
|
---|
65 | },
|
---|
66 | devtool: false,
|
---|
67 | entry: {
|
---|
68 | main: path.resolve(root, main),
|
---|
69 | },
|
---|
70 | module: {
|
---|
71 | rules: extraRules,
|
---|
72 | parser: webWorkerTsConfig === undefined
|
---|
73 | ? {
|
---|
74 | javascript: {
|
---|
75 | worker: false,
|
---|
76 | url: false,
|
---|
77 | },
|
---|
78 | }
|
---|
79 | : undefined,
|
---|
80 | },
|
---|
81 | plugins: extraPlugins,
|
---|
82 | optimization: {
|
---|
83 | splitChunks: {
|
---|
84 | chunks: (chunk) => !helpers_1.isPolyfillsEntry(chunk.name),
|
---|
85 | cacheGroups: {
|
---|
86 | vendors: false,
|
---|
87 | defaultVendors: {
|
---|
88 | name: 'vendor',
|
---|
89 | chunks: (chunk) => chunk.name === 'main',
|
---|
90 | enforce: true,
|
---|
91 | test: /[\\/]node_modules[\\/]/,
|
---|
92 | },
|
---|
93 | },
|
---|
94 | },
|
---|
95 | },
|
---|
96 | };
|
---|
97 | }
|
---|
98 | exports.getTestConfig = getTestConfig;
|
---|