unplugin-obj
raw JSON → 0.1.2 verified Mon Apr 27 auth: no javascript
Import .obj files as strings in Vite, Rollup, Webpack, and more. Version 0.1.2 is the latest stable release. Built on the unplugin framework, it provides seamless integration across multiple build tools with a unified API. The plugin converts .obj files to raw text, enabling use with three.js or custom parsers. It includes TypeScript type declarations and supports SvelteKit, Nuxt, and Vue CLI. Compared to alternatives like raw-loader or asset modules, it offers framework-agnostic zero-config setup and consistent import syntax across bundlers.
Common errors
error Cannot find module 'unplugin-obj' or its corresponding type declarations. ↓
cause Missing type declarations for .obj files or incorrect import path.
fix
Add 'unplugin-obj/obj' to tsconfig.json types array or add a .d.ts file with /// <reference types="unplugin-obj/obj" />.
error Error: The plugin 'unplugin-obj' doesn't provide a default export. ↓
cause Importing from the package root instead of the tool-specific subpath.
fix
Change import to e.g. import ObjFileImport from 'unplugin-obj/vite';
error TypeScript error: Cannot find module './model.obj' or its corresponding type declarations. ↓
cause TypeScript does not recognize .obj imports without type declarations.
fix
Add type declarations for .obj files (see above).
Warnings
gotcha TypeScript and ESLint may complain about non-existent .obj modules before the plugin is configured. ↓
fix Add type declarations via 'unplugin-obj/obj' in tsconfig.json or a reference directive.
gotcha The plugin must be imported from a tool-specific subpath (e.g., 'unplugin-obj/vite'), not the package root. ↓
fix Use correct import: import ObjFileImport from 'unplugin-obj/vite';
gotcha Webpack users must use require() for the plugin in webpack.config.js if using CommonJS. ↓
fix Use const ObjFileImport = require('unplugin-obj/webpack');
breaking Version 0.x may introduce breaking changes without notice; no stable release yet. ↓
fix Pin exact version and test updates carefully.
Install
npm install unplugin-obj yarn add unplugin-obj pnpm add unplugin-obj Imports
- default wrong
const obj = require('./model.obj');correctimport obj from './model.obj'; - ObjFileImport (plugin factory) wrong
import ObjFileImport from 'unplugin-obj';correctimport ObjFileImport from 'unplugin-obj/vite'; - Type reference wrong
/// <reference types="unplugin-obj" />correct/// <reference types="unplugin-obj/obj" />
Quickstart
// vite.config.ts
import { defineConfig } from 'vite';
import ObjFileImport from 'unplugin-obj/vite';
export default defineConfig({
plugins: [ObjFileImport()],
});
// App.ts
import obj from './models/Lowpoly_tree_sample.obj';
console.log(obj); // outputs the OBJ file content as a string
// Optionally parse with three.js:
// import { parseOBJ } from 'three/addons/loaders/OBJLoader.js';
// console.log(parseOBJ(obj));