让MathJax处理角度cli项目

时间:2017-04-03 11:00:46

标签: angular webpack angular-cli mathjax

我希望能够在@ angular / cli项目中使用MathJax。我之前有一个使用systemjs的Angular 2项目,这不是问题。然而,角度cli切换到使用webpack,我似乎无法让这个新项目工作。

我相信我遵循了here描述的全局库安装的所有说明,但我可能会误解某些内容。

我建立了一个回购展示了正在发生的事情。可以看到here

基本上,我所做的是安装@ angular / cli并将yarn设置为其默认包管理器。

我用

开始了这个项目
ng new math-bug

我用

安装了依赖项
yarn add express body-parser mathjax mongoose
yarn add @types\mathjax --dev

我修改了文件.angular-cli.json,将以下内容添加到scripts数组中(以前为空)。

"../node_modules/mathjax/MathJax.js"

我在项目中添加了一个使用以下行的组件:

"MathJax.Hub.Queue([ "Typeset", MathJax.Hub, this.id]);"

但是当我尝试使用ng build构建我的项目时,我收到以下错误: 当我构建我的项目时,我收到错误:

ERROR in C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,9): Cannot find name 'MathJax'.
C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,40): Cannot find name 'MathJax'.

额外的信息,如果它有用 - 我在Windows 10上运行它,当我运行--version时,这是输出:

@angular/cli: 1.0.0
node: 7.2.1
os: win32 x64
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

1 个答案:

答案 0 :(得分:0)

src/tsconfig.app.json中将mathjax添加到types,如下所示:

"types": ["mathjax"]

如果您还打算使用mathjax进行测试,请将相同的内容添加到src/tsconfig.spec.json

请点击此处typeshttps://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types