@stylexjs/rollup-plugin 0.7.4 → 0.8.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 +26 -1
- package/flow_modules/rollup/index.js +1 -1
- package/lib/es/index.mjs +14 -1
- package/lib/index.d.ts +9 -0
- package/lib/index.js +14 -2
- package/lib/index.js.flow +5 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -30,4 +30,29 @@ const config = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export default config;
|
|
33
|
-
```
|
|
33
|
+
```
|
|
34
|
+
## Plugin Options
|
|
35
|
+
It inherits all options from `@stylexjs/babel-plugin` and can be found [here 🔗](https://stylexjs.com/docs/api/configuration/babel-plugin/). Along with other options like <br/>
|
|
36
|
+
|
|
37
|
+
### fileName
|
|
38
|
+
```js
|
|
39
|
+
fileName: string // Default: 'stylex.css'
|
|
40
|
+
```
|
|
41
|
+
The name of the output css file.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
### useCSSLayers
|
|
45
|
+
```js
|
|
46
|
+
useCSSLayers: boolean // Default: false
|
|
47
|
+
```
|
|
48
|
+
Enabling this option switches Stylex from using `:not(#\#)` to using `@layers` for handling CSS specificity.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
### babelConfig
|
|
52
|
+
```js
|
|
53
|
+
babelConfig: {
|
|
54
|
+
plugins: PluginItem[],
|
|
55
|
+
presets: PluginItem[]
|
|
56
|
+
} // Default: { plugins: [], presets: [] }
|
|
57
|
+
```
|
|
58
|
+
List of custom babel plugins and presets which can be used during code transformation.
|
|
@@ -555,7 +555,7 @@ export type OutputPlugin = {
|
|
|
555
555
|
// eslint-disable-next-line no-redeclare
|
|
556
556
|
...Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>,
|
|
557
557
|
// eslint-disable-next-line no-redeclare
|
|
558
|
-
...Partial<{ [
|
|
558
|
+
...Partial<{ [_K in AddonHooks]: ObjectHook<AddonHook> }>,
|
|
559
559
|
cacheKey?: string,
|
|
560
560
|
name: string,
|
|
561
561
|
version?: string,
|
package/lib/es/index.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import flowSyntaxPlugin from '@babel/plugin-syntax-flow';
|
|
|
4
4
|
import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx';
|
|
5
5
|
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import { transform } from 'lightningcss';
|
|
8
|
+
import browserslist from 'browserslist';
|
|
9
|
+
import { browserslistToTargets } from 'lightningcss';
|
|
7
10
|
const IS_DEV_ENV = process.env.NODE_ENV === 'development' || process.env.BABEL_ENV === 'development';
|
|
8
11
|
export default function stylexPlugin() {
|
|
9
12
|
let {
|
|
@@ -19,6 +22,7 @@ export default function stylexPlugin() {
|
|
|
19
22
|
} = {},
|
|
20
23
|
importSources = ['stylex', '@stylexjs/stylex'],
|
|
21
24
|
useCSSLayers = false,
|
|
25
|
+
lightningcssOptions,
|
|
22
26
|
...options
|
|
23
27
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
28
|
let stylexRules = {};
|
|
@@ -31,9 +35,18 @@ export default function stylexPlugin() {
|
|
|
31
35
|
const rules = Object.values(stylexRules).flat();
|
|
32
36
|
if (rules.length > 0) {
|
|
33
37
|
const collectedCSS = stylexBabelPlugin.processStylexRules(rules, useCSSLayers);
|
|
38
|
+
const {
|
|
39
|
+
code
|
|
40
|
+
} = transform({
|
|
41
|
+
targets: browserslistToTargets(browserslist('>= 1%')),
|
|
42
|
+
...lightningcssOptions,
|
|
43
|
+
filename: fileName,
|
|
44
|
+
code: Buffer.from(collectedCSS)
|
|
45
|
+
});
|
|
46
|
+
const processedCSS = code.toString();
|
|
34
47
|
this.emitFile({
|
|
35
48
|
fileName,
|
|
36
|
-
source:
|
|
49
|
+
source: processedCSS,
|
|
37
50
|
type: 'asset'
|
|
38
51
|
});
|
|
39
52
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { type PluginItem } from '@babel/core';
|
|
11
11
|
import type { Options } from '@stylexjs/babel-plugin';
|
|
12
|
+
import type { TransformOptions } from 'lightningcss';
|
|
12
13
|
import type { Plugin } from 'rollup';
|
|
13
14
|
export type PluginOptions = Readonly<
|
|
14
15
|
Omit<
|
|
@@ -20,6 +21,10 @@ export type PluginOptions = Readonly<
|
|
|
20
21
|
presets?: ReadonlyArray<PluginItem>;
|
|
21
22
|
}>;
|
|
22
23
|
useCSSLayers?: boolean;
|
|
24
|
+
lightningcssOptions?: Omit<
|
|
25
|
+
TransformOptions<{}>,
|
|
26
|
+
'code' | 'filename' | 'visitor'
|
|
27
|
+
>;
|
|
23
28
|
})
|
|
24
29
|
> & {
|
|
25
30
|
fileName?: string;
|
|
@@ -28,6 +33,10 @@ export type PluginOptions = Readonly<
|
|
|
28
33
|
presets?: ReadonlyArray<PluginItem>;
|
|
29
34
|
}>;
|
|
30
35
|
useCSSLayers?: boolean;
|
|
36
|
+
lightningcssOptions?: Omit<
|
|
37
|
+
TransformOptions<{}>,
|
|
38
|
+
'code' | 'filename' | 'visitor'
|
|
39
|
+
>;
|
|
31
40
|
}
|
|
32
41
|
>;
|
|
33
42
|
declare function stylexPlugin($$PARAM_0$$: PluginOptions): Plugin;
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,9 @@ var _pluginSyntaxFlow = _interopRequireDefault(require("@babel/plugin-syntax-flo
|
|
|
10
10
|
var _pluginSyntaxJsx = _interopRequireDefault(require("@babel/plugin-syntax-jsx"));
|
|
11
11
|
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
13
|
+
var _lightningcss = require("lightningcss");
|
|
14
|
+
var _browserslist = _interopRequireDefault(require("browserslist"));
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
16
|
const IS_DEV_ENV = process.env.NODE_ENV === 'development' || process.env.BABEL_ENV === 'development';
|
|
15
17
|
function stylexPlugin() {
|
|
16
18
|
let {
|
|
@@ -26,6 +28,7 @@ function stylexPlugin() {
|
|
|
26
28
|
} = {},
|
|
27
29
|
importSources = ['stylex', '@stylexjs/stylex'],
|
|
28
30
|
useCSSLayers = false,
|
|
31
|
+
lightningcssOptions,
|
|
29
32
|
...options
|
|
30
33
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
34
|
let stylexRules = {};
|
|
@@ -38,9 +41,18 @@ function stylexPlugin() {
|
|
|
38
41
|
const rules = Object.values(stylexRules).flat();
|
|
39
42
|
if (rules.length > 0) {
|
|
40
43
|
const collectedCSS = _babelPlugin.default.processStylexRules(rules, useCSSLayers);
|
|
44
|
+
const {
|
|
45
|
+
code
|
|
46
|
+
} = (0, _lightningcss.transform)({
|
|
47
|
+
targets: (0, _lightningcss.browserslistToTargets)((0, _browserslist.default)('>= 1%')),
|
|
48
|
+
...lightningcssOptions,
|
|
49
|
+
filename: fileName,
|
|
50
|
+
code: Buffer.from(collectedCSS)
|
|
51
|
+
});
|
|
52
|
+
const processedCSS = code.toString();
|
|
41
53
|
this.emitFile({
|
|
42
54
|
fileName,
|
|
43
|
-
source:
|
|
55
|
+
source: processedCSS,
|
|
44
56
|
type: 'asset'
|
|
45
57
|
});
|
|
46
58
|
}
|
package/lib/index.js.flow
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import { type PluginItem } from '../flow_modules/@babel/core';
|
|
11
11
|
import type { Options } from '@stylexjs/babel-plugin';
|
|
12
|
+
import type { TransformOptions } from 'lightningcss';
|
|
12
13
|
import type { Plugin } from '../flow_modules/rollup';
|
|
13
|
-
|
|
14
14
|
export type PluginOptions = $ReadOnly<{
|
|
15
15
|
...Partial<Options>,
|
|
16
16
|
fileName?: string,
|
|
@@ -19,6 +19,10 @@ export type PluginOptions = $ReadOnly<{
|
|
|
19
19
|
presets?: $ReadOnlyArray<PluginItem>,
|
|
20
20
|
}>,
|
|
21
21
|
useCSSLayers?: boolean,
|
|
22
|
+
lightningcssOptions?: Omit<
|
|
23
|
+
TransformOptions<{}>,
|
|
24
|
+
'code' | 'filename' | 'visitor',
|
|
25
|
+
>,
|
|
22
26
|
...
|
|
23
27
|
}>;
|
|
24
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Rollup plugin for StyleX",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/es/index.mjs",
|
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.23.9",
|
|
35
|
-
"@stylexjs/babel-plugin": "0.7.4",
|
|
36
35
|
"@babel/plugin-syntax-flow": "^7.23.3",
|
|
37
36
|
"@babel/plugin-syntax-jsx": "^7.23.3",
|
|
38
|
-
"@babel/plugin-syntax-typescript": "^7.23.3"
|
|
37
|
+
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
38
|
+
"@stylexjs/babel-plugin": "0.8.0",
|
|
39
|
+
"lightningcss": "^1.27.0"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
42
|
"flow_modules/*",
|