但是,据我所知 - 我甚至没有安装它。我相信我曾经,但我正在将这个项目更新为webpack4x和babel 7x。这是webpack 3x和babel 6x。
这是我的package.json
"dependencies": {
"@appbaseio/reactivesearch": "^3.0.0-rc.6",
"axios": "0.16.2",
"compression": "^1.7.4",
"concurrently": "3.5.0",
"express": "4.16.4",
"express-http-proxy": "1.0.6",
"lodash": "^4.17.11",
"nodemon": "^1.18.11",
"npm-run-all": "4.1.1",
"react": "16.0.0",
"react-cookie": "^3.1.2",
"react-dom": "16.0.0",
"react-helmet": "5.2.0",
"react-redux": "5.0.6",
"react-router-config": "^5.0.0",
"react-router-dom": "4.2.2",
"redux": "3.7.2",
"redux-thunk": "2.2.0",
"serialize-javascript": "1.4.0"
},
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.4.4",
"babel-loader": "^8.0.5",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.3.1",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2"
}
}
这是React-SSR项目的一部分。所以这是我的client.js(客户端应用程序的开头)
// Startup point for the client side application
// ref: https://babeljs.io/docs/en/next/babel-polyfill.html
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import { renderRoutes } from 'react-router-config';
import axios from 'axios';
import Routes from './Routes';
import reducers from './reducers';
const axiosInstance = axios.create({
baseURL: '/api'
});
// this is the client side store - there is also a server side store in /helpers/createStore.js
const store = createStore(
reducers,
window.INITIAL_STATE,
applyMiddleware(thunk.withExtraArgument(axiosInstance))
);
ReactDOM.hydrate(
<Provider store={store}>
<BrowserRouter>
<div>{renderRoutes(Routes)}</div>
</BrowserRouter>
</Provider>,
document.querySelector('#root')
);
这是我的.babelrc
{
"plugins": ["transform-object-rest-spread"],
"presets": [
"@babel/preset-react",
"@babel/preset-env"
]
}
我不太确定我是否错过了必要的包装或者配置错误......?
Babel预设都是单独的npm包,默认情况下不安装。
npm install --save-dev @babel/preset-react