I included react-pdf in a fresh umi project:
Every single element takes about 10X more in umi projects!
Code example I tried
import React from "react";
import "./styles.css";
import { Document, Page, pdf, Text, View } from "@react-pdf/renderer";
export default function App() {
const pdfClickHandler = async () => {
console.time("PDF generation took:");
await pdf(
<Document>
<Page>
<View>
{Array.from(Array(150).keys()).map((key) => (
<Text key={key}>text-element</Text>
))}
</View>
</Page>
</Document>
).toBlob();
console.timeEnd("PDF generation took:");
};
return (
<div className="App">
<button onClick={pdfClickHandler}>
Generate fast PDF (without ant-design-pro)
</button>
</div>
);
}
NOTE: The following examples are ant-design-pro
projects. BUT the error occurs in all umi-js
projects.
What is going on behind the scenes when the toBlob is beeing called?
How can I fix this issue?
I was able to fix it:
npm install assert browserify-zlib buffer process stream-browserify util
export default (config: any, { webpack }: { webpack: any }) => {
// Set alias
config.resolve.alias.set('process', 'process/browser');
config.resolve.alias.set('stream', 'stream-browserify');
config.resolve.alias.set('zlib', 'browserify-zlib');
// Set plugin
config.plugin('record').use(webpack.ProvidePlugin, [{
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}]);
};