I'm trying to use Webpack file-loader to copy a static json resource file to dist/ so I can import that json file in a Vue.js component. Webpack is copying the file correctly when I run npm run build, but when I try to import the file (like import myJson from '@/static/runtimeConfig.json') then "myJSON" variable only gets the file path instead of the actual JSON file contents. Can anyone help me understand why this is?
My webpack file-loader config looks like this:
module: {
//load runtimeConfig.json file through a custom loader
rules: [
{
// set the type to javascript/auto to bypass webpack's built-in json importing
type: 'javascript/auto',
test: /(runtimeConfig\.json)$/i,
// file-loader resolves imports on a file and emits that file to dist/
loader: 'file-loader',
// use filename runtimeConfig.json instead of a hashed filename
options: {
name: '[path][name].[ext]',
outputPath: 'static',
}
}
],
},
My intent is to import a json file in a vue.js components, like this:
import myJson from '@/static/runtimeConfig.json'
But, after I do that import, myJson is just the path to the file, not the actual json contents
console.log(myJson)
--> /static/src/static/runtimeConfig.json