我在项目中使用babel + webpack +做出反应。它适用于Chrome,但它只能以第一种方式运行:
request.js
const fetch = (options) => {
return new Promise((resolve, reject) => {
...
$.ajax(options);
})
}
export default fetch;
如果我使用export default fetch = fn
,我会收到错误。
.babelrc
{
"presets": [["es2015", { "modules": false }], "stage-2", "react"],
"plugins": [
"transform-object-assign",
// "transform-strict-mode"
// ["transform-runtime", {"helpers": false,"polyfill": false,"regenerator": true}],
"transform-node-env-inline",
//"transform-remove-strict-mode",
//"transform-strict-mode",
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}]
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
}
}
}
那么,为什么?感谢。
答案 0 :(得分:0)
因为这不是有效的JS语法。
试试这个:
export default function fetch() {
...
}