@wildpeaks/three-webpack-plugin

2.0.0 • Public • Published

Webpack Plugin: Three

Build Status Known Vulnerabilities Greenkeeper badge

Webpack plugin to use the additional Three.js "examples" classes that aren't ES Modules, such as THREE.OrbitControls.

Usage

Install packages three and @wildpeaks/three-webpack-plugin:

npm install --save-dev three @wildpeaks/three-webpack-plugin

Add the plugin in your webpack.config.js:

const ThreeWebpackPlugin = require('@wildpeaks/three-webpack-plugin');

module.exports = {
	//...
	plugins: [
		//...
		new ThreeWebpackPlugin()
	]
};

You can now import the classes in your application:

// Import from "three" for core classes
import {Scene, WebGLRenderer} from 'three';

// Import from "three/examples/js" for addditional classes
import {OrbitControls} from 'three/examples/js/controls/OrbitControls';

// Use the imported classes
const scene = new Scene();
const renderer = new WebGLRenderer();
const controls = new OrbitControls();

Typescript

Until definitions are integrated directly in @types/three, add a file globals.d.ts at the root of your project to specify the types of the imports, e.g.:

declare module 'three/examples/js/controls/OrbitControls' {
	export const OrbitControls: typeof THREE.OrbitControls;
}

Note that this is not required for compiling to JS, it improves Intellisense in your code editor.

Package Sidebar

Install

npm i @wildpeaks/three-webpack-plugin

Weekly Downloads

32

Version

2.0.0

License

MIT

Unpacked Size

6.28 kB

Total Files

5

Last publish

Collaborators

  • cecilemuller