unplugin-stylex 0.3.0 → 0.3.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/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/types.d.cts +5 -3
- package/dist/types.d.ts +5 -3
- package/jsr.json +1 -1
- package/package.json +7 -7
- package/.eslintignore +0 -4
- package/.eslintrc.json +0 -14
- package/.github/actions/setup-and-cache/action.yml +0 -18
- package/.github/renovate.json +0 -27
- package/.github/workflows/ci.yml +0 -43
- package/.github/workflows/release.yml +0 -39
- package/.github/workflows/typos.yml +0 -15
- package/src/core/build.ts +0 -9
- package/src/core/constants.ts +0 -7
- package/src/core/options.ts +0 -26
- package/src/core/plugins.ts +0 -12
- package/src/core/transformer.ts +0 -44
- package/src/esbuild.ts +0 -29
- package/src/index.ts +0 -141
- package/src/rollup.ts +0 -27
- package/src/rspack.ts +0 -29
- package/src/types.ts +0 -28
- package/src/vite.ts +0 -28
- package/src/webpack.ts +0 -27
- package/typos.toml +0 -10
- package/vitest.config.ts +0 -13
package/dist/rspack.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ import { UnpluginStylexInstance } from './types.cjs';
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance
|
|
10
|
+
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance>;
|
|
11
11
|
declare const rspackPlugin: RspackPluginType;
|
|
12
12
|
|
|
13
13
|
export { rspackPlugin as default };
|
package/dist/rspack.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { UnpluginStylexInstance } from './types.js';
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance
|
|
10
|
+
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance>;
|
|
11
11
|
declare const rspackPlugin: RspackPluginType;
|
|
12
12
|
|
|
13
13
|
export { rspackPlugin as default };
|
package/dist/types.d.cts
CHANGED
|
@@ -5,16 +5,18 @@ type BabelConfig = {
|
|
|
5
5
|
};
|
|
6
6
|
type StylexOptions = {
|
|
7
7
|
filename?: string;
|
|
8
|
+
aliases?: string[];
|
|
8
9
|
stylexImports?: string[];
|
|
9
10
|
classNamePrefix?: string;
|
|
10
|
-
useCSSLayers?: boolean;
|
|
11
11
|
unstable_moduleResolution?: {
|
|
12
12
|
type: 'commonjs' | 'haste';
|
|
13
13
|
rootDir: string;
|
|
14
14
|
};
|
|
15
15
|
babelConfig?: BabelConfig;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
useCSSLayers?: boolean;
|
|
17
|
+
genConditionalClasses?: boolean;
|
|
18
|
+
treeshakeCompensation?: boolean;
|
|
19
|
+
runtimeInjection?: boolean;
|
|
18
20
|
};
|
|
19
21
|
type UnpluginStylexOptions = {
|
|
20
22
|
compiler?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -5,16 +5,18 @@ type BabelConfig = {
|
|
|
5
5
|
};
|
|
6
6
|
type StylexOptions = {
|
|
7
7
|
filename?: string;
|
|
8
|
+
aliases?: string[];
|
|
8
9
|
stylexImports?: string[];
|
|
9
10
|
classNamePrefix?: string;
|
|
10
|
-
useCSSLayers?: boolean;
|
|
11
11
|
unstable_moduleResolution?: {
|
|
12
12
|
type: 'commonjs' | 'haste';
|
|
13
13
|
rootDir: string;
|
|
14
14
|
};
|
|
15
15
|
babelConfig?: BabelConfig;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
useCSSLayers?: boolean;
|
|
17
|
+
genConditionalClasses?: boolean;
|
|
18
|
+
treeshakeCompensation?: boolean;
|
|
19
|
+
runtimeInjection?: boolean;
|
|
18
20
|
};
|
|
19
21
|
type UnpluginStylexOptions = {
|
|
20
22
|
compiler?: string;
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-stylex",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"packageManager": "pnpm@8.11.0",
|
|
5
5
|
"description": "Unplugin for stylex",
|
|
6
6
|
"repository": "https://github.com/eryue0220/unplugin-stylex",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@stylexjs/stylex": "^0.5.1"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@babel/core": "^7.24.
|
|
77
|
+
"@babel/core": "^7.24.5",
|
|
78
78
|
"@babel/plugin-syntax-flow": "^7.24.1",
|
|
79
79
|
"@babel/plugin-syntax-jsx": "^7.24.1",
|
|
80
80
|
"@babel/plugin-syntax-typescript": "^7.24.1",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"unplugin": "^1.10.1"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@stylistic/eslint-plugin-ts": "^1.
|
|
87
|
-
"@types/node": "^20.12.
|
|
86
|
+
"@stylistic/eslint-plugin-ts": "^1.8.1",
|
|
87
|
+
"@types/node": "^20.12.11",
|
|
88
88
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
89
89
|
"@typescript-eslint/parser": "^6.21.0",
|
|
90
|
-
"@vitest/coverage-v8": "^1.
|
|
90
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
91
91
|
"babel-plugin-syntax-hermes-parser": "^0.19.2",
|
|
92
92
|
"eslint": "^8.57.0",
|
|
93
93
|
"tsup": "^8.0.2",
|
|
94
94
|
"typescript": "^5.4.5",
|
|
95
|
-
"vite": "^5.2.
|
|
96
|
-
"vitest": "^1.
|
|
95
|
+
"vite": "^5.2.11",
|
|
96
|
+
"vitest": "^1.6.0"
|
|
97
97
|
}
|
|
98
98
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true
|
|
4
|
-
},
|
|
5
|
-
"parser": "@typescript-eslint/parser",
|
|
6
|
-
"plugins": ["@stylistic/ts"],
|
|
7
|
-
"root": true,
|
|
8
|
-
"rules": {
|
|
9
|
-
"max-len": ["error", { "code": 120 }],
|
|
10
|
-
"semi": ["error", "never"],
|
|
11
|
-
"quotes": ["error", "single"],
|
|
12
|
-
"@typescript-eslint/no-explicit-any": "off"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
name: Setup and Cache
|
|
2
|
-
description: Setup for node, pnpm and cache for browser testing binaries
|
|
3
|
-
inputs:
|
|
4
|
-
node-version:
|
|
5
|
-
required: false
|
|
6
|
-
description: Node version for setup-node
|
|
7
|
-
default: 20.x
|
|
8
|
-
|
|
9
|
-
runs:
|
|
10
|
-
using: composite
|
|
11
|
-
|
|
12
|
-
steps:
|
|
13
|
-
- name: install pnpm
|
|
14
|
-
uses: pnpm/action-setup@v2
|
|
15
|
-
- name: Set node version to ${{ inputs.node-version }}
|
|
16
|
-
uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: ${{ inputs.node-version }}
|
package/.github/renovate.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
-
"extends": ["config:base"],
|
|
4
|
-
"lockFileMaintenance": {"enabled": true, "automerge": false},
|
|
5
|
-
"rangeStrategy": "replace",
|
|
6
|
-
"postUpdateOptions": ["pnpmDedupe"],
|
|
7
|
-
"packageRules": [
|
|
8
|
-
{
|
|
9
|
-
"matchPackageNames": ["@tsd/typescript", "typescript"],
|
|
10
|
-
"groupName": "typescript"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"matchPackageNames": [
|
|
14
|
-
"@babel/core",
|
|
15
|
-
"@babel/plugin-syntax-flow",
|
|
16
|
-
"@babel/plugin-syntax-jsx",
|
|
17
|
-
"@babel/plugin-syntax-typescript"
|
|
18
|
-
],
|
|
19
|
-
"groupName": "babel"
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
"matchPackageNames": ["@stylexjs/stylex", "@stylexjs/babel-plugin"],
|
|
24
|
-
"groupName": "stylex"
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
}
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
|
|
7
|
-
pull_request:
|
|
8
|
-
branches: [main]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
lint:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v4
|
|
15
|
-
|
|
16
|
-
- uses: ./.github/actions/setup-and-cache
|
|
17
|
-
|
|
18
|
-
- name: Install
|
|
19
|
-
run: pnpm i
|
|
20
|
-
|
|
21
|
-
- name: Lint
|
|
22
|
-
run: pnpm run check
|
|
23
|
-
|
|
24
|
-
test:
|
|
25
|
-
runs-on: ${{ matrix.os }}
|
|
26
|
-
|
|
27
|
-
strategy:
|
|
28
|
-
matrix:
|
|
29
|
-
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
30
|
-
node: [16, 18, 20]
|
|
31
|
-
|
|
32
|
-
steps:
|
|
33
|
-
- uses: actions/checkout@v4
|
|
34
|
-
|
|
35
|
-
- uses: ./.github/actions/setup-and-cache
|
|
36
|
-
with:
|
|
37
|
-
node-version: ${{ matrix.node }}
|
|
38
|
-
|
|
39
|
-
- name: Install
|
|
40
|
-
run: pnpm i
|
|
41
|
-
|
|
42
|
-
- name: Unit Test
|
|
43
|
-
run: pnpm run test
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
permissions:
|
|
4
|
-
contents: write
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
tags:
|
|
9
|
-
- 'v*'
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
release:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v4
|
|
16
|
-
with:
|
|
17
|
-
fetch-depth: 0
|
|
18
|
-
|
|
19
|
-
- name: Set node
|
|
20
|
-
uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: lts/*
|
|
23
|
-
|
|
24
|
-
- run: npx changelogithub
|
|
25
|
-
env:
|
|
26
|
-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
27
|
-
|
|
28
|
-
publish-jsr:
|
|
29
|
-
runs-on: ubuntu-latest
|
|
30
|
-
|
|
31
|
-
permissions:
|
|
32
|
-
contents: read
|
|
33
|
-
id-token: write
|
|
34
|
-
|
|
35
|
-
steps:
|
|
36
|
-
- uses: actions/checkout@v4
|
|
37
|
-
|
|
38
|
-
- name: Publish package
|
|
39
|
-
run: npx jsr publish
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
name: Spell Check
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- "main"
|
|
7
|
-
jobs:
|
|
8
|
-
typos:
|
|
9
|
-
name: Spell Check with Typos
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- name: Checkout Actions Repository
|
|
13
|
-
uses: actions/checkout@v4
|
|
14
|
-
- name: Check spelling
|
|
15
|
-
uses: crate-ci/typos@master
|
package/src/core/build.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
package/src/core/constants.ts
DELETED
package/src/core/options.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { StylexOptions, UnpluginStylexOptions } from '@/types'
|
|
2
|
-
import { isDevelopment } from './constants'
|
|
3
|
-
|
|
4
|
-
export function getOptions(options: UnpluginStylexOptions) {
|
|
5
|
-
const stylex = options.stylex || ({} as StylexOptions)
|
|
6
|
-
const isDev = options.dev || isDevelopment
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
dev: options.dev || isDev,
|
|
11
|
-
stylex: {
|
|
12
|
-
filename: stylex.filename || 'stylex.css',
|
|
13
|
-
stylexImports: stylex.stylexImports || ['@stylexjs/stylex'],
|
|
14
|
-
runtimeInjection: stylex.runtimeInjection ?? isDev,
|
|
15
|
-
aliases: stylex.aliases,
|
|
16
|
-
useCSSLayers: stylex.useCSSLayers || false,
|
|
17
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: 'commonJS', rootDir: process.cwd() },
|
|
18
|
-
babelConfig: {
|
|
19
|
-
babelrc: (stylex.babelConfig || {}).babelrc || false,
|
|
20
|
-
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
21
|
-
presets: (stylex.babelConfig || {}).presets || [],
|
|
22
|
-
},
|
|
23
|
-
...stylex,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/core/plugins.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { extname as pathExtname } from 'node:path'
|
|
2
|
-
import { transformAsync } from '@babel/core'
|
|
3
|
-
import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx'
|
|
4
|
-
import stylexBabelPlugin from '@stylexjs/babel-plugin'
|
|
5
|
-
|
|
6
|
-
import { getSyntaxPlugins } from './plugins'
|
|
7
|
-
|
|
8
|
-
export async function transformer(context) {
|
|
9
|
-
const { id, inputCode, options } = context
|
|
10
|
-
const stylex = options.stylex
|
|
11
|
-
const extname = pathExtname(id)
|
|
12
|
-
const stylexRules = {}
|
|
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,
|
|
32
|
-
}
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
36
|
-
stylexRules[id] = metadata.stylex
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!stylex.babelConfig?.babelrc) {
|
|
40
|
-
return { code, map, stylexRules }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return { code, stylexRules }
|
|
44
|
-
}
|
package/src/esbuild.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createEsbuildPlugin } from 'unplugin'
|
|
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
|
-
|
|
14
|
-
|
|
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
|
package/src/index.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for main unplugin.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as path from 'node:path'
|
|
8
|
-
|
|
9
|
-
import { createUnplugin } from 'unplugin'
|
|
10
|
-
import type { UnpluginFactory, UnpluginInstance } from 'unplugin'
|
|
11
|
-
import type { BuildOptions } from 'vite'
|
|
12
|
-
|
|
13
|
-
import { buildStylexRules } from './core/build'
|
|
14
|
-
import { PLUGIN_NAME } from './core/constants'
|
|
15
|
-
import { getOptions } from './core/options'
|
|
16
|
-
import { transformer } from './core/transformer'
|
|
17
|
-
import type { UnpluginStylexOptions } from './types'
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The main unplugin factory.
|
|
21
|
-
*/
|
|
22
|
-
export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined> = (rawOptions = {}) => {
|
|
23
|
-
const options = getOptions(rawOptions)
|
|
24
|
-
const stylexRules = {}
|
|
25
|
-
let viteConfig: { build: BuildOptions | undefined; base: string | undefined; } | null = null
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
name: PLUGIN_NAME,
|
|
29
|
-
|
|
30
|
-
transformInclude(id) {
|
|
31
|
-
// webpack will contain these files, which will occur errors
|
|
32
|
-
const invalidExts = ['.json', '.html', '.jade', '.json5']
|
|
33
|
-
const extname = path.extname(id)
|
|
34
|
-
// for handle vite
|
|
35
|
-
const questionMarkIndex = extname.indexOf('?')
|
|
36
|
-
const validExtName = questionMarkIndex > -1 ? extname.slice(0, questionMarkIndex) : extname
|
|
37
|
-
return !invalidExts.includes(validExtName)
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
async transform(code, id) {
|
|
41
|
-
const dir = path.dirname(id)
|
|
42
|
-
const basename = path.basename(id)
|
|
43
|
-
const file = path.join(dir, basename.includes('?') ? basename.split('?')[0] : basename)
|
|
44
|
-
|
|
45
|
-
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const context = {
|
|
50
|
-
id: file,
|
|
51
|
-
inputCode: code,
|
|
52
|
-
pluginContext: this,
|
|
53
|
-
options,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const result = await transformer(context)
|
|
58
|
-
|
|
59
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
60
|
-
stylexRules[id] = result.stylexRules[id]
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return result
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error('transform::error::', error)
|
|
66
|
-
this.error(error)
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
buildEnd() {
|
|
71
|
-
const fileName = options.stylex.filename
|
|
72
|
-
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
73
|
-
|
|
74
|
-
if (!collectedCSS) return
|
|
75
|
-
|
|
76
|
-
this.emitFile({
|
|
77
|
-
fileName,
|
|
78
|
-
source: collectedCSS,
|
|
79
|
-
type: 'asset',
|
|
80
|
-
})
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
vite: {
|
|
84
|
-
config(config) {
|
|
85
|
-
viteConfig = {
|
|
86
|
-
build: config.build,
|
|
87
|
-
base: config.base,
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
configResolved(config) {
|
|
92
|
-
config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
|
|
93
|
-
config.optimizeDeps.exclude.push('@stylexjs/open-props')
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
buildEnd() {
|
|
97
|
-
const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
98
|
-
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
99
|
-
|
|
100
|
-
if (!collectedCSS) return
|
|
101
|
-
|
|
102
|
-
this.emitFile({
|
|
103
|
-
fileName,
|
|
104
|
-
source: collectedCSS,
|
|
105
|
-
type: 'asset',
|
|
106
|
-
})
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
transformIndexHtml(html, ctx) {
|
|
110
|
-
const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
111
|
-
const css = ctx.bundle?.[fileName]
|
|
112
|
-
|
|
113
|
-
if (!css) {
|
|
114
|
-
return html
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const publicPath = path.posix.join(
|
|
118
|
-
viteConfig!.base ?? '/',
|
|
119
|
-
fileName.replace(/\\/g, '/')
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
return [
|
|
123
|
-
{
|
|
124
|
-
tag: 'link',
|
|
125
|
-
attrs: {
|
|
126
|
-
rel: 'stylesheet',
|
|
127
|
-
href: publicPath,
|
|
128
|
-
},
|
|
129
|
-
injectTo: 'head',
|
|
130
|
-
},
|
|
131
|
-
]
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export const unplugin: UnpluginInstance<UnpluginStylexOptions | undefined, boolean> = createUnplugin(unpluginFactory)
|
|
138
|
-
|
|
139
|
-
export * from './types'
|
|
140
|
-
|
|
141
|
-
export default unplugin
|
package/src/rollup.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for Rollup plugin.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createRollupPlugin } from 'unplugin'
|
|
8
|
-
import type { RollupPlugin } from 'unplugin'
|
|
9
|
-
import { unpluginFactory } from './index'
|
|
10
|
-
import type { UnpluginStylexInstance } from './types'
|
|
11
|
-
|
|
12
|
-
const rollupPlugin: UnpluginStylexInstance<RollupPlugin | RollupPlugin[]> = createRollupPlugin(unpluginFactory)
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Rollup plugin
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* import stylexPlugin from 'unplugin-stylex/rollup'
|
|
20
|
-
*
|
|
21
|
-
* export default {
|
|
22
|
-
* plugins: [
|
|
23
|
-
* stylexPlugin(),
|
|
24
|
-
* ],
|
|
25
|
-
* }
|
|
26
|
-
*/
|
|
27
|
-
export default rollupPlugin
|
package/src/rspack.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for Rspac plugin.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createRspackPlugin } from 'unplugin'
|
|
8
|
-
import type { RspackPluginInstance } from 'unplugin'
|
|
9
|
-
import { unpluginFactory } from './index'
|
|
10
|
-
import type { UnpluginStylexInstance } from './types'
|
|
11
|
-
|
|
12
|
-
type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>
|
|
13
|
-
|
|
14
|
-
const rspackPlugin: RspackPluginType = createRspackPlugin(unpluginFactory)
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Rsapck plugin
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
*
|
|
21
|
-
* import stylexPlugin from 'unplugin-stylex/rspack'
|
|
22
|
-
*
|
|
23
|
-
* module.exports = {
|
|
24
|
-
* plugins: [
|
|
25
|
-
* stylexPlugin(),
|
|
26
|
-
* ],
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
|
-
export default rspackPlugin
|
package/src/types.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export type BabelConfig = {
|
|
2
|
-
plugins: unknown[]
|
|
3
|
-
presets: unknown[]
|
|
4
|
-
babelrc: boolean
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export type StylexOptions = {
|
|
8
|
-
filename?: string
|
|
9
|
-
stylexImports?: string[]
|
|
10
|
-
classNamePrefix?: string
|
|
11
|
-
useCSSLayers?: boolean
|
|
12
|
-
unstable_moduleResolution?: {
|
|
13
|
-
type: 'commonjs' | 'haste'
|
|
14
|
-
rootDir: string
|
|
15
|
-
}
|
|
16
|
-
babelConfig?: BabelConfig
|
|
17
|
-
runtimeInjection: boolean
|
|
18
|
-
aliases?: string[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type UnpluginStylexOptions = {
|
|
22
|
-
compiler?: string
|
|
23
|
-
dev?: boolean
|
|
24
|
-
enforce?: 'post' | 'pre'
|
|
25
|
-
stylex?: StylexOptions
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T
|
package/src/vite.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for Vite plugin.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createVitePlugin } from 'unplugin'
|
|
8
|
-
import type { VitePlugin } from 'unplugin'
|
|
9
|
-
import { unpluginFactory } from './index'
|
|
10
|
-
import type { UnpluginStylexInstance } from './types'
|
|
11
|
-
|
|
12
|
-
const vitePlugin: UnpluginStylexInstance<VitePlugin | VitePlugin[]> = createVitePlugin(unpluginFactory)
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Vite example
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* import { defineConfig } from 'vite'
|
|
20
|
-
* import stylexPlugin from 'unplugin-stylex/vite'
|
|
21
|
-
*
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* plugins: [
|
|
24
|
-
* stylexPlugin(),
|
|
25
|
-
* ],
|
|
26
|
-
* })
|
|
27
|
-
*/
|
|
28
|
-
export default vitePlugin
|
package/src/webpack.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This entry file is for Webpack plugin.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createWebpackPlugin } from 'unplugin'
|
|
8
|
-
import type { WebpackPluginInstance } from 'unplugin'
|
|
9
|
-
import { unpluginFactory } from './index'
|
|
10
|
-
import type { UnpluginStylexInstance } from './types'
|
|
11
|
-
|
|
12
|
-
const webpackPlugin: UnpluginStylexInstance<WebpackPluginInstance> = createWebpackPlugin(unpluginFactory)
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Webpack plugin
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* import stylexPlugin from 'unplugin-stylex/webpack'
|
|
20
|
-
*
|
|
21
|
-
* module.exports = {
|
|
22
|
-
* plugins: [
|
|
23
|
-
* stylexPlugin(),
|
|
24
|
-
* ],
|
|
25
|
-
* }
|
|
26
|
-
*/
|
|
27
|
-
export default webpackPlugin
|
package/typos.toml
DELETED