导入pdfmake.js文件到我的ts文件 [英] Import pdfmake.js file to my ts file
本文介绍了导入pdfmake.js文件到我的ts文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发vsts Web扩展.我想使用 PDFmake.js
文件生成一个 pdf
.通过作为 npm install pdfmake
安装,将 PDFmake.js
文件导入
到 node_nodules
文件夹中.
I am developing a vsts web extension .
I want a to use PDFmake.js
file to generate a pdf
.
PDFmake.js
file is imported
to node_nodules
folder by installing as npm install pdfmake
.
我想将此 js文件
导入到我的 ts文件
中.这就是我的做法,
I want to import
this js file
to my ts file
.
this is how i am doing ,
import pdfmake = require("../node_modules/pdfmake/build/pdfmake");
它给了我下面的错误.
Severity Code Description Project File Line Suppression State
Error TS5055 Cannot write file 'D:/TFS/DM Helper Tools/DEV/WebExtension/RapidCCB/build/pdfmake.js' because it would overwrite input file. <Unknown> 1 Active
推荐答案
遵循以下说明:
首先
npm install pdfmake --save
第二,在下面添加到 typings.d.ts :
declare module 'pdfmake/build/pdfmake.js';
declare module 'pdfmake/build/vfs_fonts.js';
第三,在使用pdfMake的文件(组件或服务)中,添加以下几行:
Third, in the file where pdfMake is being used, either component or service, add below lines:
import * as pdfMake from 'pdfmake/build/pdfmake.js';
import * as pdfFonts from 'pdfmake/build/vfs_fonts.js';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"target": "ES5",
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"typeRoots": [],
"types": [] //Explicitly specify an empty array so that the TS2 @types modules are not acquired since we aren't ready for them yet.
},
"exclude": ["node_modules"]
}
最后,照常使用 pdfMake.xxx()
.
请参见此链接
这篇关于导入pdfmake.js文件到我的ts文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文