How does the webpack use the es6 export method to use require ()

  node.js, question

Problems encountered in using webpack: webpack supports commonjs and es6 modules. How to use them at the same time:
Examples:

// a.js
 export default function() {
 console.log('hello world')
 bracket
// main.js
 // import hello from './a' is possible, but es6 does not support writing in blocks if modules need to be introduced into if statements.
 const hello = require('./a.js')

The question is, how can such code work? Is there any module that needs to be introduced? Those who know, thank you for telling me. Thank you very much.

First you need to add babel, which includes many dependent modules.

Then you need to configure your webpack.config.js file.

{
    test: /\.js$/,
    exclude: /node_modules|vue\/dist/,
    loader: 'babel?optional[]=runtime&loose=true'
}

The above is just an example.

Please refer to.https://babeljs.io/