unplugin-stylex 0.0.2 → 0.2.4
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/.eslintrc.json +4 -6
- package/.github/renovate.json +27 -0
- package/.github/workflows/release.yml +13 -0
- package/.github/workflows/typos.yml +15 -0
- package/README.md +9 -7
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7MXMBS5H.js +190 -0
- package/dist/chunk-NVMQARFA.cjs +190 -0
- package/dist/chunk-ZBPRDZS4.cjs +1 -0
- package/dist/esbuild.cjs +4 -2
- package/dist/esbuild.d.cts +10 -5
- package/dist/esbuild.d.ts +10 -5
- package/dist/esbuild.js +4 -2
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.cts +12 -1
- package/dist/rollup.d.ts +12 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +4 -2
- package/dist/rspack.d.cts +11 -5
- package/dist/rspack.d.ts +11 -5
- package/dist/rspack.js +4 -2
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +7 -7
- package/dist/types.d.ts +7 -7
- package/dist/types.js +1 -0
- package/dist/vite.cjs +4 -2
- package/dist/vite.d.cts +10 -5
- package/dist/vite.d.ts +10 -5
- package/dist/vite.js +4 -2
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.d.cts +12 -1
- package/dist/webpack.d.ts +12 -1
- package/dist/webpack.js +1 -1
- package/jsr.json +20 -0
- package/package.json +8 -3
- package/src/core/build.ts +9 -0
- package/src/core/{utils.ts → options.ts} +9 -9
- package/src/core/plugins.ts +12 -0
- package/src/core/transformer.ts +31 -48
- package/src/esbuild.ts +27 -2
- package/src/index.ts +64 -24
- package/src/rollup.ts +12 -2
- package/src/rspack.ts +27 -2
- package/src/types.ts +8 -7
- package/src/vite.ts +26 -2
- package/src/webpack.ts +12 -2
- package/typos.toml +10 -0
- package/vitest.config.ts +2 -2
- package/dist/chunk-D3OQCQYP.cjs +0 -152
- package/dist/chunk-XQ5JPTTJ.js +0 -152
package/dist/rollup.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
// src/rollup.ts
|
|
6
6
|
var rollup_default = (options) => {
|
|
7
7
|
if (isDevelopment || (options == null ? void 0 : options.dev)) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error('If you want to use this plugin through rollup, please use "@stylexjs/rollup-plugin" instead');
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
export {
|
package/dist/rspack.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
4
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
4
5
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
5
6
|
|
|
6
7
|
// src/rspack.ts
|
|
7
8
|
var _unplugin = require('unplugin');
|
|
8
|
-
var
|
|
9
|
+
var rspackPlugin = _unplugin.createRspackPlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
10
|
+
var rspack_default = rspackPlugin;
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
exports.default = rspack_default;
|
package/dist/rspack.d.cts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { RspackPluginInstance } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.cjs';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for Rspac plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>;
|
|
11
|
+
declare const rspackPlugin: RspackPluginType;
|
|
12
|
+
|
|
13
|
+
export { rspackPlugin as default };
|
package/dist/rspack.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { RspackPluginInstance } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.js';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for Rspac plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>;
|
|
11
|
+
declare const rspackPlugin: RspackPluginType;
|
|
12
|
+
|
|
13
|
+
export { rspackPlugin as default };
|
package/dist/rspack.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unpluginFactory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7MXMBS5H.js";
|
|
4
|
+
import "./chunk-6F4PWJZI.js";
|
|
4
5
|
import "./chunk-36ARBXVP.js";
|
|
5
6
|
|
|
6
7
|
// src/rspack.ts
|
|
7
8
|
import { createRspackPlugin } from "unplugin";
|
|
8
|
-
var
|
|
9
|
+
var rspackPlugin = createRspackPlugin(unpluginFactory);
|
|
10
|
+
var rspack_default = rspackPlugin;
|
|
9
11
|
export {
|
|
10
12
|
rspack_default as default
|
|
11
13
|
};
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";require('./chunk-ZBPRDZS4.cjs');
|
package/dist/types.d.cts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
-
|
|
3
1
|
type BabelConfig = {
|
|
4
2
|
plugins: unknown[];
|
|
5
3
|
presets: unknown[];
|
|
@@ -11,17 +9,19 @@ type StylexOptions = {
|
|
|
11
9
|
classNamePrefix?: string;
|
|
12
10
|
useCSSLayers?: boolean;
|
|
13
11
|
unstable_moduleResolution?: {
|
|
14
|
-
type:
|
|
12
|
+
type: 'commonjs' | 'haste';
|
|
15
13
|
rootDir: string;
|
|
16
14
|
};
|
|
17
15
|
babelConfig?: BabelConfig;
|
|
16
|
+
runtimeInjection: boolean;
|
|
17
|
+
aliases?: string[];
|
|
18
18
|
};
|
|
19
19
|
type UnpluginStylexOptions = {
|
|
20
|
+
compiler?: string;
|
|
20
21
|
dev?: boolean;
|
|
21
|
-
|
|
22
|
-
exclude?: FilterPattern;
|
|
23
|
-
enforce?: "post" | "pre";
|
|
22
|
+
enforce?: 'post' | 'pre';
|
|
24
23
|
stylex?: StylexOptions;
|
|
25
24
|
};
|
|
25
|
+
type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T;
|
|
26
26
|
|
|
27
|
-
export type { BabelConfig, UnpluginStylexOptions };
|
|
27
|
+
export type { BabelConfig, StylexOptions, UnpluginStylexInstance, UnpluginStylexOptions };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
-
|
|
3
1
|
type BabelConfig = {
|
|
4
2
|
plugins: unknown[];
|
|
5
3
|
presets: unknown[];
|
|
@@ -11,17 +9,19 @@ type StylexOptions = {
|
|
|
11
9
|
classNamePrefix?: string;
|
|
12
10
|
useCSSLayers?: boolean;
|
|
13
11
|
unstable_moduleResolution?: {
|
|
14
|
-
type:
|
|
12
|
+
type: 'commonjs' | 'haste';
|
|
15
13
|
rootDir: string;
|
|
16
14
|
};
|
|
17
15
|
babelConfig?: BabelConfig;
|
|
16
|
+
runtimeInjection: boolean;
|
|
17
|
+
aliases?: string[];
|
|
18
18
|
};
|
|
19
19
|
type UnpluginStylexOptions = {
|
|
20
|
+
compiler?: string;
|
|
20
21
|
dev?: boolean;
|
|
21
|
-
|
|
22
|
-
exclude?: FilterPattern;
|
|
23
|
-
enforce?: "post" | "pre";
|
|
22
|
+
enforce?: 'post' | 'pre';
|
|
24
23
|
stylex?: StylexOptions;
|
|
25
24
|
};
|
|
25
|
+
type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T;
|
|
26
26
|
|
|
27
|
-
export type { BabelConfig, UnpluginStylexOptions };
|
|
27
|
+
export type { BabelConfig, StylexOptions, UnpluginStylexInstance, UnpluginStylexOptions };
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-6F4PWJZI.js";
|
package/dist/vite.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
4
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
4
5
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
5
6
|
|
|
6
7
|
// src/vite.ts
|
|
7
8
|
var _unplugin = require('unplugin');
|
|
8
|
-
var
|
|
9
|
+
var vitePlugin = _unplugin.createVitePlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
10
|
+
var vite_default = vitePlugin;
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
exports.default = vite_default;
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { VitePlugin } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.cjs';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for Vite plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
declare const vitePlugin: UnpluginStylexInstance<VitePlugin | VitePlugin[]>;
|
|
11
|
+
|
|
12
|
+
export { vitePlugin as default };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { VitePlugin } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.js';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for Vite plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
declare const vitePlugin: UnpluginStylexInstance<VitePlugin | VitePlugin[]>;
|
|
11
|
+
|
|
12
|
+
export { vitePlugin as default };
|
package/dist/vite.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unpluginFactory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7MXMBS5H.js";
|
|
4
|
+
import "./chunk-6F4PWJZI.js";
|
|
4
5
|
import "./chunk-36ARBXVP.js";
|
|
5
6
|
|
|
6
7
|
// src/vite.ts
|
|
7
8
|
import { createVitePlugin } from "unplugin";
|
|
8
|
-
var
|
|
9
|
+
var vitePlugin = createVitePlugin(unpluginFactory);
|
|
10
|
+
var vite_default = vitePlugin;
|
|
9
11
|
export {
|
|
10
12
|
vite_default as default
|
|
11
13
|
};
|
package/dist/webpack.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var _chunkN4Z3Z2PUcjs = require('./chunk-N4Z3Z2PU.cjs');
|
|
|
5
5
|
// src/webpack.ts
|
|
6
6
|
var webpack_default = (options) => {
|
|
7
7
|
if (_chunkN4Z3Z2PUcjs.isDevelopment || (options == null ? void 0 : options.dev)) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error('If you want to use this plugin through webpack, please use "@stylexjs/webpack-plugin" instead');
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
|
package/dist/webpack.d.cts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { UnpluginStylexOptions } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This entry file is for Webpack plugin.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Note: Current, please use @stylexjs/webpack-plugin
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: (options?: UnpluginStylexOptions) => void;
|
|
2
13
|
|
|
3
14
|
export { _default as default };
|
package/dist/webpack.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { UnpluginStylexOptions } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This entry file is for Webpack plugin.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Note: Current, please use @stylexjs/webpack-plugin
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: (options?: UnpluginStylexOptions) => void;
|
|
2
13
|
|
|
3
14
|
export { _default as default };
|
package/dist/webpack.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
// src/webpack.ts
|
|
6
6
|
var webpack_default = (options) => {
|
|
7
7
|
if (isDevelopment || (options == null ? void 0 : options.dev)) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error('If you want to use this plugin through webpack, please use "@stylexjs/webpack-plugin" instead');
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
export {
|
package/jsr.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eryue0220/unplugin-stylex",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"exports": {
|
|
5
|
+
"./index": "./src/index.ts",
|
|
6
|
+
"./esbuild": "./src/esbuild.ts",
|
|
7
|
+
"./rollup": "./src/rollup.ts",
|
|
8
|
+
"./rspack": "./src/rspack.ts",
|
|
9
|
+
"./vite": "./src/vite.ts",
|
|
10
|
+
"./webpack": "./src/webpack.ts"
|
|
11
|
+
},
|
|
12
|
+
"exclude": [
|
|
13
|
+
".eslintrc.json",
|
|
14
|
+
".eslintignore",
|
|
15
|
+
"test",
|
|
16
|
+
"examples",
|
|
17
|
+
"pnpm-lock.yaml",
|
|
18
|
+
"pnpm-workspace.yaml"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-stylex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"packageManager": "pnpm@8.11.0",
|
|
5
5
|
"description": "Unplugin for stylex",
|
|
6
6
|
"repository": "https://github.com/eryue0220/unplugin-stylex",
|
|
@@ -59,20 +59,25 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=16.14.0"
|
|
61
61
|
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@stylexjs/stylex": "^0.5.1"
|
|
64
|
+
},
|
|
62
65
|
"dependencies": {
|
|
63
66
|
"@babel/core": "^7.23.6",
|
|
64
67
|
"@babel/plugin-syntax-flow": "^7.23.3",
|
|
65
68
|
"@babel/plugin-syntax-jsx": "^7.23.3",
|
|
66
69
|
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
67
70
|
"@rollup/pluginutils": "^5.1.0",
|
|
68
|
-
"@stylexjs/babel-plugin": "^0.
|
|
69
|
-
"unplugin": "^1.
|
|
71
|
+
"@stylexjs/babel-plugin": "^0.5.1",
|
|
72
|
+
"unplugin": "^1.7.1"
|
|
70
73
|
},
|
|
71
74
|
"devDependencies": {
|
|
75
|
+
"@stylistic/eslint-plugin-ts": "^1.6.2",
|
|
72
76
|
"@types/node": "^20.10.5",
|
|
73
77
|
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
|
74
78
|
"@typescript-eslint/parser": "^6.16.0",
|
|
75
79
|
"@vitest/coverage-v8": "^1.1.1",
|
|
80
|
+
"babel-plugin-syntax-hermes-parser": "^0.19.1",
|
|
76
81
|
"eslint": "^8.56.0",
|
|
77
82
|
"tsup": "^8.0.1",
|
|
78
83
|
"typescript": "^5.3.3",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import stylex from '@stylexjs/babel-plugin'
|
|
2
|
+
import type { Rule } from '@stylexjs/babel-plugin'
|
|
3
|
+
|
|
4
|
+
export function buildStylexRules(stylexRules: { [key: string]: Rule[] }, useCSSLayers: boolean): string {
|
|
5
|
+
const rules = Object.values(stylexRules).flat()
|
|
6
|
+
if (rules.length === 0) return ''
|
|
7
|
+
|
|
8
|
+
return stylex.processStylexRules(rules, useCSSLayers)
|
|
9
|
+
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import type { UnpluginStylexOptions } from '@/types'
|
|
1
|
+
import type { StylexOptions, UnpluginStylexOptions } from '@/types'
|
|
2
2
|
import { isDevelopment } from './constants'
|
|
3
3
|
|
|
4
|
-
export function getOptions(options: UnpluginStylexOptions
|
|
5
|
-
const stylex = options.stylex || {}
|
|
4
|
+
export function getOptions(options: UnpluginStylexOptions) {
|
|
5
|
+
const stylex = options.stylex || ({} as StylexOptions)
|
|
6
|
+
const isDev = options.dev || isDevelopment
|
|
6
7
|
|
|
7
8
|
return {
|
|
8
9
|
...options,
|
|
9
|
-
dev: options.dev ||
|
|
10
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
11
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
12
|
-
enforce: options.enforce || 'pre',
|
|
10
|
+
dev: options.dev || isDev,
|
|
13
11
|
stylex: {
|
|
14
|
-
...stylex,
|
|
15
12
|
filename: stylex.filename || 'stylex.css',
|
|
16
|
-
stylexImports: stylex.stylexImports || ['
|
|
13
|
+
stylexImports: stylex.stylexImports || ['@stylexjs/stylex'],
|
|
14
|
+
runtimeInjection: stylex.runtimeInjection ?? isDev,
|
|
15
|
+
aliases: stylex.aliases,
|
|
17
16
|
useCSSLayers: stylex.useCSSLayers || false,
|
|
18
17
|
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: 'commonJS', rootDir: process.cwd() },
|
|
19
18
|
babelConfig: {
|
|
@@ -21,6 +20,7 @@ export function getOptions(options: UnpluginStylexOptions = ({} as UnpluginStyle
|
|
|
21
20
|
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
22
21
|
presets: (stylex.babelConfig || {}).presets || [],
|
|
23
22
|
},
|
|
23
|
+
...stylex,
|
|
24
24
|
},
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript'
|
|
2
|
+
import flowSyntaxPlugin from '@babel/plugin-syntax-flow'
|
|
3
|
+
|
|
4
|
+
export function getSyntaxPlugins(extname: string) {
|
|
5
|
+
const TSPlugin = extname === '.tsx'
|
|
6
|
+
? [[typescriptSyntaxPlugin, { isTSX: true }]]
|
|
7
|
+
: [typescriptSyntaxPlugin]
|
|
8
|
+
|
|
9
|
+
return ['.js', '.jsx'].includes(extname)
|
|
10
|
+
? [flowSyntaxPlugin]
|
|
11
|
+
: TSPlugin
|
|
12
|
+
}
|
package/src/core/transformer.ts
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
|
|
1
|
+
import { extname as pathExtname } from 'node:path'
|
|
4
2
|
import { transformAsync } from '@babel/core'
|
|
5
|
-
import flowSyntaxPlugin from '@babel/plugin-syntax-flow'
|
|
6
3
|
import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx'
|
|
7
|
-
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript'
|
|
8
4
|
import stylexBabelPlugin from '@stylexjs/babel-plugin'
|
|
9
5
|
|
|
6
|
+
import { getSyntaxPlugins } from './plugins'
|
|
7
|
+
|
|
10
8
|
export async function transformer(context) {
|
|
11
|
-
const { id,
|
|
9
|
+
const { id, inputCode, options } = context
|
|
12
10
|
const stylex = options.stylex
|
|
13
|
-
const extname =
|
|
11
|
+
const extname = pathExtname(id)
|
|
14
12
|
const stylexRules = {}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
jsxSyntaxPlugin,
|
|
35
|
-
[
|
|
36
|
-
stylexBabelPlugin,
|
|
37
|
-
{
|
|
38
|
-
dev: options.dev,
|
|
39
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
40
|
-
importSources: stylex.stylexImports,
|
|
41
|
-
...stylex,
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
],
|
|
45
|
-
presets: stylex.babelConfig.presets,
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
50
|
-
stylexRules[id] = metadata.stylex
|
|
13
|
+
const stylexBabelPluginOptions = {
|
|
14
|
+
dev: options.dev,
|
|
15
|
+
importSources: stylex.stylexImports,
|
|
16
|
+
...stylex,
|
|
17
|
+
}
|
|
18
|
+
const plugins = [
|
|
19
|
+
...(stylex.babelConfig?.plugins || []),
|
|
20
|
+
...getSyntaxPlugins(extname),
|
|
21
|
+
jsxSyntaxPlugin,
|
|
22
|
+
stylexBabelPlugin.withOptions(stylexBabelPluginOptions),
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
const { code, map, metadata } = await transformAsync(
|
|
26
|
+
inputCode,
|
|
27
|
+
{
|
|
28
|
+
babelrc: stylex.babelConfig?.babelrc,
|
|
29
|
+
filename: id,
|
|
30
|
+
presets: stylex.babelConfig?.presets,
|
|
31
|
+
plugins,
|
|
51
32
|
}
|
|
33
|
+
)
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
36
|
+
stylexRules[id] = metadata.stylex
|
|
37
|
+
}
|
|
56
38
|
|
|
57
|
-
|
|
39
|
+
if (!stylex.babelConfig?.babelrc) {
|
|
40
|
+
return { code, map, stylexRules }
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
return { code
|
|
43
|
+
return { code, stylexRules }
|
|
61
44
|
}
|
package/src/esbuild.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import { createEsbuildPlugin } from 'unplugin'
|
|
2
|
-
import {
|
|
8
|
+
import type { EsbuildPlugin } from 'unplugin'
|
|
9
|
+
import { unpluginFactory } from './index'
|
|
10
|
+
import type { UnpluginStylexInstance } from './types'
|
|
11
|
+
|
|
12
|
+
const esbuildPlugin: UnpluginStylexInstance<EsbuildPlugin | EsbuildPlugin[]> = createEsbuildPlugin(unpluginFactory)
|
|
13
|
+
|
|
3
14
|
|
|
4
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Esbuild plugin
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* import { build } from 'esbuild'
|
|
21
|
+
* import stylexPlugin from 'unplugin-stylex/esbuild'
|
|
22
|
+
*
|
|
23
|
+
* export default {
|
|
24
|
+
* plugins: [
|
|
25
|
+
* stylexPlugin(),
|
|
26
|
+
* ],
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export default esbuildPlugin
|