我正在开发一个React项目,但在使用webpack.config.js
时遇到了问题,我一直在使用一个简单的导入语句获取SyntaxError: Unexpected token import
:import path from "path"
我查看了other堆栈溢出的答案,并相应地修改了我的配置,但到目前为止没有任何帮助
webpack.config.js
import path from "path";
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve("dist"),
filename: "index_bundle.js"
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
query: {
babelrc: false,
presets: [
"stage-0",
"react",
["es2015", { "modules": false }],
["env", {
"targets":
{ "uglify": false }
}
]
]
}
}
]
}
};
.babelrc
{
"presets": ["es2015"]
}
获取以下内容时出错:
(function (exports, require, module, __filename, __dirname) { import path from "path";
^^^^^^
SyntaxError: Unexpected token import
使用webpack-巴别塔的经验告诉我,这真的是件很愚蠢的事情,但在过去的几个小时里,我一直在拔掉头发,无法理解。
发布于 2017-06-21 16:21:27
Babel不会转译配置文件,只是在入口点中编写代码。你必须走这条老路。
const path = require("path");
https://stackoverflow.com/questions/44680751
复制