@stylexjs/rollup-plugin 0.1.0-beta.6 → 0.2.0-beta.10
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 +3 -0
- package/__tests__/index-test.js +53 -28
- package/package.json +3 -3
- package/src/index.js +25 -7
package/README.md
ADDED
package/__tests__/index-test.js
CHANGED
|
@@ -57,16 +57,15 @@ describe('rollup-plugin-stylex', () => {
|
|
|
57
57
|
|
|
58
58
|
expect(css).toMatchInlineSnapshot(`
|
|
59
59
|
"@keyframes x11gtny7-B{0%{opacity:.25;}100%{opacity:1;}}
|
|
60
|
-
.x188knyk{margin-block-start:99px}
|
|
61
|
-
.x1c4r43l{display:flex}
|
|
62
|
-
.x1je5kxa{height:500px}
|
|
63
|
-
html:not([dir='rtl']) .x1n8p6zw{margin-left:10px}
|
|
64
|
-
html[dir='rtl'] .x1n8p6zw{margin-right:10px}
|
|
65
60
|
.x1nrqb13{animation-name:x11gtny7-B}
|
|
66
|
-
.
|
|
61
|
+
.xntgbld{display:block}
|
|
62
|
+
.x1c4r43l{display:flex}
|
|
67
63
|
.x1wdx05y{display:inline}
|
|
64
|
+
.x1je5kxa{height:500px}
|
|
65
|
+
.xo3gju4{margin-inline-start:10px}
|
|
66
|
+
.x1h9ru99{margin-top:99px}
|
|
68
67
|
.x6mlivy{width:100%}
|
|
69
|
-
.
|
|
68
|
+
.x1u78jha{width:50%}
|
|
70
69
|
.x1kflwvg:hover{background:red}"
|
|
71
70
|
`);
|
|
72
71
|
|
|
@@ -77,7 +76,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
77
76
|
var styles$2 = {
|
|
78
77
|
bar: {
|
|
79
78
|
display: "xntgbld",
|
|
80
|
-
width: "x6mlivy"
|
|
79
|
+
width: "x6mlivy",
|
|
80
|
+
$$css: true
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -86,7 +86,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
86
86
|
baz: {
|
|
87
87
|
display: "x1wdx05y",
|
|
88
88
|
height: "x1je5kxa",
|
|
89
|
-
width: "x1u78jha"
|
|
89
|
+
width: "x1u78jha",
|
|
90
|
+
$$css: true
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
|
|
@@ -95,10 +96,21 @@ describe('rollup-plugin-stylex', () => {
|
|
|
95
96
|
foo: {
|
|
96
97
|
animationName: "x1nrqb13",
|
|
97
98
|
display: "x1c4r43l",
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
marginInlineStart: "xo3gju4",
|
|
100
|
+
marginLeft: null,
|
|
101
|
+
marginRight: null,
|
|
102
|
+
marginTop: "x1h9ru99",
|
|
100
103
|
height: "x1je5kxa",
|
|
101
|
-
":hover_background": "x1kflwvg"
|
|
104
|
+
":hover_background": "x1kflwvg",
|
|
105
|
+
":hover_backgroundAttachment": null,
|
|
106
|
+
":hover_backgroundClip": null,
|
|
107
|
+
":hover_backgroundColor": null,
|
|
108
|
+
":hover_backgroundImage": null,
|
|
109
|
+
":hover_backgroundOrigin": null,
|
|
110
|
+
":hover_backgroundPosition": null,
|
|
111
|
+
":hover_backgroundRepeat": null,
|
|
112
|
+
":hover_backgroundSize": null,
|
|
113
|
+
$$css: true
|
|
102
114
|
}
|
|
103
115
|
};
|
|
104
116
|
function App() {
|
|
@@ -123,46 +135,59 @@ describe('rollup-plugin-stylex', () => {
|
|
|
123
135
|
"import stylex from 'stylex';
|
|
124
136
|
|
|
125
137
|
// otherStyles.js
|
|
126
|
-
stylex.inject(".xntgbld{display:block}",
|
|
127
|
-
stylex.inject(".x6mlivy{width:100%}",
|
|
138
|
+
stylex.inject(".xntgbld{display:block}", 4);
|
|
139
|
+
stylex.inject(".x6mlivy{width:100%}", 4);
|
|
128
140
|
var styles$2 = {
|
|
129
141
|
bar: {
|
|
130
142
|
"otherStyles__styles.bar": "otherStyles__styles.bar",
|
|
131
143
|
display: "xntgbld",
|
|
132
|
-
width: "x6mlivy"
|
|
144
|
+
width: "x6mlivy",
|
|
145
|
+
$$css: true
|
|
133
146
|
}
|
|
134
147
|
};
|
|
135
148
|
|
|
136
149
|
// npmStyles.js
|
|
137
|
-
stylex.inject(".x1wdx05y{display:inline}",
|
|
138
|
-
stylex.inject(".x1je5kxa{height:500px}",
|
|
139
|
-
stylex.inject(".x1u78jha{width:50%}",
|
|
150
|
+
stylex.inject(".x1wdx05y{display:inline}", 4);
|
|
151
|
+
stylex.inject(".x1je5kxa{height:500px}", 4);
|
|
152
|
+
stylex.inject(".x1u78jha{width:50%}", 4);
|
|
140
153
|
const styles$1 = {
|
|
141
154
|
baz: {
|
|
142
155
|
"npmStyles__styles.baz": "npmStyles__styles.baz",
|
|
143
156
|
display: "x1wdx05y",
|
|
144
157
|
height: "x1je5kxa",
|
|
145
|
-
width: "x1u78jha"
|
|
158
|
+
width: "x1u78jha",
|
|
159
|
+
$$css: true
|
|
146
160
|
}
|
|
147
161
|
};
|
|
148
162
|
|
|
149
163
|
// index.js
|
|
150
164
|
stylex.inject("@keyframes x11gtny7-B{0%{opacity:.25;}100%{opacity:1;}}", 1);
|
|
151
|
-
stylex.inject(".x1nrqb13{animation-name:x11gtny7-B}",
|
|
152
|
-
stylex.inject(".x1c4r43l{display:flex}",
|
|
153
|
-
stylex.inject(".
|
|
154
|
-
stylex.inject(".
|
|
155
|
-
stylex.inject(".x1je5kxa{height:500px}",
|
|
156
|
-
stylex.inject(".x1kflwvg:hover{background:red}",
|
|
165
|
+
stylex.inject(".x1nrqb13{animation-name:x11gtny7-B}", 4);
|
|
166
|
+
stylex.inject(".x1c4r43l{display:flex}", 4);
|
|
167
|
+
stylex.inject(".xo3gju4{margin-inline-start:10px}", 4);
|
|
168
|
+
stylex.inject(".x1h9ru99{margin-top:99px}", 4);
|
|
169
|
+
stylex.inject(".x1je5kxa{height:500px}", 4);
|
|
170
|
+
stylex.inject(".x1kflwvg:hover{background:red}", 16);
|
|
157
171
|
var styles = {
|
|
158
172
|
foo: {
|
|
159
173
|
"index__styles.foo": "index__styles.foo",
|
|
160
174
|
animationName: "x1nrqb13",
|
|
161
175
|
display: "x1c4r43l",
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
marginInlineStart: "xo3gju4",
|
|
177
|
+
marginLeft: null,
|
|
178
|
+
marginRight: null,
|
|
179
|
+
marginTop: "x1h9ru99",
|
|
164
180
|
height: "x1je5kxa",
|
|
165
|
-
":hover_background": "x1kflwvg"
|
|
181
|
+
":hover_background": "x1kflwvg",
|
|
182
|
+
":hover_backgroundAttachment": null,
|
|
183
|
+
":hover_backgroundClip": null,
|
|
184
|
+
":hover_backgroundColor": null,
|
|
185
|
+
":hover_backgroundImage": null,
|
|
186
|
+
":hover_backgroundOrigin": null,
|
|
187
|
+
":hover_backgroundPosition": null,
|
|
188
|
+
":hover_backgroundRepeat": null,
|
|
189
|
+
":hover_backgroundSize": null,
|
|
190
|
+
$$css: true
|
|
166
191
|
}
|
|
167
192
|
};
|
|
168
193
|
function App() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.10",
|
|
4
4
|
"description": "Rollup plugin for stylex",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": "https://www.github.com/facebookexternal/stylex",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/core": "^7.16.0",
|
|
21
|
-
"@stylexjs/babel-plugin": "0.
|
|
21
|
+
"@stylexjs/babel-plugin": "0.2.0-beta.10"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/preset-env": "^7.16.8",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"@rollup/plugin-commonjs": "^23.0.1",
|
|
27
27
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
28
28
|
"rollup": "^3.2.3",
|
|
29
|
-
"@stylexjs/stylex": "0.
|
|
29
|
+
"@stylexjs/stylex": "0.2.0-beta.10"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
const babel = require('@babel/core');
|
|
9
9
|
const stylexBabelPlugin = require('@stylexjs/babel-plugin');
|
|
10
|
+
const flowSyntaxPlugin = require('@babel/plugin-syntax-flow');
|
|
11
|
+
const jsxSyntaxPlugin = require('@babel/plugin-syntax-jsx');
|
|
12
|
+
const typescriptSyntaxPlugin = require('@babel/plugin-syntax-typescript');
|
|
13
|
+
const path = require('path');
|
|
10
14
|
|
|
11
15
|
const IS_DEV_ENV =
|
|
12
16
|
process.env.NODE_ENV === 'development' ||
|
|
@@ -15,17 +19,19 @@ const IS_DEV_ENV =
|
|
|
15
19
|
module.exports = function stylexPlugin({
|
|
16
20
|
dev = IS_DEV_ENV,
|
|
17
21
|
fileName = 'stylex.css',
|
|
22
|
+
babelConig: { plugins = [], presets = [] } = {},
|
|
18
23
|
} = {}) {
|
|
19
|
-
let stylexRules =
|
|
24
|
+
let stylexRules = {};
|
|
20
25
|
|
|
21
26
|
return {
|
|
22
27
|
name: 'rollup-plugin-stylex',
|
|
23
28
|
buildStart() {
|
|
24
|
-
stylexRules =
|
|
29
|
+
stylexRules = {};
|
|
25
30
|
},
|
|
26
31
|
generateBundle() {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const rules = Object.values(stylexRules).flat();
|
|
33
|
+
if (rules.length > 0) {
|
|
34
|
+
const collectedCSS = stylexBabelPlugin.processStylexRules(rules);
|
|
29
35
|
|
|
30
36
|
this.emitFile({
|
|
31
37
|
fileName,
|
|
@@ -34,18 +40,30 @@ module.exports = function stylexPlugin({
|
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
},
|
|
43
|
+
shouldTransformCachedModule({ code: _code, id, cache: _cache, meta }) {
|
|
44
|
+
stylexRules[id] = meta.stylex;
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
37
47
|
async transform(inputCode, id) {
|
|
38
48
|
const { code, map, metadata } = await babel.transformAsync(inputCode, {
|
|
39
49
|
babelrc: false,
|
|
40
50
|
filename: id,
|
|
41
|
-
|
|
51
|
+
presets,
|
|
52
|
+
plugins: [
|
|
53
|
+
...plugins,
|
|
54
|
+
/\.jsx?/.test(path.extname(id))
|
|
55
|
+
? flowSyntaxPlugin
|
|
56
|
+
: typescriptSyntaxPlugin,
|
|
57
|
+
jsxSyntaxPlugin,
|
|
58
|
+
[stylexBabelPlugin, { dev, stylexSheetName: fileName }],
|
|
59
|
+
],
|
|
42
60
|
});
|
|
43
61
|
|
|
44
62
|
if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
|
|
45
|
-
stylexRules =
|
|
63
|
+
stylexRules[id] = metadata.stylex;
|
|
46
64
|
}
|
|
47
65
|
|
|
48
|
-
return { code, map };
|
|
66
|
+
return { code, map, meta: metadata };
|
|
49
67
|
},
|
|
50
68
|
};
|
|
51
69
|
};
|