如何在 webpack.config.js 中使用 .babelrc 插件选项

7

.babelrc上插件的选项如下:

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

既然我不想使用 .babelrc,而只想使用 webpack.config.js,那么我需要在下面的 webpack.config.js 文件中添加 "polyfill": false"regenerator": true 选项。如何实现呢?

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: [],
};

看起来在 webpack.config.js 上进行的这个修改有效:

plugins: [
        'react-html-attrs', 
        'transform-decorators-legacy', 
        'transform-class-properties', 
        ['transform-runtime',{"polyfill": false, "regenerator": true}]
]
1个回答

0

看起来这个对 webpack.config.js 的修改有效:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接