我想以编程方式打印一些pdf文档。我现在想花几个小时来使this PDFkit library与webpack一起工作。如何在webpack中使用PDFkit库?
我已经走了形式:
Can't resolve 'fs' in ..
到
fs.readFileSync is not a function
然后警告
[BABEL] Note: The code generator has deoptimised the styling of "E:/MyProjects/accountingsystem/node_modules/brotli/dec/dictionary-da
ta.js" as it exceeds the max of "500KB".
然后
require is not defined
- 我卡在这里。所有这些错误都来自图书馆本身。
我刚才一个文件 - app.js只有代码一行,这就是:
const PDFDocument = require('pdfkit');
我最后webpack.config.js
看起来是这样的:
module.exports = {
// devtool: 'source-map',
entry: './src/app.js',
output: {
path: path.resolve (__dirname, "dist"),
filename: "bundle.js"
},
// node: {
// console: true,
// fs: 'empty',
// net: 'empty',
// tls: 'empty'
// },
// i've added 'target' - following the advice form some github comments.
target: 'node',
module : {
rules : [
{ test: /\.js$/, loader: 'babel-loader' },
{
test : /\.html$/,
use : [ 'html-loader' ]
},
// then i've added this 2 loaders also:
{ test: /\.json$/, loader: 'json-loader' },
{ test: /pdfkit|png-js/, loader: "transform-loader?brfs" }
]
},
plugins:[
new HtmlWebpackPlugin ({
template : `src/app.html`
})
],
};
这实际上是一个1行的应用程序,我现在打了几个小时的墙。我看到很多用户在使用fs
核心模块和webpack
时遇到了问题 - 我尝试了所有我能找到的解决方案。它能有多难?这里究竟发生了什么?感谢任何见解。