-
Notifications
You must be signed in to change notification settings - Fork 213
Decorators transpilation is broken in React preset #342
Comments
In Slack @timkelty posted this comment for how he was using decorators in his project: module.exports = neutrino => {
const applyDecorators = plugins => {
plugins = [
'babel-plugin-transform-decorators-legacy',
'babel-plugin-transform-decorators',
'babel-plugin-transform-class-properties',
...plugins
];
return plugins;
};
neutrino.use(require.resolve('neutrino-preset-react'));
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
options.plugins = applyDecorators(options.plugins);
options.env.development.plugins = applyDecorators(options.env.development.plugins);
return options;
});
} Hope that helps. |
@constgen That got me working with |
Thanks a lot. This information was helpful. Actually more short variant worked for me const decoratorsPlugin = require.resolve('babel-plugin-transform-decorators-legacy');
const classPropertiesPlugin = require.resolve('babel-plugin-transform-class-properties');
config.module.rule('compile').use('babel').tap((options) => {
options.plugins.unshift(decoratorsPlugin, classPropertiesPlugin);
options.env.development.plugins.unshift(decoratorsPlugin, classPropertiesPlugin);
return options;
}); My concerns:
|
@constgen yep, your example does seem like it should be sufficient. Not sure why I had It does seem like a particularly tricky way to have to go about this. What would be right way to address this in a new version of neutrino? Should |
Another variant could be: const { merge } = require('neutrino-middleware-compile-loader');
const decorators = require.resolve('babel-plugin-transform-decorators-legacy');
const classes = require.resolve('babel-plugin-transform-class-properties');
config.module.rule('compile').use('babel').tap(options => merge({
plugins: [decorators, classes],
env: {
development: {
plugins: [decorators, classes]
}
}
}, options); I don't think adding a decorators option in the preset is the right thing because:
Trying to document how to easily merge babel configurations would be useful though, through the use of the compile loader's |
I think we should discuss this as one of the options. Another one is to clearly document this as we do with Hot Module Replacement. |
As mentioned, I don't think adding a decorators option in the preset is the right thing because:
|
This is not working for me, nor the solutions provided. I've changed two things:
Here's my full
|
Recently I have reviewed changes in |
Have spent 2 days without result to integrate decorators transpilation to Babel on project with
neutrino-preset-react
. The issue is not reproduced on the same code base but onneutrino-preset-web
. I tried all suggestions from Internet in all possible combinations but nothing worked. The error sounds likeThis is a test suite https://mega.nz/#!rN1WwYIK!hOBFn6E5akz522HOnlQFysoy8HKLEH-l4vRydOYqv7A . Switch preset in
.neutrinorc.js
and run againnpm start
to see different behavior.Had no problems with the similar configuration in Neutrino 5. I believe the issue appeared starting from Neutrino 6 and later when we included class properties syntax by default to React preset.
It may be a serious blocker because decorators are necessary for
mobx
andreact-dnd
.The text was updated successfully, but these errors were encountered: