unplugin-stylex 0.5.4 → 0.6.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/CHANGELOG.md +12 -0
- package/README.md +1 -4
- package/biome.json +64 -4
- package/dist/astro.cjs +84 -0
- package/dist/astro.d.cts +39 -0
- package/dist/astro.d.ts +39 -0
- package/dist/astro.js +84 -0
- package/dist/chunk-7LU6DGX6.cjs +12 -0
- package/dist/{chunk-QPFVWZ5B.js → chunk-B3OIQQRZ.js} +134 -23
- package/dist/chunk-F2LYIKCV.js +12 -0
- package/dist/{chunk-NQYXBBLC.cjs → chunk-IU3ZVEOU.cjs} +131 -20
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.d.cts +2 -0
- package/dist/esbuild.d.ts +2 -0
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +2 -2
- package/dist/farm.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/rolldown.cjs +2 -2
- package/dist/rolldown.d.cts +2 -0
- package/dist/rolldown.d.ts +2 -0
- package/dist/rolldown.js +1 -1
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.d.cts +2 -0
- package/dist/rollup.d.ts +2 -0
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.d.cts +2 -0
- package/dist/rspack.d.ts +2 -0
- package/dist/rspack.js +1 -1
- package/dist/types.d.cts +14 -1
- package/dist/types.d.ts +14 -1
- package/dist/vite.cjs +3 -7
- package/dist/vite.d.cts +2 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +3 -7
- package/dist/webpack.cjs +2 -2
- package/dist/webpack.d.cts +2 -0
- package/dist/webpack.d.ts +2 -0
- package/dist/webpack.js +1 -1
- package/jsr.json +6 -1
- package/package.json +23 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# unplugin-stylex
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#164](https://github.com/eryue0220/unplugin-stylex/pull/164) [`7d76bb1`](https://github.com/eryue0220/unplugin-stylex/commit/7d76bb1699af43a47a151e4ec80a633983544ac0) Thanks [@eryue0220](https://github.com/eryue0220)! - Fixed bug and support more frameworks
|
|
8
|
+
|
|
9
|
+
## 0.5.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#119](https://github.com/eryue0220/unplugin-stylex/pull/119) [`9bb6f3c`](https://github.com/eryue0220/unplugin-stylex/commit/9bb6f3c5936fb50e950bb84e7d614f5e9665f817) Thanks [@sfc-gh-alisowski](https://github.com/sfc-gh-alisowski)! - Upgrade stylex
|
|
14
|
+
|
|
3
15
|
## 0.5.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# unplugin-stylex · [](https://github.com/eryue0220/unplugin-stylex/blob/main/LICENSE) [](https://www.npmjs.com/package/unplugin-stylex)
|
|
2
2
|
|
|
3
|
-
> [!WARNING]
|
|
4
|
-
> This plugin is in early development and may not work as expected. Please report any issues you find.
|
|
5
|
-
|
|
6
3
|
## Installation
|
|
7
4
|
|
|
8
5
|
Install the package from the following command
|
|
@@ -95,7 +92,7 @@ module.exports = {
|
|
|
95
92
|
</br></details>
|
|
96
93
|
|
|
97
94
|
<details>
|
|
98
|
-
<summary>rolldown
|
|
95
|
+
<summary>rolldown</summary><br>
|
|
99
96
|
|
|
100
97
|
```js
|
|
101
98
|
// rolldown.config.js
|
package/biome.json
CHANGED
|
@@ -1,10 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"html": {
|
|
3
|
+
"formatter": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"indentScriptAndStyle": true,
|
|
6
|
+
"indentStyle": "space",
|
|
7
|
+
"indentWidth": 2
|
|
8
|
+
},
|
|
9
|
+
"parser": {
|
|
10
|
+
"interpolation": true
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"javascript": {
|
|
14
|
+
"formatter": {
|
|
15
|
+
"lineWidth": 120,
|
|
16
|
+
"indentWidth": 2,
|
|
17
|
+
"indentStyle": "space",
|
|
18
|
+
"quoteStyle": "single",
|
|
19
|
+
"semicolons": "asNeeded"
|
|
20
|
+
},
|
|
21
|
+
"linter": {
|
|
22
|
+
"enabled": false
|
|
23
|
+
},
|
|
24
|
+
"jsxRuntime": "reactClassic"
|
|
25
|
+
},
|
|
26
|
+
"json": {
|
|
27
|
+
"formatter": {
|
|
28
|
+
"enabled": true,
|
|
29
|
+
"indentStyle": "space",
|
|
30
|
+
"indentWidth": 2
|
|
31
|
+
}
|
|
32
|
+
},
|
|
3
33
|
"files": {
|
|
4
|
-
"
|
|
5
|
-
|
|
34
|
+
"includes": [
|
|
35
|
+
"examples/**",
|
|
36
|
+
"!!**/.astro",
|
|
37
|
+
"!examples/**/node_modules",
|
|
38
|
+
"!examples/**/dist",
|
|
39
|
+
"src/**",
|
|
40
|
+
"test/**"
|
|
41
|
+
]
|
|
6
42
|
},
|
|
7
43
|
"linter": {
|
|
8
44
|
"enabled": true
|
|
9
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"overrides": [
|
|
47
|
+
{
|
|
48
|
+
"includes": ["**/*.astro", "**/*.vue"],
|
|
49
|
+
"linter": {
|
|
50
|
+
"rules": {
|
|
51
|
+
"correctness": {
|
|
52
|
+
"noUnusedVariables": "off",
|
|
53
|
+
"noUnusedImports": "off"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"includes": ["examples/rollup-example/public/index.html"],
|
|
60
|
+
"html": {
|
|
61
|
+
"formatter": {
|
|
62
|
+
"enabled": false
|
|
63
|
+
},
|
|
64
|
+
"linter": {
|
|
65
|
+
"enabled": false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
]
|
|
10
70
|
}
|
package/dist/astro.cjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunk7LU6DGX6cjs = require('./chunk-7LU6DGX6.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkIU3ZVEOUcjs = require('./chunk-IU3ZVEOU.cjs');
|
|
11
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
12
|
+
|
|
13
|
+
// src/astro.ts
|
|
14
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
15
|
+
function astro(options = {}) {
|
|
16
|
+
const configured = _chunkIU3ZVEOUcjs.getOptions.call(void 0, { ...options, framework: "vite" });
|
|
17
|
+
const filename = configured.stylex.filename;
|
|
18
|
+
return {
|
|
19
|
+
name: _chunkIU3ZVEOUcjs.PLUGIN_NAME,
|
|
20
|
+
hooks: {
|
|
21
|
+
"astro:config:setup": async ({ config, updateConfig, injectScript }) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const astroOptions = {
|
|
24
|
+
...options,
|
|
25
|
+
validExts: _nullishCoalesce(options.validExts, () => ( /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/))
|
|
26
|
+
};
|
|
27
|
+
if (!_chunkIU3ZVEOUcjs.stylexRulesStore.has(_chunkIU3ZVEOUcjs.STORE_KEY)) {
|
|
28
|
+
_chunkIU3ZVEOUcjs.stylexRulesStore.set(_chunkIU3ZVEOUcjs.STORE_KEY, {});
|
|
29
|
+
}
|
|
30
|
+
config.vite.plugins ??= [];
|
|
31
|
+
const basePlugin = _chunk7LU6DGX6cjs.vite_default.call(void 0, astroOptions);
|
|
32
|
+
const wrappedPlugin = {
|
|
33
|
+
...basePlugin,
|
|
34
|
+
getStylexRules: () => _chunkIU3ZVEOUcjs.stylexRulesStore.get(_chunkIU3ZVEOUcjs.STORE_KEY) || {}
|
|
35
|
+
};
|
|
36
|
+
const base = _nullishCoalesce(config.base, () => ( "/"));
|
|
37
|
+
const cssPath = path.posix.join(base, filename).replace(/\/+/g, "/");
|
|
38
|
+
injectScript(
|
|
39
|
+
"head-inline",
|
|
40
|
+
`
|
|
41
|
+
(function() {
|
|
42
|
+
const link = document.createElement('link');
|
|
43
|
+
link.rel = 'stylesheet';
|
|
44
|
+
link.href = ${JSON.stringify(cssPath)};
|
|
45
|
+
document.head.appendChild(link);
|
|
46
|
+
})();
|
|
47
|
+
`
|
|
48
|
+
);
|
|
49
|
+
config.vite.plugins.push(wrappedPlugin);
|
|
50
|
+
const currentNoExternal = _nullishCoalesce(((_a = config.vite.ssr) == null ? void 0 : _a.noExternal), () => ( []));
|
|
51
|
+
const noExternal = Array.isArray(currentNoExternal) ? [...currentNoExternal] : [];
|
|
52
|
+
if (!noExternal.includes("@stylexjs/stylex")) {
|
|
53
|
+
noExternal.push("@stylexjs/stylex");
|
|
54
|
+
}
|
|
55
|
+
updateConfig({
|
|
56
|
+
vite: {
|
|
57
|
+
ssr: {
|
|
58
|
+
noExternal
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
"astro:server:setup": ({ server }) => {
|
|
64
|
+
server.middlewares.use((req, res, next) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const base = "/";
|
|
67
|
+
const cssPath = path.posix.join(base, filename).replace(/\/+/g, base);
|
|
68
|
+
if (req.url === cssPath || req.url === `/${filename}` || ((_a = req.url) == null ? void 0 : _a.endsWith(`/${filename}`))) {
|
|
69
|
+
const stylexRules = _nullishCoalesce(_chunkIU3ZVEOUcjs.stylexRulesStore.get(_chunkIU3ZVEOUcjs.STORE_KEY), () => ( {}));
|
|
70
|
+
const collectedCSS = _chunkIU3ZVEOUcjs.buildStylexRules.call(void 0, stylexRules, _nullishCoalesce(((_b = options.stylex) == null ? void 0 : _b.useCSSLayers), () => ( false)));
|
|
71
|
+
res.setHeader("Content-Type", "text/css");
|
|
72
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
73
|
+
res.end(_nullishCoalesce(collectedCSS, () => ( "")));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
next();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
exports.default = astro;
|
package/dist/astro.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { UnpluginStylexOptions } from './types.cjs';
|
|
2
|
+
import '@babel/core';
|
|
3
|
+
import '@stylexjs/babel-plugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This entry file is for astro plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Astro plugin
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* import { defineConfig } from 'astro/config'
|
|
17
|
+
* import stylexAstroPlugin from 'unplugin-stylex/astro'
|
|
18
|
+
*
|
|
19
|
+
* export default defineConfig({
|
|
20
|
+
* integrations: [
|
|
21
|
+
* stylexAstroPlugin(),
|
|
22
|
+
* ],
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
declare function astro(options?: UnpluginStylexOptions): {
|
|
26
|
+
name: string;
|
|
27
|
+
hooks: {
|
|
28
|
+
'astro:config:setup': ({ config, updateConfig, injectScript }: {
|
|
29
|
+
config: any;
|
|
30
|
+
updateConfig: any;
|
|
31
|
+
injectScript: any;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
'astro:server:setup': ({ server }: {
|
|
34
|
+
server: any;
|
|
35
|
+
}) => void;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { astro as default };
|
package/dist/astro.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { UnpluginStylexOptions } from './types.js';
|
|
2
|
+
import '@babel/core';
|
|
3
|
+
import '@stylexjs/babel-plugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This entry file is for astro plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Astro plugin
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* import { defineConfig } from 'astro/config'
|
|
17
|
+
* import stylexAstroPlugin from 'unplugin-stylex/astro'
|
|
18
|
+
*
|
|
19
|
+
* export default defineConfig({
|
|
20
|
+
* integrations: [
|
|
21
|
+
* stylexAstroPlugin(),
|
|
22
|
+
* ],
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
declare function astro(options?: UnpluginStylexOptions): {
|
|
26
|
+
name: string;
|
|
27
|
+
hooks: {
|
|
28
|
+
'astro:config:setup': ({ config, updateConfig, injectScript }: {
|
|
29
|
+
config: any;
|
|
30
|
+
updateConfig: any;
|
|
31
|
+
injectScript: any;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
'astro:server:setup': ({ server }: {
|
|
34
|
+
server: any;
|
|
35
|
+
}) => void;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { astro as default };
|
package/dist/astro.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
vite_default
|
|
3
|
+
} from "./chunk-F2LYIKCV.js";
|
|
4
|
+
import {
|
|
5
|
+
PLUGIN_NAME,
|
|
6
|
+
STORE_KEY,
|
|
7
|
+
buildStylexRules,
|
|
8
|
+
getOptions,
|
|
9
|
+
stylexRulesStore
|
|
10
|
+
} from "./chunk-B3OIQQRZ.js";
|
|
11
|
+
import "./chunk-6F4PWJZI.js";
|
|
12
|
+
|
|
13
|
+
// src/astro.ts
|
|
14
|
+
import * as path from "path";
|
|
15
|
+
function astro(options = {}) {
|
|
16
|
+
const configured = getOptions({ ...options, framework: "vite" });
|
|
17
|
+
const filename = configured.stylex.filename;
|
|
18
|
+
return {
|
|
19
|
+
name: PLUGIN_NAME,
|
|
20
|
+
hooks: {
|
|
21
|
+
"astro:config:setup": async ({ config, updateConfig, injectScript }) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const astroOptions = {
|
|
24
|
+
...options,
|
|
25
|
+
validExts: options.validExts ?? /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/
|
|
26
|
+
};
|
|
27
|
+
if (!stylexRulesStore.has(STORE_KEY)) {
|
|
28
|
+
stylexRulesStore.set(STORE_KEY, {});
|
|
29
|
+
}
|
|
30
|
+
config.vite.plugins ??= [];
|
|
31
|
+
const basePlugin = vite_default(astroOptions);
|
|
32
|
+
const wrappedPlugin = {
|
|
33
|
+
...basePlugin,
|
|
34
|
+
getStylexRules: () => stylexRulesStore.get(STORE_KEY) || {}
|
|
35
|
+
};
|
|
36
|
+
const base = config.base ?? "/";
|
|
37
|
+
const cssPath = path.posix.join(base, filename).replace(/\/+/g, "/");
|
|
38
|
+
injectScript(
|
|
39
|
+
"head-inline",
|
|
40
|
+
`
|
|
41
|
+
(function() {
|
|
42
|
+
const link = document.createElement('link');
|
|
43
|
+
link.rel = 'stylesheet';
|
|
44
|
+
link.href = ${JSON.stringify(cssPath)};
|
|
45
|
+
document.head.appendChild(link);
|
|
46
|
+
})();
|
|
47
|
+
`
|
|
48
|
+
);
|
|
49
|
+
config.vite.plugins.push(wrappedPlugin);
|
|
50
|
+
const currentNoExternal = ((_a = config.vite.ssr) == null ? void 0 : _a.noExternal) ?? [];
|
|
51
|
+
const noExternal = Array.isArray(currentNoExternal) ? [...currentNoExternal] : [];
|
|
52
|
+
if (!noExternal.includes("@stylexjs/stylex")) {
|
|
53
|
+
noExternal.push("@stylexjs/stylex");
|
|
54
|
+
}
|
|
55
|
+
updateConfig({
|
|
56
|
+
vite: {
|
|
57
|
+
ssr: {
|
|
58
|
+
noExternal
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
"astro:server:setup": ({ server }) => {
|
|
64
|
+
server.middlewares.use((req, res, next) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const base = "/";
|
|
67
|
+
const cssPath = path.posix.join(base, filename).replace(/\/+/g, base);
|
|
68
|
+
if (req.url === cssPath || req.url === `/${filename}` || ((_a = req.url) == null ? void 0 : _a.endsWith(`/${filename}`))) {
|
|
69
|
+
const stylexRules = stylexRulesStore.get(STORE_KEY) ?? {};
|
|
70
|
+
const collectedCSS = buildStylexRules(stylexRules, ((_b = options.stylex) == null ? void 0 : _b.useCSSLayers) ?? false);
|
|
71
|
+
res.setHeader("Content-Type", "text/css");
|
|
72
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
73
|
+
res.end(collectedCSS ?? "");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
next();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
astro as default
|
|
84
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkIU3ZVEOUcjs = require('./chunk-IU3ZVEOU.cjs');
|
|
4
|
+
|
|
5
|
+
// src/vite.ts
|
|
6
|
+
var _unplugin = require('unplugin');
|
|
7
|
+
var vitePlugin = _unplugin.createVitePlugin.call(void 0, _chunkIU3ZVEOUcjs.unpluginFactory);
|
|
8
|
+
var vite_default = vitePlugin;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.vite_default = vite_default;
|
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
-
import * as path2 from "
|
|
9
|
+
import * as path2 from "path";
|
|
10
10
|
import { createUnplugin } from "unplugin";
|
|
11
11
|
|
|
12
12
|
// src/core/build.ts
|
|
@@ -23,8 +23,8 @@ var isDevelopment = process.env.NODE_ENV !== "production" || process.env.BABEL_E
|
|
|
23
23
|
var EXTENSIONS = [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"];
|
|
24
24
|
|
|
25
25
|
// src/utils/get-aliases.ts
|
|
26
|
-
import fs from "
|
|
27
|
-
import path from "
|
|
26
|
+
import fs from "fs";
|
|
27
|
+
import path from "path";
|
|
28
28
|
function makePathAbsolute(value) {
|
|
29
29
|
return path.isAbsolute(value) ? value : path.resolve(process.cwd(), value);
|
|
30
30
|
}
|
|
@@ -50,7 +50,7 @@ function getAliasesFromTSConfig() {
|
|
|
50
50
|
{}
|
|
51
51
|
);
|
|
52
52
|
return Object.keys(aliases).length > 0 ? aliases : void 0;
|
|
53
|
-
} catch
|
|
53
|
+
} catch {
|
|
54
54
|
return void 0;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -72,7 +72,7 @@ function getAliasesFromViteConfig() {
|
|
|
72
72
|
},
|
|
73
73
|
{}
|
|
74
74
|
);
|
|
75
|
-
} catch
|
|
75
|
+
} catch {
|
|
76
76
|
return {};
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -94,7 +94,7 @@ function getAliasesFromWebpackConfig() {
|
|
|
94
94
|
},
|
|
95
95
|
{}
|
|
96
96
|
);
|
|
97
|
-
} catch
|
|
97
|
+
} catch {
|
|
98
98
|
return {};
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -125,7 +125,7 @@ function getAliasesFromRollupConfig() {
|
|
|
125
125
|
},
|
|
126
126
|
{}
|
|
127
127
|
);
|
|
128
|
-
} catch
|
|
128
|
+
} catch {
|
|
129
129
|
return {};
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -147,7 +147,7 @@ function getAliasesFromRolldownConfig() {
|
|
|
147
147
|
},
|
|
148
148
|
{}
|
|
149
149
|
);
|
|
150
|
-
} catch
|
|
150
|
+
} catch {
|
|
151
151
|
return {};
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -172,7 +172,7 @@ function getAliasesFromRspackConfig() {
|
|
|
172
172
|
},
|
|
173
173
|
{}
|
|
174
174
|
);
|
|
175
|
-
} catch
|
|
175
|
+
} catch {
|
|
176
176
|
return {};
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -194,7 +194,7 @@ function getAliasesFromFarmConfig() {
|
|
|
194
194
|
},
|
|
195
195
|
{}
|
|
196
196
|
);
|
|
197
|
-
} catch
|
|
197
|
+
} catch {
|
|
198
198
|
return {};
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -251,6 +251,10 @@ function getAliases(framework) {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
// src/utils/store.ts
|
|
255
|
+
var STORE_KEY = `stylex-${PLUGIN_NAME}`;
|
|
256
|
+
var stylexRulesStore = /* @__PURE__ */ new Map();
|
|
257
|
+
|
|
254
258
|
// src/core/options.ts
|
|
255
259
|
function getOptions(options) {
|
|
256
260
|
var _a, _b, _c;
|
|
@@ -260,8 +264,8 @@ function getOptions(options) {
|
|
|
260
264
|
return {
|
|
261
265
|
...options,
|
|
262
266
|
dev: isDev,
|
|
263
|
-
// .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts
|
|
264
|
-
validExts: options.validExts ?? /\.[mc]?[jt]sx
|
|
267
|
+
// .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts, .svelte, .vue
|
|
268
|
+
validExts: options.validExts ?? /\.[mc]?[jt]sx?$|\.svelte$|\.vue$/,
|
|
265
269
|
stylex: {
|
|
266
270
|
filename: stylex2.filename || "stylex.css",
|
|
267
271
|
stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
|
|
@@ -279,8 +283,8 @@ function getOptions(options) {
|
|
|
279
283
|
};
|
|
280
284
|
}
|
|
281
285
|
|
|
282
|
-
// src/core/
|
|
283
|
-
import { extname as pathExtname } from "
|
|
286
|
+
// src/core/transformers/default.ts
|
|
287
|
+
import { extname as pathExtname } from "path";
|
|
284
288
|
import { transformAsync } from "@babel/core";
|
|
285
289
|
import jsxSyntaxPlugin from "@babel/plugin-syntax-jsx";
|
|
286
290
|
import stylexBabelPlugin from "@stylexjs/babel-plugin";
|
|
@@ -293,11 +297,11 @@ function getSyntaxPlugins(extname2) {
|
|
|
293
297
|
return [".js", ".jsx"].includes(extname2) ? [flowSyntaxPlugin] : TSPlugin;
|
|
294
298
|
}
|
|
295
299
|
|
|
296
|
-
// src/core/
|
|
297
|
-
async
|
|
300
|
+
// src/core/transformers/default.ts
|
|
301
|
+
var defaultTransformer = async (context) => {
|
|
298
302
|
var _a, _b, _c, _d;
|
|
299
|
-
const {
|
|
300
|
-
const stylex2 = options.stylex;
|
|
303
|
+
const { inputCode, id, options } = context;
|
|
304
|
+
const stylex2 = options.stylex ?? {};
|
|
301
305
|
const extname2 = pathExtname(id);
|
|
302
306
|
const stylexRules = {};
|
|
303
307
|
const stylexBabelPluginOptions = {
|
|
@@ -329,12 +333,93 @@ async function transformer(context) {
|
|
|
329
333
|
};
|
|
330
334
|
}
|
|
331
335
|
return { code, stylexRules };
|
|
332
|
-
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// src/core/transformers/astro.ts
|
|
339
|
+
var astro = async (context) => {
|
|
340
|
+
const { inputCode, id, options } = context;
|
|
341
|
+
const frontmatterMatch = inputCode.match(/^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/);
|
|
342
|
+
if (!frontmatterMatch) {
|
|
343
|
+
return {
|
|
344
|
+
code: inputCode,
|
|
345
|
+
map: void 0,
|
|
346
|
+
stylexRules: {}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
const frontmatterContent = frontmatterMatch[1];
|
|
350
|
+
const templateContent = frontmatterMatch[2] ?? "";
|
|
351
|
+
const stylex2 = options.stylex ?? {};
|
|
352
|
+
const stylexImports = stylex2.stylexImports ?? ["@stylexjs/stylex"];
|
|
353
|
+
if (!stylexImports.some((importName) => frontmatterContent.includes(importName))) {
|
|
354
|
+
return {
|
|
355
|
+
code: inputCode,
|
|
356
|
+
map: void 0,
|
|
357
|
+
stylexRules: {}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const ctx = {
|
|
361
|
+
id,
|
|
362
|
+
inputCode: frontmatterContent,
|
|
363
|
+
pluginContext: context.pluginContext,
|
|
364
|
+
options
|
|
365
|
+
};
|
|
366
|
+
const result = await defaultTransformer(ctx);
|
|
367
|
+
const transformedFrontmatter = `---
|
|
368
|
+
${result.code}
|
|
369
|
+
---`;
|
|
370
|
+
const transformedCode = transformedFrontmatter + (templateContent ? `
|
|
371
|
+
${templateContent}` : "");
|
|
372
|
+
return {
|
|
373
|
+
code: transformedCode,
|
|
374
|
+
map: result.map,
|
|
375
|
+
stylexRules: result.stylexRules
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/core/transformers/svelte.ts
|
|
380
|
+
var svelte = async (context) => {
|
|
381
|
+
const { inputCode, id, options } = context;
|
|
382
|
+
const scriptMatch = inputCode.match(/<script([^>]*)>([\s\S]*?)<\/script>/i);
|
|
383
|
+
if (!scriptMatch) {
|
|
384
|
+
return {
|
|
385
|
+
code: inputCode,
|
|
386
|
+
map: void 0,
|
|
387
|
+
stylexRules: {}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const scriptAttrs = scriptMatch[1];
|
|
391
|
+
const scriptContent = scriptMatch[2];
|
|
392
|
+
const fullScriptTag = scriptMatch[0];
|
|
393
|
+
const ctx = {
|
|
394
|
+
id,
|
|
395
|
+
inputCode: scriptContent,
|
|
396
|
+
pluginContext: void 0,
|
|
397
|
+
options
|
|
398
|
+
};
|
|
399
|
+
const result = await defaultTransformer(ctx);
|
|
400
|
+
const transformedScriptTag = `<script${scriptAttrs}>${result.code}</script>`;
|
|
401
|
+
const transformedCode = inputCode.replace(fullScriptTag, transformedScriptTag);
|
|
402
|
+
return {
|
|
403
|
+
code: transformedCode,
|
|
404
|
+
map: result.map,
|
|
405
|
+
stylexRules: result.stylexRules
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// src/core/transformers/index.ts
|
|
410
|
+
var transformers = {
|
|
411
|
+
astro,
|
|
412
|
+
svelte,
|
|
413
|
+
default: defaultTransformer
|
|
414
|
+
};
|
|
333
415
|
|
|
334
416
|
// src/index.ts
|
|
335
417
|
var unpluginFactory = (rawOptions, meta) => {
|
|
336
418
|
const options = getOptions({ ...rawOptions || {}, framework: meta.framework });
|
|
337
|
-
|
|
419
|
+
if (!stylexRulesStore.has(STORE_KEY)) {
|
|
420
|
+
stylexRulesStore.set(STORE_KEY, {});
|
|
421
|
+
}
|
|
422
|
+
const stylexRules = stylexRulesStore.get(STORE_KEY);
|
|
338
423
|
let viteConfig = null;
|
|
339
424
|
return {
|
|
340
425
|
name: PLUGIN_NAME,
|
|
@@ -350,6 +435,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
350
435
|
const dir = path2.dirname(id);
|
|
351
436
|
const basename2 = path2.basename(id);
|
|
352
437
|
const file = path2.join(dir, basename2.includes("?") ? basename2.split("?")[0] : basename2);
|
|
438
|
+
const extname2 = path2.extname(file).slice(1);
|
|
353
439
|
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
354
440
|
return;
|
|
355
441
|
}
|
|
@@ -360,6 +446,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
360
446
|
options
|
|
361
447
|
};
|
|
362
448
|
try {
|
|
449
|
+
const transformer = transformers[extname2] ?? transformers.default;
|
|
363
450
|
const result = await transformer(context);
|
|
364
451
|
if ((_a = result.stylexRules) == null ? void 0 : _a[id]) {
|
|
365
452
|
stylexRules[id] = result.stylexRules[id];
|
|
@@ -387,9 +474,28 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
387
474
|
base: config.base
|
|
388
475
|
};
|
|
389
476
|
},
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
477
|
+
configureServer(server) {
|
|
478
|
+
server.middlewares.use((req, res, next) => {
|
|
479
|
+
var _a;
|
|
480
|
+
if (!req.url) {
|
|
481
|
+
next();
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const fileName = `${((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
|
|
485
|
+
const cssPath = path2.posix.join((viteConfig == null ? void 0 : viteConfig.base) ?? "/", fileName.replace(/\\/g, "/")).replace(/\/+/g, "/");
|
|
486
|
+
const basePath = ((viteConfig == null ? void 0 : viteConfig.base) ?? "/").replace(/\/+$/, "") || "/";
|
|
487
|
+
const filename = options.stylex.filename;
|
|
488
|
+
const normalizedUrl = req.url.split("?")[0];
|
|
489
|
+
const isCSSRequest = normalizedUrl === cssPath || normalizedUrl === `${basePath}/${filename}` || normalizedUrl === `/${filename}` || normalizedUrl.endsWith(`/${filename}`) || normalizedUrl === filename;
|
|
490
|
+
if (isCSSRequest) {
|
|
491
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
|
|
492
|
+
res.setHeader("Content-Type", "text/css");
|
|
493
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
494
|
+
res.end(collectedCSS || "");
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
next();
|
|
498
|
+
});
|
|
393
499
|
},
|
|
394
500
|
buildEnd() {
|
|
395
501
|
var _a;
|
|
@@ -428,6 +534,11 @@ var unplugin = createUnplugin(unpluginFactory);
|
|
|
428
534
|
var index_default = unplugin;
|
|
429
535
|
|
|
430
536
|
export {
|
|
537
|
+
buildStylexRules,
|
|
538
|
+
PLUGIN_NAME,
|
|
539
|
+
STORE_KEY,
|
|
540
|
+
stylexRulesStore,
|
|
541
|
+
getOptions,
|
|
431
542
|
unpluginFactory,
|
|
432
543
|
unplugin,
|
|
433
544
|
index_default
|