How to use .babelrc plugin options in webpack.config.js

The plugin options on .babelrcare given below:

{
  "plugins": [
    ["transform-runtime", {
      "polyfill": false,
      "regenerator": true
    }]
  ]
}

Because I do not want to use .babelrc, but I intend to use only webpack.config.js, I need to add options "polyfill": falseand "regenerator": truemy webpack.config.jsfile below, I can do it.

var webpack=require('webpack')

module.exports = {
    //configuration
    context: __dirname + '/src/ui/',
    entry: './ui.js',
    module: {
        loaders: [{
            // "test" is commonly used to match the file extension
            test: /\.jsx?$/,
            // "exclude" should be used to exclude exceptions
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader',
            query: {
                presets: ['react', 'es2015', 'stage-0'],
                plugins: ['react-html-attrs', 'transform-decorators-legacy', 
                          'transform-class-properties', 'transform-runtime'],
            }
        }]
    },    
    output: {
        path: __dirname + '/src/public/js/',
        filename: 'ui.bundle.js'
    },
    plugins: [],
};

This modification webpack.config.jsdoes not seem to work:

plugins: [
        'react-html-attrs', 
        'transform-decorators-legacy', 
        'transform-class-properties', 
        ['transform-runtime',{"polyfill": false, "regenerator": true}]
]
+4
source share

Source: https://habr.com/ru/post/1671615/


All Articles