I
I
Ivan2021-03-29 23:02:14
JSON
Ivan, 2021-03-29 23:02:14

How to read .json file?

There is a manifest.json file (src/manifest.json) with the following content:

{
  "entrypoints": {
    "index": {
      "assets": {
        "js": [
          "assets/js/vendors~index~second.js",
          "assets/js/index~second.js",
          "assets/js/index.js"
        ],
        "css": [
          "assets/css/index~second.css",
          "assets/css/index.css"
        ]
      }
    },
    "second": {
      "assets": {
        "js": [
          "assets/js/vendors~index~second.js",
          "assets/js/index~second.js",
          "assets/js/second.js"
        ],
        "css": [
          "assets/css/index~second.css",
          "assets/css/second.css"
        ]
      }
    }
  }
}


There is a webpack.base.conf.js file (build/webpack.base.conf.js)

const path = require('path')
const { $ } = require('jquery')

const PATHS = {
  src: path.join(__dirname, '../src'),
  dist: path.join(__dirname, '../dist'),
  assets: 'assets/'
}

$.getJSON(PATHS.src + '/manifest.json', function(data) {
  console.log(data.entrypoints.index.assets.js)
})


This code gives the error "TypeError: Cannot read property 'getJSON' of undefined

" Or is it impossible to use a similar technique in webpack configuration files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-03-29
@Vamba45

console.log(
  require(path.join(PATHS.src, 'manifest.json'))
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question