Hi, I found the way to use typescript and webpack5 with hotreload.
I declared glb file as module in webpack and typescript, so I can import them and use them as shown. However, what I have to do is this ugly workaround:
import * as Model from './models/model.glb';
new GLTFLoader().load(Model as unknown as string, function (gltf) {
//...
});
I’d like something common like this, but If I use this code, url is undefined and it won’t work.
import Model from './models/model.glb';
new GLTFLoader().load(Model, function (gltf) {
//...
});
What is the correct way to handle it? I really don’t like to have that double cast and import as *
My webpack relevant configuration:
module: {
rules: [
{
test: /\.(glb|gltf)$/,
type: 'asset/resource'
}
],
},
My typescript definitions
declare module '*.glb' {
const value: any;
export default value;
}
declare module '*.gltf' {
const value: any;
export default value;
}
three: 0.141.0
webpack: 5.73.0
webpack-dev-server: 4.9.2
html-webpack-plugin 5.5.0