@stylexswc/rollup-plugin 0.5.1 → 0.6.0-rc.1

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 CHANGED
@@ -47,9 +47,44 @@ module.exports = config;
47
47
  ```
48
48
 
49
49
  ## Plugin Options
50
- The options are similar like `@stylexjs/babel-plugin` and can be found [here](https://stylexjs.com/docs/api/configuration/babel-plugin/)
50
+
51
+ The plugin accepts the following configuration options:
52
+
53
+ ### `rsOptions`
54
+
55
+ - Type: `StyleXOptions`
56
+ - Optional
57
+ - Default: `{}`
58
+ - Description: StyleX compiler options that extend from `@stylexswc/rs-compiler`
59
+
60
+ ### `fileName`
61
+
62
+ - Type: `string`
63
+ - Optional
64
+ - Default: `'stylex.css'`
65
+ - Description: Name of the output CSS file
66
+
67
+ ### `useCSSLayers`
68
+
69
+ - Type: `boolean`
70
+ - Optional
71
+ - Default: `false`
72
+ - Description: Enable CSS Layers support for better style isolation
73
+
74
+ ### `lightningcssOptions`
75
+
76
+ - Type: `TransformOptions`
77
+ - Optional
78
+ - Description: LightningCSS transform options (excluding code, filename, and visitor properties)
79
+
80
+ ### `extractCSS`
81
+
82
+ - Type: `boolean`
83
+ - Optional
84
+ - Default: `true`
85
+ - Description: Controls whether CSS should be extracted into a separate file
51
86
 
52
87
  ## Documentation
53
88
 
54
- * [StyleX Documentation](https://stylexjs.com)
55
- * [NAPI-RS compiler for StyleX](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/crates/stylex-rs-compiler)
89
+ - [StyleX Documentation](https://stylexjs.com)
90
+ - [NAPI-RS compiler for StyleX](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/crates/stylex-rs-compiler)
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export type PluginOptions = {
6
6
  fileName?: string;
7
7
  useCSSLayers?: boolean;
8
8
  lightningcssOptions?: Omit<TransformOptions<{}>, 'code' | 'filename' | 'visitor'>;
9
+ extractCSS?: boolean;
9
10
  };
10
- export default function stylexPlugin({ rsOptions, fileName, useCSSLayers, lightningcssOptions, }?: PluginOptions): Plugin;
11
+ export default function stylexPlugin({ rsOptions, fileName, useCSSLayers, lightningcssOptions, extractCSS, }?: PluginOptions): Plugin;
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAA0D,MAAM,QAAQ,CAAC;AAK7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAI5D,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;CACnF,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,SAAc,EACd,QAAuB,EACvB,YAAoB,EACpB,mBAAmB,GACpB,GAAE,aAAkB,GAAG,MAAM,CAiG7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAA0D,MAAM,QAAQ,CAAC;AAM7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAY5D,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,SAAc,EACd,QAAuB,EACvB,YAAoB,EACpB,mBAAmB,EACnB,UAAiB,GAClB,GAAE,aAAkB,GAAG,MAAM,CAiG7B"}
package/dist/index.js CHANGED
@@ -9,8 +9,16 @@ const lightningcss_1 = require("lightningcss");
9
9
  const browserslist_1 = __importDefault(require("browserslist"));
10
10
  const lightningcss_2 = require("lightningcss");
11
11
  const babel_plugin_1 = __importDefault(require("@stylexjs/babel-plugin"));
12
+ const crypto_1 = __importDefault(require("crypto"));
12
13
  const IS_DEV_ENV = process.env.NODE_ENV === 'development';
13
- function stylexPlugin({ rsOptions = {}, fileName = 'stylex.css', useCSSLayers = false, lightningcssOptions, } = {}) {
14
+ function replaceFileName(original, css) {
15
+ if (!original.includes('[hash]')) {
16
+ return original;
17
+ }
18
+ const hash = crypto_1.default.createHash('sha256').update(css).digest('hex').slice(0, 8);
19
+ return original.replace(/\[hash\]/g, hash);
20
+ }
21
+ function stylexPlugin({ rsOptions = {}, fileName = 'stylex.css', useCSSLayers = false, lightningcssOptions, extractCSS = true, } = {}) {
14
22
  const { dev = IS_DEV_ENV, unstable_moduleResolution = { type: 'commonJS', rootDir: process.cwd() }, importSources = ['stylex', '@stylexjs/stylex'], ...options } = rsOptions;
15
23
  let stylexRules = {};
16
24
  return {
@@ -26,13 +34,13 @@ function stylexPlugin({ rsOptions = {}, fileName = 'stylex.css', useCSSLayers =
26
34
  const { code } = (0, lightningcss_1.transform)({
27
35
  targets: (0, lightningcss_2.browserslistToTargets)((0, browserslist_1.default)('>= 1%')),
28
36
  ...lightningcssOptions,
29
- filename: fileName,
37
+ filename: 'stylex.css',
30
38
  code: Buffer.from(collectedCSS),
31
39
  });
32
40
  // Convert the Buffer back to a string
33
41
  const processedCSS = code.toString();
34
42
  this.emitFile({
35
- fileName,
43
+ fileName: replaceFileName(fileName, processedCSS),
36
44
  source: processedCSS,
37
45
  type: 'asset',
38
46
  });
@@ -79,7 +87,7 @@ function stylexPlugin({ rsOptions = {}, fileName = 'stylex.css', useCSSLayers =
79
87
  }
80
88
  }
81
89
  }
82
- if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
90
+ if (extractCSS && !dev && metadata.stylex != null && metadata.stylex.length > 0) {
83
91
  stylexRules[id] = metadata.stylex;
84
92
  }
85
93
  return { code, map: map, meta: metadata };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stylexswc/rollup-plugin",
3
- "description": "Stylex rollup plugin with NAPI-RS compiler",
4
- "version": "0.5.1",
3
+ "description": "StyleX rollup plugin with NAPI-RS compiler",
4
+ "version": "0.6.0-rc.1",
5
5
  "config": {
6
6
  "scripty": {
7
7
  "path": "../../scripts/packages"
@@ -9,10 +9,10 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@stylexjs/babel-plugin": "^0.9.3",
12
- "@stylexswc/rs-compiler": "0.5.1",
13
12
  "lightningcss": "^1.27.0"
14
13
  },
15
14
  "devDependencies": {
15
+ "@stylexswc/rs-compiler": "0.6.0-rc.1",
16
16
  "@types/node": "^22.5.1",
17
17
  "browserslist": "^4.24.2",
18
18
  "rollup": "^4.25.0"
@@ -31,7 +31,8 @@
31
31
  "keywords": [
32
32
  "rollup-plugin",
33
33
  "rolup",
34
- "stylex"
34
+ "stylex",
35
+ "swc"
35
36
  ],
36
37
  "license": "MIT",
37
38
  "main": "dist/index.js",