Отсутствующие свойства класса transform реакции - PullRequest
0 голосов
/ 06 июня 2018

Я знаю, что есть много вопросов / ответов, но ни один из них, кажется, не помогает мне решить мою проблему.Я не понимаю, что не так с моей настройкой: enter image description here

Вот мой webpack.config.js:

var path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'ftux-components.js',
    library: "shared-components",
    libraryTarget: "umd"
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel',
        query: {
          presets: ['env', 'react', 'es2015', 'stage-0'],
          plugins: ["transform-class-properties"]
        }
      },
      {
        test: /\.s?css$/,
        loaders: ['style', 'css', 'sass', 'postcss-loader']
      },
      {
        test: /\.(ttf|eot|svg|jpg|png|woff)$/,
        loader: 'url-loader'
      }
    ],
    rules: [
      {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        exclude: /(node_modules|bower_components|build)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      }
    ]
  },
  externals: {
    react: {
      root: 'React',
      commonjs2: 'react',
      commonjs: 'react',
      amd: 'react'
    },
    'react-dom': {
      root: 'ReactDOM',
      commonjs2: 'react-dom',
      commonjs: 'react-dom',
      amd: 'react-dom'
    },
    'styled-components': {
      commonjs: 'styled-components',
      commonjs2: 'styled-components',
      amd: 'styled-components'
    }
  }
};

Вот мой babelrc:

{
    "presets": ["env", "react", "es2015", "stage-0"],
    "plugins": [
        "transform-class-properties",
        "transform-object-rest-spread",
        "transform-react-jsx"
    ]
}

Я попытался изменить порядок пресетов, добавив соответствующие плагины (transform-class-properties), удалив переустановку node_modules, но, похоже, ничего не помогло.Мой npm и узел обновлены, также пытался использовать this , чтобы убедиться, что я включил все, что мне нужно для babel.Есть предложения?

Ответы [ 2 ]

0 голосов
/ 06 июня 2018

Хорошо, я понял это.Мне нужно было включить пресеты и плагины в массив правил в объекте модуля в webpack.config.js:

rules: [
    {
    test: /\.js$/,
    include: path.resolve(__dirname, 'src'),
    exclude: /(node_modules|bower_components|build)/,
    loader: 'babel-loader',
    query: {
        presets: ['env', 'react', 'es2015', 'stage-0'],
        plugins: ["transform-class-properties"]
    }
    }
]

Нашел ответ здесь .

0 голосов
/ 06 июня 2018

В вашем Babel Loader вы не включаете плагин для свойств класса, даже если он у вас уже установлен.Попробуйте сделать так, чтобы ваш загрузчик выглядел так:

     {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel',
        query: {
          presets: ['env', 'react', 'es2015', 'stage-0'],
          plugins: ["transform-class-properties"]
        }
      },
...