ravi reddy
ravi reddy

Reputation: 45

How to Access package.json data inside the application?

i am setting a key using npm config set produrl 1234. Here how can i access produrl in side my application.

Upvotes: 1

Views: 386

Answers (1)

Guillaume Jasmin
Guillaume Jasmin

Reputation: 1139

If you want to read data from your package.json:

webpack.config.js:

const Webpack = require('webpack');
const pkg = require('./package.json')

module.exports = {
  ...
  plugins: [
    new Webpack.DefinePlugin({
      'process.env': {
        PROD_URL: JSON.stringify(pkg.produrl),
      },
    })
  ]
}

in your application:

console.log(process.env.PROD_URL)

Upvotes: 2

Related Questions