uxtemple / babel-plugin-react-autoprefix Goto Github PK
View Code? Open in Web Editor NEWAdds vendor prefixes to styles in React elements
Adds vendor prefixes to styles in React elements
Tried the following in a demo app:
class App {
render() {
return <div style={{ display: 'flex' }}>hi</div>;
}
}
When prefixing { display: 'flex' }
I expect the output to be
{ display: 'flex;display:-webkit-flex;display:-ms-flexbox' }
See: https://github.com/petehunt/jsxstyle/blob/master/lib/autoprefix.js#L81
But instead I get:
{ display: [3, 'flex'] }
Great plugin, just what'd I'd been looking for!
One issue - build fails when the value of style
prop does not meet expectations, for example a string or object. There's a good argument that this is an acceptable failure (or at least an optional linter warning/error), however it can cause problems with other tools.
For example, the popular FormatJS uses the style
prop to set how numbers should be displayed, eg <FormattedNumber style='currency'>
. While they probably shouldn't be using standard HTML attributes as props like this, it unfortunately prevents using both at the same time.
I'm probably doing something wrong, but running npm test
fails with:
➜ bash .bin/test 22:43:47
find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
It would be best to eliminate shell scripts so that tests can be run on any platform.
For instance, it would be awesome if this was supported:
const style = {
foo: {
alignItems: "center",
display: "flex",
width: 100
}
};
<div style={style.foo} />
Perhaps the plugin will need some sort of marker to tell it to autoprefix some things, e.g.
const style = {
foo: prefix({
alignItems: "center",
display: "flex",
width: 100
})
};
<div style={style.foo} />
Or, if smart enough, even:
const style = prefix({
foo: {
alignItems: "center",
display: "flex",
width: 100
}
});
<div style={style.foo} />
Does this only work on JSX in-line styles or can it also work on dynamic styles applied inside of a render()?
If I wanted to have some conditional style based on react state/props and generate different style={myCustomStyle}
dynamically, does this somehow get run on each render pass?
Thanks,
Version 0.2.2.
Expected: -webkit-box-align: center; …
Result: webkit-box-align: center; …
(lacks leading -
)
Screenshot attached with a few examples. Is this an issue with the underlying autoprefix? Happy to provide a pull request if pointed in the right direction.
related console errors (firefox dev edition, same displayed in chrome & safari):
someComponent = () => {
<div style={{ backgroundImage = `url(${image})`}} />
}
Results in backgroundImage: undefined
in the browser. I belive this is caused by this plugin, because removing this plugin solves the issue.
const anotherStyle = {
width: 100
};
const style = {
height: 100,
...anotherStyle
};
<div style={style} />
For reference: new plugin API.
Here is the error:
ERROR in ./src/index.js
Module build failed: TypeError: Plugin is not a function
at exports.default (<project_path>/node_modules/babel-plugin-react-autoprefix/index.js:91:10)
at Function.memoisePluginContainer (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:127:13)
at Function.normalisePlugin (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:161:32)
at <project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:197:30
at Array.map (native)
at Function.normalisePlugins (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
at OptionManager.mergeOptions (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
at OptionManager.addConfig (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:221:10)
at OptionManager.findConfigs (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:364:16)
at OptionManager.init (<project_path>/node_modules/babel-core/lib/transformation/file/options/option-manager.js:412:12)
@ multi main
const height = 100;
const style = {
height
};
<div style={style} />
I am getting the following error when adding this module to my project (tried searching around, but can't find anyone else with this problem on this module):
/myproject/node_modules/babel-plugin-react-autoprefix/index.js:10
let binding
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Module._extensions..js (module.js:417:10)
at Object.require.extensions.(anonymous function) [as .js] (/myproject/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:174:20
at Array.map (native)
Adding a 'use strict';
to the index.js
helps it get a bit further:
/myproject/node_modules/babel-plugin-react-autoprefix/index.js:112
module.exports = ({ types: t }) => ({
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Module._extensions..js (module.js:417:10)
at Object.require.extensions.(anonymous function) [as .js] (/myproject/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:174:20
at Array.map (native)
Seems like it's using modern features, but the runtime is not expecting them. My .babelrc
configuration is as follows:
{
"presets": ["latest", "react", "stage-0"],
"plugins": [
"react-autoprefix",
"react-hot-loader/babel",
"transform-object-rest-spread",
"transform-flow-strip-types",
["react-intl", {
"messagesDir": "../build/messages/",
"enforceDescriptions": true
}],
],
"retainLines": true
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.