WebPack 5: Using named exports from JSON modules

mohi

Mohi

Posted on August 24, 2022

WebPack 5: Using named exports from JSON modules

If you work with JavaScript, or you've ever interacted with a JavaScript project, Node.js or a frontend project, you surely met the package.json file.

In the JavaScript application under package.json file, you can see the one property called version. We can use this version while deploying to indicate the different versions of the application.

in WebPack 4 the version can be accessed in our application by simply importing this file as below:

import { version } from '../../package';
Enter fullscreen mode Exit fullscreen mode

After migration to WebPack 5 The version can be accessed in our application by simply importing this file as below:

import packageInfo from 'package.json';

export default packageInfo.version;
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
mohi
Mohi

Posted on August 24, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related