From 807aa548b261a03952e48c601f31d7fbf1859bc6 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 26 Sep 2017 16:08:20 +0800 Subject: [PATCH] refine:rm duplicate code && split xlsx --- build/webpack.prod.conf.js | 8 ++++++++ src/vendor/Export2Excel.js | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index 05f84874..d69d0e1d 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -95,6 +95,14 @@ var webpackConfig = merge(baseWebpackConfig, { return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0); } }), + // split xlsx into its own file + new webpack.optimize.CommonsChunkPlugin({ + async: 'xlsx', + minChunks(module) { + var context = module.context; + return context && (context.indexOf('xlsx') >= 0); + } + }), // extract webpack runtime and module manifest to its own file in order to // prevent vendor hash from being updated whenever app bundle is updated new webpack.optimize.CommonsChunkPlugin({ diff --git a/src/vendor/Export2Excel.js b/src/vendor/Export2Excel.js index a121a33a..8852064e 100644 --- a/src/vendor/Export2Excel.js +++ b/src/vendor/Export2Excel.js @@ -1,7 +1,8 @@ /* eslint-disable */ require('script-loader!file-saver'); require('script-loader!vendor/Blob'); -require('script-loader!xlsx/dist/xlsx.core.min'); +import XLSX from 'xlsx' + function generateArray(table) { var out = []; var rows = table.querySelectorAll('tr'); @@ -93,7 +94,6 @@ function s2ab(s) { export function export_table_to_excel(id) { var theTable = document.getElementById(id); - console.log('a') var oo = generateArray(theTable); var ranges = oo[1]; @@ -117,9 +117,6 @@ export function export_table_to_excel(id) { saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx") } -function formatJson(jsonData) { - console.log(jsonData) -} export function export_json_to_excel(th, jsonData, defaultTitle) { /* original data */