javascript - Is it better to have polyfills as import statements with babel-preset-env or add them in entries at webpack.config.js? -
babel-preset-env offers option usebuiltins apply babel-polyfill , transform import 'babel-polyfill' specific, environment-based, import 'core-js/whatever.
is transformation applied if add babel-polyfill in webpack entry section (see example below), or in case usebuiltins ignored , replaced possible imports?
entry: { app: ['babel-polyfill', './src/app.js'] }
it works when specifing:
"presets": [ ..., "env" ] it doesn't related entry point ./src/app.js includes code requirements, guess. don't understand want achieve adding babel-polyfill entry point, seems no effect in case.
i'll try elaborate how works. there babel-preset-env plugin prepares list of transformation plugins , polyfills. list used transform-polyfill-require-plugin import , require statements , replaces list of environment-specific modules.
it doesn't related entry point @ all. adding babel-polyfill add it's code bundle. transform-polyfill-require-plugin doesn't work there anyhow. it's possible check via simple debugging.
and don't need really. can add require("babel-polyfill"); once in app it's noticed in docs. can't import babel-polyfill twice might cause error writes down global , has check collision.
Comments
Post a Comment