1

I'm pretty new to using Typescript and Angular 4, and I am having trouble integrating Google Code-Prettify with the angular CLI setup.

I am trying to figure out how to import code-prettify to use dynamically with my components, but I am unsure how to accomplish this.

I've tried installing with NPM and importing PR from the package, but PR comes in as an empty object.

Is there a way to accomplish what I am trying to do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dev_pool
  • 203
  • 4
  • 14

1 Answers1

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();
Hai.Xu
  • 50
  • 8