使用 Google Code-Prettify with Typescript 和 Angular 4

Using Google Code-Prettify with Typescript and Angular 4

我刚开始使用 Typescript 和 Angular 4,我在将 Google Code-Prettify 与 angular CLI 设置集成时遇到了问题。

我正在尝试弄清楚如何导入代码美化以动态地与我的组件一起使用,但我不确定如何完成此操作。

我试过使用 NPM 安装并从包中导入 PR,但 PR 以空对象的形式出现。

有什么方法可以完成我想做的事情吗?

you can change some code in prettify.js:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre><code>//old code in here
if (typeof define === "function" && define['amd']) {
    define("google-code-prettify", [], function () {
     return PR;
     });
}
//new code in here
      
if(typeof module==="object"&&typeof module.exports==="object") {
    module.exports = PR;
} else if (typeof define === "function" && define['amd']) {
    define("google-code-prettify", [], function () {
     return PR;
    });
}
use case like this:
let prettify = require('../../dep/prettify');
$("#doc-view").html(virtualDom);
prettify.prettyPrint();