libredwg-vite-ts
v1.0.1
Published
Vite plugin for libredwg-ts - handles WASM file serving automatically
Maintainers
Readme
libredwg-vite-ts
Vite plugin for libredwg-ts - automatically handles WASM file serving and bundling.
Installation
npm install -D libredwg-vite-ts
npm install libredwg-tsUsage
1. Add plugin to vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { libredwgPlugin } from 'libredwg-vite-ts'
export default defineConfig({
plugins: [
vue(),
libredwgPlugin()
]
})2. Use in your application
import { LibreDwg } from 'libredwg-ts'
import { getLibreDwgWasmPath } from 'libredwg-vite-ts'
// Get the correct WASM path based on your base URL
const wasmPath = getLibreDwgWasmPath(import.meta.env.BASE_URL)
// Initialize LibreDwg
const dwg = await LibreDwg.create(wasmPath)
// Parse a DWG file
const data = dwg.dwg_read_data(arrayBuffer, 0) // 0 = DWG file type
const database = dwg.convert(data)
// Use the database
console.log(database.entities)
console.log(database.tables.LAYER)
// Free memory when done
dwg.dwg_free(data)Options
libredwgPlugin({
// Custom path to WASM directory (optional)
// If not provided, plugin will auto-detect from node_modules
wasmDir: '/path/to/wasm/files'
})How it works
- Development: Intercepts requests for WASM files and serves them with correct MIME type
- Production: Copies WASM files to the build output
assetsfolder
License
MIT
