【发布时间】:2019-03-24 00:46:49
【问题描述】:
我使用 webpack 来捆绑我的节点应用程序。
我在 webpack 从 const 转换为 var 的包中看到了结果。这意味着 webpack 将我的文件转换为 es5。
如何告诉 webpack 转换为 es6? (例如,保留 const 和/或使用 import 关键字)
app.js
import {test} from './some';
const x = 1;
console.log('test', test);
console.log('this should be const in the bundle, not var. ', x);
捆绑包是:
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _some__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./some */ "./some.js");
var x = 1;
console.log('test', _some__WEBPACK_IMPORTED_MODULE_0__["test"]);
console.log('this should be const in the bundle, not var. ', x);
/***/ }),
我的 webpack 配置:
const path = require('path');
module.exports = () => [
{
mode: 'development',
entry: path.resolve(__dirname, './app.js'),
output: {
path: path.resolve(__dirname, './dist')
},
devtool: 'source-map',
target: 'node',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
}
];
【问题讨论】:
标签: javascript node.js webpack ecmascript-6 webpack-4