正确的webpack配置为babel 6,反应热负载,webpack中间件

时间:2016-04-10 03:47:52

标签: node.js reactjs webpack babeljs webpack-hot-middleware

在网络包配置上阅读了一篇小说的SO帖子后,我仍然无法解决<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <div id="red_head"> <p id="menu_title" onclick="hideText('text1')" > Add your first menu item</p> </div> <form name="first_prod" id="first_prod" enctype="multipart/form-data" action="testing.php" method="post" accept-charset="utf-8" > <input type="Submit" id="save_first_prod" name="save_first_prod" value=" + ADD"> </form>错误。

package.json(不是全部)

module parse failed

结构

"dependencies": {
    "babel-core": "^6.7.6",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-es2015-webpack": "^6.4.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "react": "^0.14.6",
    "react-dom": "^0.14.6",
    "react-hot-loader": "^1.3.0",
    "webpack": "^1.12.14",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-hot-middleware": "^2.10.0"
}

的客户机/ webpack.config.js

package.json
node_modules
.babelrc
client/
    webpack.config.js
    .babelrc         # duplicated just for shits and giggles...
    src/
        index.jsx
        components/
server/
    index.js
    //more stuff        

.babelrc

var path = require('path'),
    webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  context: __dirname + '/src',
  entry: [
    'webpack-hot-middleware/client',
    __dirname + '/src/index.jsx'
  ],
  output: {
    path: __dirname + '/public',
    filename: 'bundle.js',
    publicPath: 'http://localhost:12345'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  module: {
    loaders: [
      {
        test: /\.jsx$/,
        include: __dirname + '/src',
        loaders: ['react-hot', 'babel-loader?presets[]=react,presets[]=es2015,presets[]=stage-0'],
        query: { 
          plugins: ['./babelRelayPlugin'],
          presets: ['es2015', 'react'] 
        }
      }
    ]
  }
};

的客户机/ SRC / index.jsx

{ "presets": ["react", "es2015", "stage-0"] }

一直在暗中修改webpack配置,并且不能让babel转换为es6。

来自其他SO帖子的重复出现的问题

  1. import React from 'react'; import ReactDOM from 'react-dom'; import Layout from './src/components/layout.jsx'; ReactDOM.render(<Layout />, document.querySelector('#app')); 数组必须位于Loaders属性
  2. module数组添加到presets
  3. .babelrc
  4. npm install --save babel-preset-whatever已弃用,请使用babel-preset-react-hmre
  5. 装载机从右到左,从上到下装载
  6. 亏本。

0 个答案:

没有答案