haoyunfeix / note

0 stars 0 forks source link

main vs jsnext: vs module #6

Open haoyunfeix opened 4 years ago

haoyunfeix commented 4 years ago

Node module's package.json has main property. It's the entry point of a package, which is exported when a client requires the package.

jsnext:main Module bundlers that utilizes tree shaking to reduce bundle size, like Rollup and Webpack 2, require packages to expose ES Modules with import and export. So they invented a non-standard property called jsnext:main.

However, it had a problem. If the file specified jsnext:main contains ES2015+ features, it won't run without transpilation on browsers that don't support those features. But normally people don't transpile packages in node_modules, and many issues were created on GitHub. To solve the problem, people concluded that jsnext:main shouldn't have ES2015+ features other than import and export. What an irony.

module Now the name jsnext:main is too confusing. I was confused at least. People discussed for a better name, and module came out that supersedes jsnext:main. And it might be standardized.