Home:ALL Converter>Babel 7 and babel-polyfill

Babel 7 and babel-polyfill

Ask Time:2017-12-28T21:08:41         Author:Palaniichuk Dmytro

Json Formatter

After updating to babel 7 beta, looks like babel polyfill does not transpile before bundle. I updated all scoped packages like this one "@babel/polyfill": "7.0.0-beta.36". And changed imports for two files from import 'babel-polyfill' to import '@babel/polyfill'. How to use babel/pollyfill with babel env and babel 7. Should I use babel/polyfill when use useBuiltIns: 'usage', with targets?

.babelrc.js

const nodeEnv = process.env.NODE_ENV || 'development'
let presetEnvConfig, plugins

if (nodeEnv === 'test'){
    presetEnvConfig = {targets: {node: 'current'}}
    plugins = ['istanbul']
} else {
    presetEnvConfig = {
        targets: {
            browsers: ['last 2 versions', 'ie >= 11']
        },
        modules: false
    }
    plugins = ['react-hot-loader/babel']
}

const config = {
    presets: [
        ['@babel/preset-env', presetEnvConfig],
        '@babel/react',
        '@babel/stage-2'
    ],
    plugins,
}

types.js

import keyMirror from '../../../utils/keyMirror'

export default keyMirror({
    Unassign: null,
    Reassign: null,
    QuickAssignment: null,
}, 'TagAssignmentTypes')

index.js

 <Assignment
     assignee={assignee}
     tagId={tagId && tagId.toString(16)}
     assignmentType={assignmentTypes.Reassign}
     onRequestClose={() => this.setState({isAssignmentInProgress: false})}
     onChange={onChange}
    />

Author:Palaniichuk Dmytro,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48008100/babel-7-and-babel-polyfill
gianmarco :

@babel/polyfill is a wrapper package which only includes imports of stable core-js features (in Babel 6 it also included proposals) and regenerator-runtime/runtime, needed by transpiled generators and async functions. This package doesn't make it possible to provide a smooth migration path from core-js@2 to core-js@3: for this reason, it was decided to deprecate @babel/polyfill in favor of separate inclusion of required parts of core-js and regenerator-runtime.\n\nInstead of\n\nimport \"@babel/polyfill\";\n\n\nyou should use those 2 lines:\n\nimport \"core-js/stable\";\nimport \"regenerator-runtime/runtime\";\n\n\nDon't forget install those dependencies directly!\n\nnpm i --save core-js regenerator-runtime\n\n\n",
2019-07-01T21:52:02
Raja Sekar :

Change \n\n\n @babel/stage-2 to @babel/preset-stage-2\n",
2017-12-28T15:47:07
yy