I've used your webpack example to extend my create-react-app setup.
I've added your rules to my webpack.config.js but there must a problem with the asset inlining.
in fact this does nothing in my generated webpack chunk:
{ loader: 'raw-loader', test: /\.afm$/ }
this is applied to the webpack output, which indicates that this a problem on the loader side and not a problem with your registerAFMFonts
:
var map = {
"./Helvetica.afm": "./node_modules/pdfkit/js/data/Helvetica.afm"
};
But when i double check the chunk contents there are no inlined glyphs.
That's a pity because i really appreciated the approach with kicking out all the unnecessary embedded fonts. In fact everything up the stack trace works well until the PDFDocument constructor tries to load the standard Helvetica font file, then the app crashes with an uncaught error...
The only thing i modified is the pattern which chooses the font variants. I only want the standard Helvetica to be inlined, like this:
registerAFMFonts(require.context('pdfkit/js/data', false, /Helvetica\.afm$/));
Here's the trace:
Uncaught (in promise) Error: File 'data/Helvetica.afm' not found in virtual file system
at VirtualFileSystem.readFileSync (virtual-fs.js:22)
at Object.Helvetica (pdfkit.es5.js:2658)
at new StandardFont (pdfkit.es5.js:2700)
at Function.open (pdfkit.es5.js:3096)
at PDFDocument.font (pdfkit.es5.js:3170)
at PDFDocument.initFonts (pdfkit.es5.js:3132)
at new PDFDocument (pdfkit.es5.js:4890)
at new PDFBuilder (PDFBuilder.js:42)
at PDFCreator.createID (index.jsx:40)
at PDFCreator.componentDidMount (index.jsx:72)
Any ideas how to ensure that the file will be inlined into the chunk or safely referenced in the virtual file system?
Cheers and thx in advance