Trying to compile some JS which contains something like:
class MyClass extends Component {
static PropTypes = {
...
}
}
When transpiling it throws an error for an unexpected token at the equal sign.
I was hoping this was resolved in #971, so I updated to 1.7.2, but no dice.
I admittedly don't know enough about which version of ESCMA needs to be supported in order for this to work. Does Laravel Mix somewhere document which version it supports?
It would be great to have static methods and properties supported!
I installed it with Babel
npm install --save-dev babel-plugin-transform-class-properties
Then, create a .babelrc in the root of your project
{
"plugins": ["transform-class-properties"]
}
Thanks, @helmerdavila! So Laravel Mix will automatically take that into account?
I'm familiar with Babel, but haven't used it, yet. Is it reliable to do things like that?
Maybe in the future this will be included by default
Class properties are an experimental feature of js in the draft phase. At some point in the future, it may become a js feature. Until then you'll need to pull in the plugin.
Most helpful comment
I installed it with Babel
npm install --save-dev babel-plugin-transform-class-propertiesThen, create a
.babelrcin the root of your project