protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
835 stars 422 forks source link

The "./cptable" Error resolve way(only when you use frontend framework). #159

Open RexHung0302 opened 3 years ago

RexHung0302 commented 3 years ago

First, thank the author create this plugins.

I use xlsx-style and got an error like others, but a find a way to resolve(only when you use frontend framework) the error without do edit /node_modules/xlsx-style/dist/cptable.js, the resolve way is by webpack.config.js.

module.exports = {
  configureWebpack: () => {
    var obj = {
      externals: {
        "./cptable": "var cptable",
      },
    };
    return obj;
  },
};
const { override, addWebpackExternals } = require("customize-cra");

module.exports = override(
  addWebpackExternals({
    "./cptable": "var cptable",
  })
);

I'm do the demo in my repositories, you can pull and try.

I'm not try angular, sorry.

HandsomeOne commented 2 years ago

how to fix it when using vite (or rollup)?

RexHung0302 commented 2 years ago

how to fix it when using vite (or rollup)?

Hi, u can set it on vite.config.js.

https://vitejs.dev/config/#configuring-vite

1029800858 commented 7 months ago

how to fix it when using vite (or rollup)?

Hi, u can set it on vite.config.js.

https://vitejs.dev/config/#configuring-vite

How to configure on vite? Can you provide a demo

RexHung0302 commented 7 months ago

how to fix it when using vite (or rollup)?

Hi, u can set it on vite.config.js. https://vitejs.dev/config/#configuring-vite

How to configure on vite? Can you provide a demo

sure, you can try this

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      external: ['./cptable'],
      output: {
        globals: {
          './cptable': 'cptable',
        },
      },
    },
  },
})

I got those code from GPT, you can try it and let me know how it work, thx.