501351981 / vue-office

支持word(.docx)、excel(.xlsx,.xls)、pdf等各类型office文件预览的vue组件集合,提供一站式office文件预览方案,支持vue2和3,也支持React等非Vue框架。Web-based pdf, excel, word preview library
https://501351981.github.io/vue-office/examples/docs/
MIT License
3.35k stars 413 forks source link

vite打包后报错资源加载有问题 #294

Open czkm opened 1 month ago

czkm commented 1 month ago

vue版本:如vue@3 打包工具及版本:如 "vite": "^4.2.1",

"@vue-office/docx": "^1.6.0", "@vue-office/excel": "^1.7.3", "@vue-office/pdf": "^2.0.0", 打包后报错

  ReferenceError: Cannot access 'C9' before initialization
    at @vue-office-ade5967a.js:1:937
    at @vue-office-ade5967a.js:1:945
    at @vue-office-ade5967a.js:195:4463
vite配置如下
   import { defineConfig, loadEnv } from 'vite' // 使用 defineConfig 工具函数获取类型提示:
import { resolve } from 'path';

import vue from '@vitejs/plugin-vue'
const pathResolve = (dir) => {
  return resolve(__dirname, '.', dir);
};

const viteConfig = defineConfig((mode) => {
  const env = loadEnv(mode.mode, process.cwd());
  return {
    optimizeDeps: {
      force: true // 强制进行依赖预构建
    },
    resolve: {
      alias: {
        '/@': pathResolve('./src/'),
        '@util': pathResolve('./src/utils/'),
        '@hook': pathResolve('./src/hook/')
      },
      extensions: ['.js', '.ts', '.json'] // 导入时想要省略的扩展名列表
    },
    server: {
      host: env.VITE_IP,
      port: env.VITE_PORT,
      open: JSON.parse(env.VITE_OPEN),
      hmr: true,
      proxy: {
        '/api': {
          // target: `https://${env.VITE_IP}:3000/`,
          // target: `https://172.31.0.19:5241`,
          // target: `https://172.31.0.48:5241`,
          // target: `https://172.31.0.125:5241`,
          target: `https://192.168.1.65:5241/`,// 服务器地址
          changeOrigin: true,
          secure: false,
          rewrite: (path) => path.replace(/^\/api/, ''),
          // rewrite: (path) => path

        },
      },
    },
    build: {
      outDir: 'build', // 打包文件的输出目录
      assetsDir: 'static', // 静态资源的存放目录
      assetsInlineLimit: 4096 // 图片转 base64 编码的阈值
    },
    plugins: [
      vue(),
    ],
    define: {
      __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
      __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
    },

  }
})

export default viteConfig;
501351981 commented 1 month ago

换纯js方式预览看看,见说明文档