title: How to use PDFkit library with webpack?
body: <p>I want to print some pdf documents programmatically. and I'm trying for hours now to make <a href="http://pdfkit.org/demo/browser.html" rel="noreferrer">this PDFkit library</a> working with webpack.</p>
  
  <p>I've gone form:</p>
  
  <p><code>Can't resolve 'fs' in ..</code></p>
  
  <p>to</p>
  
  <p><code>fs.readFileSync is not a function</code></p>
  
  <p>then to the warning</p>
  
  <pre><code>[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".
  </code></pre>
  
  <p>then to</p>
  
  <p><code>require is not defined</code> - i'm stuck here. All this errors are coming form within the library itself.</p>
  
  <p>I have just <strong>one</strong> file - <strong>app.js</strong> with just <strong>a single line of code</strong>, which is:</p>
  
  <p><code>const PDFDocument = require('pdfkit');</code></p>
  
  <p>My final <code>webpack.config.js</code> looks like this:</p>
  
  <pre><code>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`
      })
  ],
  </code></pre>
  
  <p>};</p>
  
  <p>This is literally a 1 line app, and i'm hitting the wall for hours now. I've seen that many users are having issues with <code>fs</code> core module and <code>webpack</code> - and i tried every solution i could find. How hard can it be? What is actually happening here? Any insight is appreciated, Thanks.</p>