简体   繁体   English

无法让 browserify 使用 babel-plugin-transform-class-properties

[英]Can't get browserify to use babel-plugin-transform-class-properties

I'm trying to use MobX in my project and I am attempting to use class properties.我正在尝试在我的项目中使用MobX ,并且我正在尝试使用类属性。 However, when I run through browserify (with Laravel's Elixir ).但是,当我通过browserify运行时(使用Laravel 的 Elixir )。 I get the error Missing class properties transform. while parsing file我收到错误Missing class properties transform. while parsing file Missing class properties transform. while parsing file . Missing class properties transform. while parsing file Is there something I'm missing to get class properties to work with browserify?我是否缺少让类属性与 browserify 一起使用的东西?

Browserify Failed!: /Users/.../resources/assets/js/pages/Show/CampaignStore.js: Missing class properties transform. while parsing file: /Users/.../resources/assets/js/pages/Show/CampaignStore.js
 Missing class properties transform.
  2 |
  3 | class CampaignStore {
> 4 |   id = Math.random();
    |   ^
  5 |   @observable title = '';
  6 |   @observable messages = [];
  7 |

My .babelrc file:我的 .babelrc 文件:

{
  "presets": [
    "es2015",
    "react",
    "stage-0"
  ],
  "plugins": ["transform-decorators-legacy", "transform-class-properties"]
}

The class班上

import { observable, computed } from 'mobx';

class CampaignStore {
  id = Math.random();
  @observable title = '';
  @observable messages = [];

  // ...
}

gulpfile.js gulpfile.js

require('dotenv').config();
var elixir = require('laravel-elixir');

var HOST = process.env.SERVER || 'http://localhost';

elixir.config.js.browserify.transformers.push({
    name: 'babelify',
    options: {
        presets: ["es2015", "react", "stage-1"],
        plugins: ["transform-class-properties"]
    }
});

elixir(function(mix) {
    mix.browserify('pages/Show.js', 'public/js/bundles/show.js');

    mix.sass('clean.scss');

    mix.browserSync({
        proxy: HOST
    });
});

You should override exactly babelify transformer:您应该完全覆盖babelify转换器:

elixir.config.js.browserify.transformers
  .find(transformer => transformer.name === 'babelify')
  .options = {
    presets: ['es2015', 'react', 'stage-1'],
    plugins: ['transform-class-properties'],
  };

or just use the same babel config file:或者只使用相同的 babel 配置文件:

elixir.config.js.browserify.transformers
  .find(transformer => transformer.name === 'babelify')
  .options = require('./package.json').babel;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不能通过Babel的transform-class-properties在父类构造函数中使用子类的属性 - Cannot use child class' properties within parent class constructor via Babel's transform-class-properties @ babel / plugin-proposal-class-properties不起作用 - @babel/plugin-proposal-class-properties doesn't work 如何安装节点模块@babel/plugin-transform-class-properties? - How do I install node module @babel/plugin-transform-class-properties? 无法使用 browserify 和 babel 转换threejs的相对路径 - can't transpile relative path of threejs with browserify and babel 即使使用插件,也无法让 babel 转译传播运算符 - Can't get babel to transpile spread operator even WITH plugin 当前未启用对实验语法“classProperties”的支持 (8:16)。 添加@babel/plugin-proposal-class-properties - Support for the experimental syntax 'classProperties' isn't currently enabled (8:16). Add @babel/plugin-proposal-class-properties @babel/plugin-proposal-class-properties 仍然失败,“classProperties 当前未启用” - @babel/plugin-proposal-class-properties Still Fails with "classProperties isn't currently enabled" 如何在Babel + transform-decorators-legacy中禁用定义类的属性 - How to disable defining class properties in Babel + transform-decorators-legacy ES6-Browserify + babel + flot图表插件 - ES6 - Browserify + babel + flot chart plugin @ babel / plugin-transform-modules-amd的行为不符合预期 - @babel/plugin-transform-modules-amd doesn't behave as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM