0

I was wondering how can I create a node module that only expose JSON files for configuration. I can easily export JSON object from index.js but, I was thinking any better way to expose JSON from node module, and during build minify the JSON to be exposed.

It will have multiple folder level configuration for different apps.

Example -

config-module
-- App1
-----config1.json
-----config2.json
-- App2
-----config3.json
-----config4.json

And while importing in js i can import like

import config from 'config-module/App1/config1.json'

I cannot find any reference module related to this. If any reference it would be a great help

Shweta
  • 47
  • 4
  • Possible duplicate of [How to import a json file in ecmascript 6?](https://stackoverflow.com/questions/34944099/how-to-import-a-json-file-in-ecmascript-6) – messerbill Sep 20 '19 at 20:18

1 Answers1

-1

You need to configure your webpack. You must use a file-loader to get this working:

https://webpack.js.org/loaders/json-loader/

module.exports = {
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      }
    ]
  }
}

If you don't want to use require but import instead you can read more here: How to import a json file in ecmascript 6?

messerbill
  • 5,499
  • 1
  • 27
  • 38
  • But it doesn't help me in exporting from node module like, import config from 'config-module/App1/config1.js' – Shweta Sep 24 '19 at 02:31