Webpack glTF Loader
A Webpack loader for glTF assets. Automatically bundles all referenced files.
Note that this loader creates a new module for each .gltf
source, which will be inlined in the main bundle when using a default configuration.
Consider using dynamic imports / code splitting to keep bundles small.
This loader is based on MONOGRID/gltf-loader-2.
Webpack configuration
rules: [
{
test: /\.(png|jpe?g|gif)(\?.*)?$/,
exclude: /gltf/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'img/[name].[hash:7].[ext]'
}
},
{
test: /\.(gltf)$/,
loader: '@jpweeks/gltf-loader'
},
{
test: /gltf.*\.(bin|png|jpe?g|gif)$/,
loader: 'file-loader',
options: {
name: 'gltf/[name].[hash:7].[ext]'
}
}
]
Usage Example in Three.js
import gltfFile from 'assets/gltf/some.gltf';
var loader = new GLTFLoader()
loader.parse(shieldGLTF, '', (gltf) => {
let scene = gltf.scene
})