Skip to content

Instantly share code, notes, and snippets.

@super-dog-human
Last active February 28, 2021 08:19
Show Gist options
  • Save super-dog-human/c42fd44c6b3b0297ad5457290963acd8 to your computer and use it in GitHub Desktop.
Save super-dog-human/c42fd44c6b3b0297ad5457290963acd8 to your computer and use it in GitHub Desktop.

Three.js has many example files under examples directory not src.

To use there from Next.js, We needs to small tweak config.

// next.config.js
const path = require('path')

module.exports = {
  webpack: (config) => {
    config.resolve.alias['ThreejsExample'] = path.resolve(__dirname, 'node_modules/three/examples')
    return config
  },
}
// FooComponent.js
import { GLTFLoader } from 'ThreejsExample/jsm/loaders/GLTFLoader'

You can use resolve.modules intead of resolve.alias, I like the latter.

https://webpack.js.org/configuration/resolve/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment