Open CoderWeiJ opened 9 months ago
你好,我按照教程配置了serialport,但是提示类继承了空的,看源码好像是require导入的stream模块识别不到
serialport
// vite.config.ts import { defineConfig } from "vite"; import path from "node:path"; import electron from "vite-plugin-electron/simple"; import vue from "@vitejs/plugin-vue"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), electron({ main: { // Shortcut of `build.lib.entry`. entry: "electron/main.ts", vite: { build: { minify: false, rollupOptions: { external: ['serialport'], }, }, }, }, preload: { // Shortcut of `build.rollupOptions.input`. // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`. input: path.join(__dirname, "electron/preload.ts"), }, }), ], });
<script setup lang="ts"> import { onMounted } from 'vue'; import { SerialPort } from 'serialport' onMounted(async () => { await SerialPort.list(); }) </script> <template> <div>App.vue</div> </template> <style scoped> </style>
代码拉下来就用不了?配置没改过?
我是魏健!已收到您的邮件。I'm Wei Jian! We have received your email.
你好,我按照教程配置了
serialport
,但是提示类继承了空的,看源码好像是require导入的stream模块识别不到