React JS - package.json中的webpack脚本不能正常工作

时间:2016-04-26 09:26:25

标签: reactjs webpack

我正在做Tyler Mcginess关于react的课程,而我的package.json没有正确加载webpack -p,它正在返回此错误。

在react@1.0.0生产脚本'webpack -p'上失败。 错误的ERR!这很可能是反应包的问题, 错误的ERR!不是与npm本身

的package.json。

{
  "name": "react",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "production": "webpack -p"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.0.1",
    "react-dom": "^15.0.1"
  },
  "devDependencies": {
    "babel-core": "^6.7.7",
    "babel-loader": "^6.2.4",
    "babel-preset-react": "^6.5.0",
    "html-webpack-plugin": "^2.16.0",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  }
}

webpack.config.js。

module.exports = {

    entry: [
        './app/index.js',
    ],

    output: {
        path: __dirname + '/dist',
        filename: "index_bundle.js"
    },

    module: {
        loaders: [
            {test: /\.js$/, exclude: /node_modules/, loaders: "babel-loader"}
        ]
    },

    plugins: [HtmlWebpackPluginConfig]

}

1 个答案:

答案 0 :(得分:1)

在Mac上,“。”文件被隐藏所以webpack没有拿起来。扩展,所以包括一个查询键工作传递一组预设并删除.babelrc文件。

module: {
        loaders: [
            {   
                test: /\.js$/, 
                exclude: /node_modules/, 
                loader: "babel",
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    },