Tinple
Tinple

Reputation: 1271

Does ES5 modules accelate webpack build time comparing with ES6 modules?

In convention, when we write a ES6 modules, we put source code in src folder, and compile it using babel-loader and webpack to lib or dist folder to set code to ES5, and set main entry to dist folder, then publish to npm.

On the one hand, user can use this module without using webpack, and the code can run. On the other hand, when using webpack, ES5 code may reduce babel-loader time because it's already ES5 code.

What I confused is the second point, when using webpack, does ES5 codes in node_module reduce babel-loader time so we can accelate webpack build performance ?

The question is almost about ES5 npm modules with webpack build performance, although it's a convention we already did, I just want to know about something about webpack build performance. Thanks!

Upvotes: 0

Views: 149

Answers (1)

Filip Dupanović
Filip Dupanović

Reputation: 33690

Yes, generally public packages are distributed with sources that have already been transformed. The performance benefit, with regards to Webpack and babel-loader, is that you can consume these sources as-is without having to process them with babel-loader, so you'll commonly see:

{
    test: '\.js$',
    loader: 'babel',
    exclude: ['node_modules']
}

So, I too am confused about this excerpt, specifically why one would want to parse ES5 code with Babel, since no transformation would eventually take place.

Either way, the sources are always parsed by Webpack and not having to parse, transform them beforehand with babel-loader should improve performances.

Upvotes: 1

Related Questions