私はいくつかのPDF文書をプログラムで印刷したいと思います。 this PDFkit libraryをwebpackで動作させるために何時間も努力しています。webpackでPDFkitライブラリを使用するには?
私が行ってきたフォーム:
Can't resolve 'fs' in ..
[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".
、警告に続い
fs.readFileSync is not a function
require is not defined
- 私はここにいません。これらのエラーはすべてライブラリ内で発生しています。
私はちょうどファイル持っている - あるコードのちょうど一行、とapp.js:私の最後のwebpack.config.js
はこのようになります
const PDFDocument = require('pdfkit');
を:
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
の問題を抱えているのを見てきました。それはどれほど難しいでしょうか?ここで実際に何が起こっていますか?どんな洞察も感謝しています、ありがとう。