Плагин распространения объектов не работает в веб-пакете

Я пытаюсь использовать оператор распространения объекта в своем приложении. Это мои файлы.

webpack.config.js

const webpack = require('webpack')
const path = require('path');

const BUILD_DIR = path.resolve(__dirname + '/build')
const APP_DIR = path.resolve(__dirname + '/app')

module.exports = {
  entry: APP_DIR + '/index.jsx',
  output: {
    filename: 'bundle.js',
    path: BUILD_DIR,
    publicPath: '/',
  },

  devServer: {
      inline: true,
      contentBase: BUILD_DIR,
      port: 3333,
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      }
    ]
  },
  resolve: {

      extensions: [".js", ".json", ".jsx", ".css"],
  }
};

.babelrc (в корневой папке проекта)

{
  "presets": ["es2015", "react"],
  "plugins": ["transform-object-rest-spread"]
}

package.json

{
  "name": "shoop",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "dependencies": {
    "webpack": "^2.4.1"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack-dev-server": "^2.4.5"
  },
  "scripts": {
    "dev": "webpack-dev-server",
    "compile": "webpack"
  },
  "author": "",
  "license": "ISC"
}

И когда я пытаюсь запустить код ниже, я получаю сообщение «Неожиданный токен».:

index.jsx

 let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
    console.log(x); // 1
    console.log(y); // 2
    console.log(z); // { a: 3, b: 4 }

person Artifex    schedule 02.05.2017    source источник
comment
попробуйте изменить test: /\.js$/ на test: /\.jsx?$/   -  person Julio Betta    schedule 02.05.2017
comment
теперь работает, спасибо. Я должен уделять больше внимания регулярным выражениям   -  person Artifex    schedule 02.05.2017
comment
@juliobetta, вам, вероятно, следует добавить это как ответ, чтобы ОП мог его принять, а другие люди, у которых такая же проблема, могли найти это решение :)   -  person Pedro Castilho    schedule 02.05.2017


Ответы (1)


Изменить test: /\.js$/ на test: /\.jsx?$/

person Julio Betta    schedule 02.05.2017