[Vuejs]-How to get data from fs.readFile in vuejs3

1👍

The only way to make this data available in your Vue app is to use the define plugin in Webpack:

// vue.config.js
const my_data = require('./path/file.json');
module.exports =
{
  chainWebpack: config =>
  {
    config.plugin('define').tap(args =>
    {
      args[0]['process.env'].MY_JSON_DATA = JSON.stringify(my_data);
      return args;
    });
  }
}

Then you can access your data as process.env.MY_JSON_DATA

Leave a comment