问题
I'm trying to use MobX in my project and I am attempting to use class properties. However, when I run through browserify (with Laravel's Elixir). I get the error Missing class properties transform. while parsing file
. Is there something I'm missing to get class properties to work with 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:
{
"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
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
});
});
回答1:
You should override exactly babelify
transformer:
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:
elixir.config.js.browserify.transformers
.find(transformer => transformer.name === 'babelify')
.options = require('./package.json').babel;
来源:https://stackoverflow.com/questions/37145051/cant-get-browserify-to-use-babel-plugin-transform-class-properties