@stylexjs/rollup-plugin 0.2.0-beta.8 → 0.3.0
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
ADDED
package/__tests__/index-test.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
'use strict';
|
|
@@ -56,51 +58,96 @@ describe('rollup-plugin-stylex', () => {
|
|
|
56
58
|
const { css, js } = await runStylex({ fileName: 'stylex.css' });
|
|
57
59
|
|
|
58
60
|
expect(css).toMatchInlineSnapshot(`
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
.
|
|
61
|
+
"
|
|
62
|
+
@layer priority1, priority2, priority3, priority4;
|
|
63
|
+
@layer priority1{
|
|
64
|
+
@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}
|
|
65
|
+
}
|
|
66
|
+
@layer priority2{
|
|
67
|
+
.x1oz5o6v:hover{background:red}
|
|
68
|
+
}
|
|
69
|
+
@layer priority3{
|
|
70
|
+
.xeuoslp{animation-name:xgnty7z-B}
|
|
71
|
+
.x1lliihq{display:block}
|
|
72
|
+
.x78zum5{display:flex}
|
|
73
|
+
.xt0psk2{display:inline}
|
|
74
|
+
.x1hm9lzh{margin-inline-start:10px}
|
|
75
|
+
}
|
|
76
|
+
@layer priority4{
|
|
77
|
+
.x1egiwwb{height:500px}
|
|
78
|
+
.xlrshdv{margin-top:99px}
|
|
79
|
+
.xh8yej3{width:100%}
|
|
80
|
+
.x3hqpx7{width:50%}
|
|
81
|
+
}"
|
|
71
82
|
`);
|
|
72
83
|
|
|
73
84
|
expect(js).toMatchInlineSnapshot(`
|
|
74
85
|
"import stylex from 'stylex';
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
89
|
+
*
|
|
90
|
+
* This source code is licensed under the MIT license found in the
|
|
91
|
+
* LICENSE file in the root directory of this source tree.
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
|
|
77
96
|
var styles$2 = {
|
|
78
97
|
bar: {
|
|
79
|
-
display: "
|
|
80
|
-
width: "
|
|
98
|
+
display: "x1lliihq",
|
|
99
|
+
width: "xh8yej3",
|
|
81
100
|
$$css: true
|
|
82
101
|
}
|
|
83
102
|
};
|
|
84
103
|
|
|
85
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
106
|
+
*
|
|
107
|
+
* This source code is licensed under the MIT license found in the
|
|
108
|
+
* LICENSE file in the root directory of this source tree.
|
|
109
|
+
*
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
|
|
86
113
|
const styles$1 = {
|
|
87
114
|
baz: {
|
|
88
|
-
display: "
|
|
89
|
-
height: "
|
|
90
|
-
width: "
|
|
115
|
+
display: "xt0psk2",
|
|
116
|
+
height: "x1egiwwb",
|
|
117
|
+
width: "x3hqpx7",
|
|
91
118
|
$$css: true
|
|
92
119
|
}
|
|
93
120
|
};
|
|
94
121
|
|
|
95
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
124
|
+
*
|
|
125
|
+
* This source code is licensed under the MIT license found in the
|
|
126
|
+
* LICENSE file in the root directory of this source tree.
|
|
127
|
+
*
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
|
|
96
131
|
var styles = {
|
|
97
132
|
foo: {
|
|
98
|
-
animationName: "
|
|
99
|
-
display: "
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
133
|
+
animationName: "xeuoslp",
|
|
134
|
+
display: "x78zum5",
|
|
135
|
+
marginInlineStart: "x1hm9lzh",
|
|
136
|
+
marginLeft: null,
|
|
137
|
+
marginRight: null,
|
|
138
|
+
marginTop: "xlrshdv",
|
|
139
|
+
height: "x1egiwwb",
|
|
140
|
+
":hover_background": "x1oz5o6v",
|
|
141
|
+
":hover_backgroundAttachment": null,
|
|
142
|
+
":hover_backgroundClip": null,
|
|
143
|
+
":hover_backgroundColor": null,
|
|
144
|
+
":hover_backgroundImage": null,
|
|
145
|
+
":hover_backgroundOrigin": null,
|
|
146
|
+
":hover_backgroundPosition": null,
|
|
147
|
+
":hover_backgroundPositionX": null,
|
|
148
|
+
":hover_backgroundPositionY": null,
|
|
149
|
+
":hover_backgroundRepeat": null,
|
|
150
|
+
":hover_backgroundSize": null,
|
|
104
151
|
$$css: true
|
|
105
152
|
}
|
|
106
153
|
};
|
|
@@ -117,7 +164,6 @@ describe('rollup-plugin-stylex', () => {
|
|
|
117
164
|
it('preserves stylex.inject calls and does not extract CSS', async () => {
|
|
118
165
|
const { css, js } = await runStylex({
|
|
119
166
|
dev: true,
|
|
120
|
-
fileName: 'stylex.css',
|
|
121
167
|
});
|
|
122
168
|
|
|
123
169
|
expect(css).toBeUndefined();
|
|
@@ -125,49 +171,85 @@ describe('rollup-plugin-stylex', () => {
|
|
|
125
171
|
expect(js).toMatchInlineSnapshot(`
|
|
126
172
|
"import stylex from 'stylex';
|
|
127
173
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
176
|
+
*
|
|
177
|
+
* This source code is licensed under the MIT license found in the
|
|
178
|
+
* LICENSE file in the root directory of this source tree.
|
|
179
|
+
*
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
stylex.inject(".x1lliihq{display:block}", 3000);
|
|
184
|
+
stylex.inject(".xh8yej3{width:100%}", 4000);
|
|
131
185
|
var styles$2 = {
|
|
132
186
|
bar: {
|
|
133
187
|
"otherStyles__styles.bar": "otherStyles__styles.bar",
|
|
134
|
-
display: "
|
|
135
|
-
width: "
|
|
188
|
+
display: "x1lliihq",
|
|
189
|
+
width: "xh8yej3",
|
|
136
190
|
$$css: true
|
|
137
191
|
}
|
|
138
192
|
};
|
|
139
193
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
196
|
+
*
|
|
197
|
+
* This source code is licensed under the MIT license found in the
|
|
198
|
+
* LICENSE file in the root directory of this source tree.
|
|
199
|
+
*
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
stylex.inject(".xt0psk2{display:inline}", 3000);
|
|
204
|
+
stylex.inject(".x1egiwwb{height:500px}", 4000);
|
|
205
|
+
stylex.inject(".x3hqpx7{width:50%}", 4000);
|
|
144
206
|
const styles$1 = {
|
|
145
207
|
baz: {
|
|
146
208
|
"npmStyles__styles.baz": "npmStyles__styles.baz",
|
|
147
|
-
display: "
|
|
148
|
-
height: "
|
|
149
|
-
width: "
|
|
209
|
+
display: "xt0psk2",
|
|
210
|
+
height: "x1egiwwb",
|
|
211
|
+
width: "x3hqpx7",
|
|
150
212
|
$$css: true
|
|
151
213
|
}
|
|
152
214
|
};
|
|
153
215
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
218
|
+
*
|
|
219
|
+
* This source code is licensed under the MIT license found in the
|
|
220
|
+
* LICENSE file in the root directory of this source tree.
|
|
221
|
+
*
|
|
222
|
+
*
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
stylex.inject("@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}", 1);
|
|
226
|
+
stylex.inject(".xeuoslp{animation-name:xgnty7z-B}", 3000);
|
|
227
|
+
stylex.inject(".x78zum5{display:flex}", 3000);
|
|
228
|
+
stylex.inject(".x1hm9lzh{margin-inline-start:10px}", 3000);
|
|
229
|
+
stylex.inject(".xlrshdv{margin-top:99px}", 4000);
|
|
230
|
+
stylex.inject(".x1egiwwb{height:500px}", 4000);
|
|
231
|
+
stylex.inject(".x1oz5o6v:hover{background:red}", 1130);
|
|
162
232
|
var styles = {
|
|
163
233
|
foo: {
|
|
164
234
|
"index__styles.foo": "index__styles.foo",
|
|
165
|
-
animationName: "
|
|
166
|
-
display: "
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
235
|
+
animationName: "xeuoslp",
|
|
236
|
+
display: "x78zum5",
|
|
237
|
+
marginInlineStart: "x1hm9lzh",
|
|
238
|
+
marginLeft: null,
|
|
239
|
+
marginRight: null,
|
|
240
|
+
marginTop: "xlrshdv",
|
|
241
|
+
height: "x1egiwwb",
|
|
242
|
+
":hover_background": "x1oz5o6v",
|
|
243
|
+
":hover_backgroundAttachment": null,
|
|
244
|
+
":hover_backgroundClip": null,
|
|
245
|
+
":hover_backgroundColor": null,
|
|
246
|
+
":hover_backgroundImage": null,
|
|
247
|
+
":hover_backgroundOrigin": null,
|
|
248
|
+
":hover_backgroundPosition": null,
|
|
249
|
+
":hover_backgroundPositionX": null,
|
|
250
|
+
":hover_backgroundPositionY": null,
|
|
251
|
+
":hover_backgroundRepeat": null,
|
|
252
|
+
":hover_backgroundSize": null,
|
|
171
253
|
$$css: true
|
|
172
254
|
}
|
|
173
255
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Rollup plugin for
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Rollup plugin for StyleX",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"repository": "https://www.github.com/
|
|
6
|
+
"repository": "https://www.github.com/facebook/stylex",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "jest"
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/core": "^7.16.0",
|
|
21
|
-
"@stylexjs/babel-plugin": "0.
|
|
21
|
+
"@stylexjs/babel-plugin": "0.3.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/preset-env": "^7.16.8",
|
|
25
25
|
"@rollup/plugin-babel": "^6.0.0",
|
|
26
|
-
"@rollup/plugin-commonjs": "^
|
|
26
|
+
"@rollup/plugin-commonjs": "^25.0.3",
|
|
27
27
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
28
|
-
"rollup": "^3.
|
|
29
|
-
"@stylexjs/stylex": "0.
|
|
28
|
+
"rollup": "^3.26.3 || ^4.0.2",
|
|
29
|
+
"@stylexjs/stylex": "0.3.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
const babel = require('@babel/core');
|
|
@@ -18,11 +20,12 @@ const IS_DEV_ENV =
|
|
|
18
20
|
|
|
19
21
|
module.exports = function stylexPlugin({
|
|
20
22
|
dev = IS_DEV_ENV,
|
|
23
|
+
unstable_moduleResolution = { type: 'commonJS', rootDir: process.cwd() },
|
|
21
24
|
fileName = 'stylex.css',
|
|
22
|
-
|
|
25
|
+
babelConfig: { plugins = [], presets = [] } = {},
|
|
26
|
+
...options
|
|
23
27
|
} = {}) {
|
|
24
28
|
let stylexRules = {};
|
|
25
|
-
|
|
26
29
|
return {
|
|
27
30
|
name: 'rollup-plugin-stylex',
|
|
28
31
|
buildStart() {
|
|
@@ -31,8 +34,7 @@ module.exports = function stylexPlugin({
|
|
|
31
34
|
generateBundle() {
|
|
32
35
|
const rules = Object.values(stylexRules).flat();
|
|
33
36
|
if (rules.length > 0) {
|
|
34
|
-
const collectedCSS = stylexBabelPlugin.processStylexRules(rules);
|
|
35
|
-
|
|
37
|
+
const collectedCSS = stylexBabelPlugin.processStylexRules(rules, true);
|
|
36
38
|
this.emitFile({
|
|
37
39
|
fileName,
|
|
38
40
|
source: collectedCSS,
|
|
@@ -40,7 +42,7 @@ module.exports = function stylexPlugin({
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
},
|
|
43
|
-
shouldTransformCachedModule({ code, id, cache, meta }) {
|
|
45
|
+
shouldTransformCachedModule({ code: _code, id, cache: _cache, meta }) {
|
|
44
46
|
stylexRules[id] = meta.stylex;
|
|
45
47
|
return false;
|
|
46
48
|
},
|
|
@@ -55,14 +57,13 @@ module.exports = function stylexPlugin({
|
|
|
55
57
|
? flowSyntaxPlugin
|
|
56
58
|
: typescriptSyntaxPlugin,
|
|
57
59
|
jsxSyntaxPlugin,
|
|
58
|
-
[stylexBabelPlugin, { dev,
|
|
60
|
+
[stylexBabelPlugin, { dev, unstable_moduleResolution, ...options }],
|
|
59
61
|
],
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
|
|
63
65
|
stylexRules[id] = metadata.stylex;
|
|
64
66
|
}
|
|
65
|
-
|
|
66
67
|
return { code, map, meta: metadata };
|
|
67
68
|
},
|
|
68
69
|
};
|