构建我的反应应用程序时出错(UglifyJs)

时间:2017-03-16 12:59:45

标签: reactjs webpack babel

当我运行我的反应应用程序的构建时,我得到了:ERROR in bundle.js from UglifyJs Unexpected token: name我找到了这个https://github.com/joeeames/WebpackFundamentalsCourse/issues/3 他们建议使用babel-reset-es2015,但我需要babel-preset-react。 我的webpack配置:

const path = require('path')

const ExtractTextPlugin = require("extract-text-webpack-plugin")

const extractSass = new ExtractTextPlugin({
    filename: "style.css",
    disable: process.env.NODE_ENV === "development"
});

const config = {
  entry: "./src/index.js",

  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname + "/dist")
  },

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

      {
        test: /\.js$/,
        enforce: 'pre',

        loader: 'eslint-loader',
        options: {
          emitWarning: true,
        }
      },

      { test: /\.html$/,
        use:[{
          loader: 'html-loader',
          options: {
            minimize:true
          }
        }]
      },

      {
        test: /\.scss$/,
        use: extractSass.extract({
          use: [{
              loader: "css-loader"
          }, {
              loader: "sass-loader"
          }],
          fallback: "style-loader"
        })
      }
  ]},

  plugins: [
    extractSass
  ],

  node:{
    fs: "empty"
  }
}

module.exports = config

1 个答案:

答案 0 :(得分:0)

你可以拥有两者,它们不是互斥的。此外,query已替换为网络包2中的options,就像您已经在其他加载程序中使用它一样。出于兼容性原因,query仍然存在,但您应该只使用options

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