Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
natew committed Jan 14, 2025
1 parent eebc40e commit a7d20be
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/one-tailwind/app/base.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind utilities;
12 changes: 6 additions & 6 deletions examples/one-tailwind/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Text, View } from 'react-native'
import './base.css'

export default function Index() {
const out = (
<div className="bg-red-500 p-4 border uppercase">this is bg should be red by tailwind</div>
)
// const out = (
// <div className="bg-red-500 p-4 border uppercase">this is bg should be red by tailwind</div>
// )

console.log('what is', typeof out.props.children, typeof out.props.children?.props)

Expand All @@ -19,11 +19,11 @@ export default function Index() {
minHeight: '100%',
}}
>
<Text className="bg-red-500 p-4">Hello world, from One</Text>
{/* <Text className="bg-red-500 p-4">Hello world, from One</Text>
{/* <View style={{ $$css: true, test: 'w-10 h-10 bg-blue-500' }} /> */}
<View style={{ $$css: true, test: 'w-10 h-10 bg-blue-500' }} /> */}

{out}
{/* {out} */}
</View>
)
}
11 changes: 4 additions & 7 deletions examples/one-tailwind/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
"./app/**/*.{js,ts,jsx,tsx}",
],
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}', './app/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [require("tailwindcss-animate"), require("tailwindcss-motion")],
};
resets: [require('nativewind/preset')],
plugins: [require('tailwindcss-animate'), require('tailwindcss-motion')],
}
29 changes: 25 additions & 4 deletions packages/compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { debug, runtimePublicPath, validParsers } from './constants'
import { getBabelOptions, transformBabel } from './transformBabel'
import { transformSWC } from './transformSWC'
import type { Environment, GetTransformProps, Options } from './types'
import { cssToReactNativeRuntime } from 'react-native-css-interop/css-to-rn/index.js'
import { configuration } from './configure'

export * from './configure'
export * from './transformBabel'
Expand Down Expand Up @@ -51,6 +53,23 @@ export async function createVXRNCompilerPlugin(
: undefined,
},

{
name: `one:compiler-css-to-js`,
enforce: 'post',
transform(code, id) {
const environment = getEnvName(this.environment.name)
if (configuration.enableNativeCSS && (environment === 'ios' || environment === 'android')) {
if (extname(id) === '.css') {
const data = JSON.stringify(cssToReactNativeRuntime(code, { inlineRem: 16 }))
return {
code: `require("nativewind").StyleSheet.registerCompiled(${data})`,
map: null,
}
}
}
},
},

{
name: 'one:compiler',
enforce: 'pre',
Expand All @@ -61,6 +80,10 @@ export async function createVXRNCompilerPlugin(
optimizeDeps: {
noDiscovery: true,
},

define: {
'process.env.NATIVEWIND_OS': 'native',
},
} satisfies UserConfig

return {
Expand Down Expand Up @@ -93,10 +116,8 @@ export async function createVXRNCompilerPlugin(
const production = process.env.NODE_ENV === 'production'

if (extension === '.css') {
console.warn('EXTENSION CSS')
if (environment === 'ios' || environment === 'android') {
return null
}
// handled in separate post plugin
return
}

let id = _id.split('?')[0]
Expand Down
5 changes: 2 additions & 3 deletions packages/compiler/src/transformSWC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export async function transformSWC(
return
}

const enableNativeCSS =
configuration.enableNativeCSS &&
(options.environment === 'ios' || options.environment === 'android')
const enableNativeCSS = configuration.enableNativeCSS

// temp fix idk why this error:
// node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx (19:9): "createInteropElement" is not exported by "../../node_modules/react-native-css-interop/dist/runtime/jsx-dev-runtime.js", imported by "node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx
!id.includes('node_modules')
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/types/transformSWC.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { type Output, type Options as SWCOptions } from '@swc/core';
import type { Options } from './types';
export declare function transformSWC(id: string, code: string, options: Options & {
es5?: boolean;
}, swcOptions?: SWCOptions): Promise<Output | undefined>;
}, swcOptions?: SWCOptions): Promise<{
code: string;
} | undefined>;
export declare const transformSWCStripJSX: (id: string, code: string) => Promise<Output | undefined>;
//# sourceMappingURL=transformSWC.d.ts.map
1 change: 1 addition & 0 deletions packages/vxrn/src/utils/getOptimizeDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { webExtensions } from '../constants'

export function getOptimizeDeps(mode: 'build' | 'serve') {
const needsInterop = [
'nativewind/jsx-dev-runtime',
'@vxrn/safe-area',
'@vxrn/vendor/react-19-prod',
'@vxrn/vendor/react-19',
Expand Down

0 comments on commit a7d20be

Please sign in to comment.