Let me actually give a good response here to solving this altogether:
The requirement was :
load a .env file for an environment.
load a .glb file into a scene
Firstly I got it working placing the assets in the public directory BUT this will skip webpack, so to solve that you have to add some code to vue.config.js which will update webpack to work with these asset types.
module.exports = {
configureWebpack: {
module: {
rules: [{
test: /\.(glb)$/i,
use: [{
loader: 'file-loader',
options: {
outputPath: 'glb',
},
}, ],
},{
test: /\.(env)$/i,
use: [{
loader: 'file-loader',
options: {
outputPath: 'env',
},
}, ],
}],
},
},
};
The above code instructs webpack to use the file loader and also to parent the assets in some folders( outputPath property )
So in my project directory my assets are inside the src directory , inside the assets directory , where all my other assets are. they are the build source. These assets are all copied into directories inside the “dist” directory … the directory built when running “npm run build”
Vue has an internally configured webpack for known asset types.
(take note it is possible your output directory has another name. Also, take note running “npm run serve” only performs a partial build and your assets will not be generated. So you have to at least run “npm run build” once to get your assets generated , after that you can resort to running “npm run serve” for faster testing )
In your code you then use “require” on the asset build source path , eg :
var loadedAssetModuleObject = require('../assets/glb/hoodie_v_1_1.glb')
Vue will make this become a module request , which returns a module object. The module object has a property named “default” this is the uri to your asset in the target built directory.
{
"default": "/glb/07c9dcb14bfb8d2ed06d215206b62e10.glb"
}
then to use this to load your file eg
BABYLON.SceneLoader.ImportMesh(
"",
loadedAssetModuleObject.default,
"",
this.scene,
this.loadSuccess.bind(this),
this.loadProgress.bind(this),
this.loadError.bind(this)
);
GREAT! this will all work locally … now to issue 2 … this falls apart when you try using amazon AWS Amplify.
No need to go into great detail about this , but it comes down to having to edit a regex string to include the “env” and the “glb” extensions. I dont want to steal the thunder of the guy who posted that solution on stack , so just go read the post and you will get an idea what to do… its pretty straight forward.