A bit of background:
I've been using Webpack with babel-loader for a while and overall the experience has been hugely positive.
Yesterday, I published an npm package of my own (to a private registry), and installed it into my "main" project that uses Webpack.
What I was surprised to find was that when I built the main project with Webpack, the code from my npm package was not transpiled into ES5 syntax, but retained all the ES6 syntax that was in it.
It appears this is because my webpack.config has this exclude
setting, which is strongly recommended by the babel-loader documentation and included in its examples:
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/, // <-- here
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
This much more or less makes sense. What confuses me is that I have never encountered this situation before, across the hundreds of packages and indirect dependencies I've consumed in my projects.
This makes me wonder if every one of those packages was transpiled to ES5 syntax before publishing to NPM. Up until now, I had assumed that people just published the code they had, and that Webpack+babel-loader took care of the necessary transpilation.
So my question is:
Is there some unwritten rule that NPM packages that have any possibility of being used in IE should be transpiled to ES5 syntax before npm publishing? Or is there something that I'm missing?
Clarification: My question assumes that we are talking about a package that is designed to be ES5-compatible once it is transpiled and the necessary polyfills are included. The question is whether it is typical for the code to be transpiled prior to publishing to npm, because up until yesterday, I thought that it was the norm for the package consumer's build process to take care of that step.