My script is using Prime UI (Angular) table to export data as xlsx
https://www.primefaces.org/primeng/showcase/#/table/export
Here are the working code
exportExcel() {
console.log('this.appResults.output.data=', this.appResults.output.data)
import("xlsx").then(xlsx => {
const worksheet = xlsx.utils.json_to_sheet(this.appResults.output.data);
const workbook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
const excelBuffer: any = xlsx.write(workbook, { bookType: 'xlsx', type: 'array' });
this.saveAsExcelFile(excelBuffer, "Results");
});
}
saveAsExcelFile(buffer: any, fileName: string): void {
import("file-saver").then(FileSaver => {
let EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
let EXCEL_EXTENSION = '.xlsx';
const data: Blob = new Blob([buffer], {
type: EXCEL_TYPE
});
FileSaver.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
});
}
And angular build time is relatively long, and with complain of the package whenever i use it
Lazy Chunk Files | Names | Size
xlsx.js | xlsx | 1.69 MB
...
file-saver.js | file-saver | 4.17 kB
Build at: 2021-06-19T03:01:59.988Z - Hash: 40c0bb4716e62bd0dfa2 - Time: 65062ms
Warning: /....component.ts depends on 'file-saver'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /home/....component.ts depends on 'xlsx'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
How can I optimize (reduce) the build time and file size? I saw some post to suppress warning but it's not my intention.