因此我们创建了一个es6模块,将其放入存储区并将其声明为对另一个存储库的依赖。
在package.json中,我们已经包含" search-service-redux-middleware":" git + http://stash.corp.web:7990/scm/blah/search-service-redux-middleware.git"。
除了我们在运行服务器时遇到以下错误外,这没什么问题:
Module parse failed: /blah/search-service-react-result/node_modules/search-service-redux-middleware/searchServiceMiddleware.js Line 1: Unexpected token You may need an appropriate loader to handle this file type.
| import request from 'superagent';
|
| export default (actionType, URL) => (store) => (next) => (action) => {
据我所知,这意味着babel并没有编译所有代码到es6 - 它会遗漏node_modules并按原样使用它们。那么我怎样才能做到这一点呢?
这是webpack.config.js:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./app/index.jsx'
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './dist',
hot: true
},
devtool: 'source-map',
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};