1

我对使用 Typescript 和 Angular 4 非常陌生,并且在将 Google Code-Prettify 与 angular CLI 设置集成时遇到了麻烦。

我试图弄清楚如何导入代码美化以与我的组件一起动态使用,但我不确定如何实现这一点。

我尝试使用 NPM 安装并从包中导入 PR,但 PR 作为一个空对象出现。

有没有办法完成我想做的事情?

4

1 回答 1

1
you can change some code in prettify.js:

//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();
于 2017-04-17T09:05:42.263 回答