ITZone

Webpack from A to Asia: Webpack import export module

The Import – Export Module is one of the great features of JavaScript, they are standardized in ES2015 (ES6) and supported in most browsers at the moment, but there are some browsers that do not recognize. Issue a new syntax but it’s okay, don’t worry, webpack will support you. Behind the scenes, webpacks actually “translate code” code so that older browsers can run as well. Besides importing and exporting, webpack supports various module syntaxes, see Module API for more information. Note that the webpack will not change any code other than import and export. If you want to use other ES6 features, use a transcoder like Babel or Bublé

Version 2 of webpack supports ES6 module syntax natively, meaning you can use import and export without a tool like babel to handle this for you. Keep in mind that you will still probably need babel for other ES6 + features.

1. Prepare the file

Code for the original webpack.config.js file:

Create file src/test.js

2. Import the module in javascript

If the src/index.js wants to use the sum function of src/test.js then we can simply import the sum function to be used.

Rerun the webpack and see if the log print the result as this is ok

Today’s article is just so short, mainly to remind you that import – export is one of the features of (ES6) and not every browser supports it, that’s why we use webpack to code their We can run well on most browsers today, from neoclassical charm to REMIX young music – EDM genres, any dance music.


This article is over, hope with this article you have added a lot of useful knowledge. See you in the next article!

Share the news now