@stylexjs/rollup-plugin 0.1.0-beta.6 → 0.2.0-beta.8
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/__tests__/index-test.js +12 -6
- package/package.json +3 -3
- package/src/index.js +25 -7
package/__tests__/index-test.js
CHANGED
|
@@ -77,7 +77,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
77
77
|
var styles$2 = {
|
|
78
78
|
bar: {
|
|
79
79
|
display: "xntgbld",
|
|
80
|
-
width: "x6mlivy"
|
|
80
|
+
width: "x6mlivy",
|
|
81
|
+
$$css: true
|
|
81
82
|
}
|
|
82
83
|
};
|
|
83
84
|
|
|
@@ -86,7 +87,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
86
87
|
baz: {
|
|
87
88
|
display: "x1wdx05y",
|
|
88
89
|
height: "x1je5kxa",
|
|
89
|
-
width: "x1u78jha"
|
|
90
|
+
width: "x1u78jha",
|
|
91
|
+
$$css: true
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
|
|
@@ -98,7 +100,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
98
100
|
marginStart: "x1n8p6zw",
|
|
99
101
|
marginBlockStart: "x188knyk",
|
|
100
102
|
height: "x1je5kxa",
|
|
101
|
-
":hover_background": "x1kflwvg"
|
|
103
|
+
":hover_background": "x1kflwvg",
|
|
104
|
+
$$css: true
|
|
102
105
|
}
|
|
103
106
|
};
|
|
104
107
|
function App() {
|
|
@@ -129,7 +132,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
129
132
|
bar: {
|
|
130
133
|
"otherStyles__styles.bar": "otherStyles__styles.bar",
|
|
131
134
|
display: "xntgbld",
|
|
132
|
-
width: "x6mlivy"
|
|
135
|
+
width: "x6mlivy",
|
|
136
|
+
$$css: true
|
|
133
137
|
}
|
|
134
138
|
};
|
|
135
139
|
|
|
@@ -142,7 +146,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
142
146
|
"npmStyles__styles.baz": "npmStyles__styles.baz",
|
|
143
147
|
display: "x1wdx05y",
|
|
144
148
|
height: "x1je5kxa",
|
|
145
|
-
width: "x1u78jha"
|
|
149
|
+
width: "x1u78jha",
|
|
150
|
+
$$css: true
|
|
146
151
|
}
|
|
147
152
|
};
|
|
148
153
|
|
|
@@ -162,7 +167,8 @@ describe('rollup-plugin-stylex', () => {
|
|
|
162
167
|
marginStart: "x1n8p6zw",
|
|
163
168
|
marginBlockStart: "x188knyk",
|
|
164
169
|
height: "x1je5kxa",
|
|
165
|
-
":hover_background": "x1kflwvg"
|
|
170
|
+
":hover_background": "x1kflwvg",
|
|
171
|
+
$$css: true
|
|
166
172
|
}
|
|
167
173
|
};
|
|
168
174
|
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.8",
|
|
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.8"
|
|
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.8"
|
|
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, id, 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
|
};
|