[6a3a178] | 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 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.getTypescriptWorkerPlugin = exports.getTypeScriptConfig = void 0;
|
---|
| 11 | const core_1 = require("@angular-devkit/core");
|
---|
| 12 | const webpack_1 = require("@ngtools/webpack");
|
---|
| 13 | function ensureIvy(wco) {
|
---|
| 14 | if (wco.tsConfig.options.enableIvy !== false) {
|
---|
| 15 | return;
|
---|
| 16 | }
|
---|
| 17 | wco.logger.warn('Project is attempting to disable the Ivy compiler. ' +
|
---|
| 18 | 'Angular versions 12 and higher do not support the deprecated View Engine compiler for applications. ' +
|
---|
| 19 | 'The Ivy compiler will be used to build this project. ' +
|
---|
| 20 | '\nFor additional information or if the build fails, please see https://angular.io/guide/ivy');
|
---|
| 21 | wco.tsConfig.options.enableIvy = true;
|
---|
| 22 | }
|
---|
| 23 | function createIvyPlugin(wco, aot, tsconfig) {
|
---|
| 24 | const { buildOptions } = wco;
|
---|
| 25 | const optimize = buildOptions.optimization.scripts;
|
---|
| 26 | const compilerOptions = {
|
---|
| 27 | sourceMap: buildOptions.sourceMap.scripts,
|
---|
| 28 | declaration: false,
|
---|
| 29 | declarationMap: false,
|
---|
| 30 | };
|
---|
| 31 | if (buildOptions.preserveSymlinks !== undefined) {
|
---|
| 32 | compilerOptions.preserveSymlinks = buildOptions.preserveSymlinks;
|
---|
| 33 | }
|
---|
| 34 | const fileReplacements = {};
|
---|
| 35 | if (buildOptions.fileReplacements) {
|
---|
| 36 | for (const replacement of buildOptions.fileReplacements) {
|
---|
| 37 | fileReplacements[core_1.getSystemPath(replacement.replace)] = core_1.getSystemPath(replacement.with);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | let inlineStyleFileExtension;
|
---|
| 41 | switch (buildOptions.inlineStyleLanguage) {
|
---|
| 42 | case 'less':
|
---|
| 43 | inlineStyleFileExtension = 'less';
|
---|
| 44 | break;
|
---|
| 45 | case 'sass':
|
---|
| 46 | inlineStyleFileExtension = 'sass';
|
---|
| 47 | break;
|
---|
| 48 | case 'scss':
|
---|
| 49 | inlineStyleFileExtension = 'scss';
|
---|
| 50 | break;
|
---|
| 51 | case 'css':
|
---|
| 52 | default:
|
---|
| 53 | inlineStyleFileExtension = 'css';
|
---|
| 54 | break;
|
---|
| 55 | }
|
---|
| 56 | return new webpack_1.AngularWebpackPlugin({
|
---|
| 57 | tsconfig,
|
---|
| 58 | compilerOptions,
|
---|
| 59 | fileReplacements,
|
---|
| 60 | jitMode: !aot,
|
---|
| 61 | emitNgModuleScope: !optimize,
|
---|
| 62 | inlineStyleFileExtension,
|
---|
| 63 | });
|
---|
| 64 | }
|
---|
| 65 | function getTypeScriptConfig(wco) {
|
---|
| 66 | const { buildOptions: { aot = false, main, polyfills }, tsConfigPath, } = wco;
|
---|
| 67 | if (main || polyfills) {
|
---|
| 68 | ensureIvy(wco);
|
---|
| 69 | return {
|
---|
| 70 | module: {
|
---|
| 71 | rules: [
|
---|
| 72 | {
|
---|
| 73 | test: /\.[jt]sx?$/,
|
---|
| 74 | loader: webpack_1.AngularWebpackLoaderPath,
|
---|
| 75 | },
|
---|
| 76 | ],
|
---|
| 77 | },
|
---|
| 78 | plugins: [createIvyPlugin(wco, aot, tsConfigPath)],
|
---|
| 79 | };
|
---|
| 80 | }
|
---|
| 81 | return {};
|
---|
| 82 | }
|
---|
| 83 | exports.getTypeScriptConfig = getTypeScriptConfig;
|
---|
| 84 | function getTypescriptWorkerPlugin(wco, workerTsConfigPath) {
|
---|
| 85 | return createIvyPlugin(wco, false, workerTsConfigPath);
|
---|
| 86 | }
|
---|
| 87 | exports.getTypescriptWorkerPlugin = getTypescriptWorkerPlugin;
|
---|