ng-afelio
Version:
Extended Angular CLI
47 lines (46 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = require("@ngtools/webpack");
const take_until_destroy_transformer_1 = require("./ts-transformers/take-until-destroy.transformer");
// import { getSourceFile } from './webpack-compiler-host';
// WebpackCompilerHost.prototype.getSourceFile = getSourceFile;
function findAngularCompilerPlugin(webpackCfg) {
var _a;
return (_a = webpackCfg === null || webpackCfg === void 0 ? void 0 : webpackCfg.plugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => {
var _a;
return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'AngularWebpackPlugin';
});
}
// function isJitMode(acp: AngularWebpackPlugin) {
// return acp.options.jitMode;
// }
function addTransformerToAngularCompilerPlugin(acp, transformer) {
acp._transformers = [transformer, ...acp._transformers];
}
exports.default = {
config(webpackConfig) {
if (webpackConfig.plugins && webpackConfig.plugins.length > 0) {
const acp = findAngularCompilerPlugin(webpackConfig);
if (!acp) {
throw new Error('AngularWebpackPlugin not found');
}
const options = {
...acp.options,
// directTemplateLoading: false,
};
webpackConfig.plugins = webpackConfig.plugins.filter(plugin => plugin !== acp);
const newCompilerPlugin = new webpack_1.AngularWebpackPlugin(options);
// if (isJitMode(acp)) {
addTransformerToAngularCompilerPlugin(newCompilerPlugin, take_until_destroy_transformer_1.takeUntilDestroyTransformer);
// }
webpackConfig.plugins.push(newCompilerPlugin);
}
return webpackConfig;
},
// pre(builderConfig: any) {
// console.debug('pre', builderConfig);
// },
// post() {
// console.debug('post');
// },
};