DEV Community

Cover image for WebPack 5: Using named exports from JSON modules
Mohi
Mohi

Posted on

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

Top comments (0)