2017-10-15 68 views
2

有沒有人知道或有一個使用babel-preset-env的webpack.config.js文件?如果是這樣,請分享。如何使用babel-preset-env設置webpack.config.js?

下面是配置文件:

const path = require('path'); 
const webpack = require('webpack'); 
const APP_DIR = path.resolve(__dirname, 'js'); 

module.exports = { 
    entry: { 
     app: "./app/javascript/app-one.js", 
    }, 
    module: { 
     rules: [ 
      { 
       test: /\.js$/, 
       exclude: /node_modules/, 
       include : [ 
       APP_DIR, 
       path.resolve(__dirname, 'node_modules/jquery') 
      ], 
       use: { 
        loader: 'babel-loader', 
        options: { 
         modules: true, 
         presets: ['env', 
          { 
           "targets": { 
            "node": "current" 
           } 
          } 
         ] 
        } 
       } 
      } 
     ] 
    }, 
    node: { 
     fs: "empty" 
    }, 
    output: { 
     path: path.resolve("./app/temp/scripts"), 
     filename: "[name].bundle.js" 
    } 
}; 

回答

0

我覺得你有誤會的是你設定的目標爲節點:電流。

preset-env僅會發現支持您希望支持的目標所必需的內容。看到這裏:http://2ality.com/2017/02/babel-preset-env.html

此外,節點支持ES2015是相當穩固(https://kangax.github.io/compat-table/es6/),所以我會假設沒有太多必須被轉發。

如果你想轉換到ES5,那麼你應該設置目標爲例如IE 10.大多數當前環境對ES6的支持非常高,因此如果根本(這是好的),轉譯將是最小的。

+0

嗯,這清除了我的東西,謝謝! – Leafyshark