diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 08389ea..c6d0f6e 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/eslint.config.js b/eslint.config.js index 694b6c9..5428fba 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,3 +1,3 @@ -module.exports = require('eslint-config-kagura').nonzzz({ ts: true, jsx: true }, { +module.exports = require('eslint-config-kagura').nonzzz({ ts: true, jsx: true, unusedImports: false }, { ignores: ['packages/**/output.js'] }) diff --git a/examples/vite-vue-demo/package.json b/examples/vite-vue-demo/package.json index 10a86a2..2d19fcf 100644 --- a/examples/vite-vue-demo/package.json +++ b/examples/vite-vue-demo/package.json @@ -7,6 +7,7 @@ "preview": "vite preview" }, "devDependencies": { + "@stylex-extend/vite-plugin": "workspace:*", "@stylex-extend/vue": "workspace:*", "@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue-jsx": "^3.1.0", diff --git a/examples/vite-vue-demo/src/colors.stylex.ts b/examples/vite-vue-demo/src/colors.stylex.ts new file mode 100644 index 0000000..1ee7639 --- /dev/null +++ b/examples/vite-vue-demo/src/colors.stylex.ts @@ -0,0 +1,5 @@ +import { defineVars } from '@stylexjs/stylex' + +export const colors = defineVars({ + purple: 'purple' +}) diff --git a/examples/vite-vue-demo/src/main.tsx b/examples/vite-vue-demo/src/main.tsx index c4a1047..795e2ad 100644 --- a/examples/vite-vue-demo/src/main.tsx +++ b/examples/vite-vue-demo/src/main.tsx @@ -1,9 +1,11 @@ import { createApp, defineComponent } from 'vue' import { keyframes } from '@stylexjs/stylex' +import { injectGlobalStyle } from '@stylex-extend/core' +import { colors } from './colors.stylex' const pulse = keyframes({ '0%': { transform: 'scale(1)' }, - '50%': { transform: 'scale(1.1)' }, + '50%': { transform: 'scale(0.5)' }, '100%': { transform: 'scale(1)' } }) @@ -13,13 +15,21 @@ const A = defineComponent(() => { const color = 'purple' +injectGlobalStyle({ + p: { + color: colors.purple + } +}) + const App = defineComponent({ + setup() { return () => ( <>
text
t.isImportDeclaration(p.node)) ctx.setupOptions(pluginOptions, identifiers, anchor === -1 ? 0 : anchor) scanImportStmt(body, ctx) - path.traverse({ - CallExpression(path) { - const CSS = transformInjectGlobalStyle(path, ctx) - Reflect.set(state.file.metadata, 'globalStyle', CSS) - } - }) + if (ctx.options.enableInjectGlobalStyle) { + path.traverse({ + CallExpression(path) { + const CSS = transformInjectGlobalStyle(path, ctx) + Reflect.set(state.file.metadata, 'globalStyle', CSS) + } + }) + } }, exit(path) { const body = path.get('body') @@ -93,3 +95,5 @@ export type StylexExtendTransformObject = { } export default declare as unknown as StylexExtendTransformObject + +export type { StylexExtendBabelPluginOptions } diff --git a/packages/babel-plugin/src/interface.ts b/packages/babel-plugin/src/interface.ts index 68938d7..28a9dd5 100644 --- a/packages/babel-plugin/src/interface.ts +++ b/packages/babel-plugin/src/interface.ts @@ -22,7 +22,7 @@ export interface ModuleResolutionExperimentalCrossFileParsing { export type ModuleResolution = ModuleResolutionCommonJS | MOduleResolutionHaste | ModuleResolutionExperimentalCrossFileParsing export interface StylexExtendBabelPluginOptions { - stylex: boolean | StylexBindingMeta + stylex?: boolean | StylexBindingMeta enableInjectGlobalStyle?: boolean /** * @default 'x' diff --git a/packages/babel-plugin/src/state-context.ts b/packages/babel-plugin/src/state-context.ts index 33fa8a4..c89e5af 100644 --- a/packages/babel-plugin/src/state-context.ts +++ b/packages/babel-plugin/src/state-context.ts @@ -1,4 +1,5 @@ import path from 'path' +import { createRequire } from 'module' import { types } from '@babel/core' import type { StylexBindingMeta, StylexExtendBabelPluginOptions } from './interface' @@ -6,6 +7,8 @@ export type InternalPluginOptions = Required