docs.sheetjs.com/tests/bundler-vite.sh

73 lines
1.8 KiB
Bash
Raw Normal View History

2024-04-14 07:05:36 +00:00
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/frontend/bundler/vitejs
# NOTE: this only checks whether data or SheetJS code is added to the bundle
cd /tmp
rm -rf sheetjs-vite-tests
mkdir sheetjs-vite-tests
cd sheetjs-vite-tests
for n in {3..5}; do
npm create vite@$n sheetjs-vite$n -- --template vue-ts
cd sheetjs-vite$n
npm i
2024-07-18 22:19:02 +00:00
npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
2024-04-14 07:05:36 +00:00
npm ls | grep vite
2024-11-04 11:45:57 +00:00
## See https://github.com/vuejs/language-tools/issues/4484#issuecomment-2182469459
if [[ "$n" == "4" ]]; then npm i "vue-tsc@2"; fi
2024-04-14 07:05:36 +00:00
curl -O https://docs.sheetjs.com/vitejs/vite.config.ts
mkdir -p data
curl -L -o data/pres.xlsx https://sheetjs.com/pres.xlsx
cat >src/components/HelloWorld.vue <<EOF
<script setup lang="ts">
// @ts-ignore
import data from '../../data/pres.xlsx?sheetjs';
</script>
<template>
<table>
<tr><th>Name</th><th>Index</th></tr>
<tr v-for="(row,R) in data" v-bind:key="R">
<td>{{row.Name}}</td>
<td>{{row.Index}}</td>
</tr>
</table>
</template>
EOF
npm run build
echo "### Results: " $(grep Clinton -R dist | wc -l) $(grep BESSELJ -R dist | wc -l)
cat >src/components/HelloWorld.vue <<EOF
<script setup lang="ts">
// @ts-ignore
import b64 from '../../data/pres.xlsx?b64';
import { read, utils } from "xlsx";
/* parse workbook and convert first sheet to row array */
const wb = read(b64);
const ws = wb.Sheets[wb.SheetNames[0]];
interface IPresident { Name: string; Index: number; };
const data = utils.sheet_to_json<IPresident>(ws);
</script>
<template>
<table>
<tr><th>Name</th><th>Index</th></tr>
<tr v-for="(row,R) in data" v-bind:key="R">
<td>{{row.Name}}</td>
<td>{{row.Index}}</td>
</tr>
</table>
</template>
EOF
npm run build
echo "### Results: " $(grep Clinton -R dist | wc -l) $(grep BESSELJ -R dist | wc -l)
cd -
done