【发布时间】:2020-03-22 00:00:33
【问题描述】:
从表面上看,我遇到了同样的问题:Webpack Babel-loader transpiles code with eval() 但这个解决方案对我不起作用。
我尝试在webpack.config.js 文件中同时使用@babel/preset-env 和babel-preset-env 预设。我也尝试(但失败)使用.babelrc 文件来实现这两种配置。是模块版本冲突问题吗?
如果我可以提供任何其他信息以使我的问题更清楚,请告诉我。
node: v10.15.3, npm: 6.4.1
webpack.config.js
'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']
}
}
]
}
]
}
};
package.json
...
"devDependencies": {
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"babel-loader": "^8.0.6",
...
(除了来自)生成的bundle.js
/***/ }),
/***/ "./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 .... ");
/***/ })
/******/ });
【问题讨论】:
标签: javascript node.js webpack babeljs