@stylexjs/babel-plugin 0.2.0-beta.8 → 0.2.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/lib/index.js +824 -475
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @stylexjs/babel-plugin
|
|
2
|
+
|
|
3
|
+
StyleX expects you to transform all `js`/`ts`/`tsx` files with `@stylexjs/babel-plugin`.
|
|
4
|
+
In addition to transforming JS code, this plugin also produces an Array of CSS rules. All the CSS rules
|
|
5
|
+
generated from all JS files within your project should be concatenated together and converted to a CSS
|
|
6
|
+
file using the `processStyles` function which is also exported from the same module.
|
|
7
|
+
|
|
8
|
+
(NOTE: StyleX only uses RTL-friendly logical values of `start` and `end` and disallows using `left` and `right` entirely.)
|
|
9
|
+
|
|
10
|
+
`@stylexjs/babel-plugin` is fairly lightweight. It pre-computes `stylex` related functions like
|
|
11
|
+
`stylex.create` and `stylex.keyframes` by converting the argument AST to a JS object and transforming them
|
|
12
|
+
by passing them to the functions of the corresponding names within `@stylex/shared`
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Babel Metadata
|
|
16
|
+
|
|
17
|
+
The StyleX Babel plugin does more than transform Javascript (or Typescript) files. It also returns a list of injected styles. The way that such a value can be returned while transforming a JS file is by using Babel's `metadata` API.
|
|
18
|
+
|
|
19
|
+
An example of this can be seen in some of the tests, but the result of using Babel's `transform(...)` function returns an object contains at least two keys:
|
|
20
|
+
|
|
21
|
+
1. `code` which is the transformed JS code
|
|
22
|
+
2. `metadata` is an object of metatdata that the plugin may want to return as a side-effect.
|
|
23
|
+
|
|
24
|
+
e.g.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const result = transformSync(sourceCode, {
|
|
28
|
+
filename: opts.filename,
|
|
29
|
+
parserOpts: { flow: { all: true } },
|
|
30
|
+
plugins: [stylexPlugin, opts],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const transformedCode = result.code;
|
|
34
|
+
const injectedStyles = result.metadata.stylex;
|
|
35
|
+
```
|