Does anybody know or have a webpack.config.js file that uses babel-preset-env? If so, please share.
Here is the config file:
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"
}
};
Using a Preset Within a Babel config, if the preset is on npm, you can pass in the name of the preset and Babel will check that it's installed in node_modules already. This is added to the presets config option, which takes an array. Otherwise, you can also specify a relative or absolute path to your presets.
@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!
I think the misunderstanding you are having is that you set the target to be node: current.
preset-env only transpiles that which is necessary to support the target you are looking to support. See here: http://2ality.com/2017/02/babel-preset-env.html
Also, Node support for ES2015 is pretty solid (https://kangax.github.io/compat-table/es6/) so I would assume not much has to be transpiled.
If you want to transpile to ES5 then you should set target to for example IE 10. Most current environments have very high support for ES6 so transpilation will be minimal if at all (which is good).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With