On the face of it I am having the same problem as this: Webpack Babel-loader transpiles code with eval() but this solution doesn't work for me.
I have tried using both, @babel/preset-env
, and babel-preset-env
presets within the webpack.config.js
file. I have also tried (and failed) to implement both this configurations using the .babelrc
file. Is it a module version conflict problem?
Let me know if there is any other information I can provide to make my problem clearer.
node: v10.15.3
, npm: 6.4.1
'use strict';
const path = require('path');
module.exports = {
entry: {
app: './src/js/scripts.js'
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'public/dist/js')
},
module: {
rules: [
{
test: /\.js$/, // include .js files
exclude: /node_modules/, // exclude any and all files in the node_modules folder
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
}
]
}
};
...
"devDependencies": {
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"babel-loader": "^8.0.6",
...
/***/ }),
/***/ "./src/js/scripts.js":
/*!***************************!*\
!*** ./src/js/scripts.js ***!
\***************************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _my_test__WEBPACK_IMPORTED_MODULE_0__ = __webpa .... ");
/***/ })
/******/ });
It is because you in development mode. Try to:
devtool
to 'none' for webpack configmode
to 'production' for webpack configAnd you will not see evals.
UPD preset-env browser options can be set with browserslist format query string:
"presets": [
[
"@babel/preset-env",
{
"targets": "ie 11, chrome 58, > 0.25%, not dead"
}
]
]
or with array but it will be removed in next versions
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": ["chrome 58", "ie 10", "not dead"]
}
}
]
]
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