Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support farm #32

Merged
merged 15 commits into from
Jul 9, 2024
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ export default {

</br></details>

<details>
<summary>farm</summary><br>

```js
// farm.config.js
import { defineConfig } from '@farmfe/core'
import stylexPlugin from 'unplugin-stylex/farm'

export default defineConfig({
// other rollup config
plugins: [
stylexPlugin({ /* options */}),
],
})
```

</br></details>

<details>
<summary>rspack</summary><br>

Expand Down
33 changes: 33 additions & 0 deletions examples/farm-example/farm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineConfig } from '@farmfe/core'
import stylexFarmPlugin from 'unplugin-stylex/farm'

export default defineConfig({
compilation: {
input: {
index: './index.html'
},
output: {
path: 'dist',
publicPath: '/',
targetEnv: 'browser'
},
},
server: {
hmr: true,
},
plugins: [
['@farmfe/plugin-react', {
refresh: true,
development: true,
runtime: 'automatic',
}],
stylexFarmPlugin({
dev: true,
stylex: {
useCSSLayers: true,
// this must set `true` in farm
treeshakeCompensation: true,
},
}),
],
})
25 changes: 25 additions & 0 deletions examples/farm-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StyleX with Farm</title>
<style>
@layer reset {
body {
box-sizing: border-box;
padding: 0;
margin: 0;
}
}
</style>
</head>

<body>
<div id="root"></div>
<script type="module" src="./src/index.tsx"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions examples/farm-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "farm-example",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "farm start",
"build": "farm build"
},
"dependencies": {
"@stylexjs/open-props": "^0.6.0",
"@stylexjs/stylex": "^0.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@farmfe/cli": "^1.0.0",
"@farmfe/core": "^1.0.22",
"@farmfe/plugin-react": "^1.0.1",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"react-refresh": "^0.14.0",
"unplugin-stylex": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ function App() {
)
}

createRoot(document.getElementById('root')).render(<App />)
createRoot(document.getElementById('root')!).render(<App />)
11 changes: 11 additions & 0 deletions examples/farm-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "Bundler"
},
"include": ["src"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion examples/vite-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

<body>
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions examples/vite-example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createRoot } from 'react-dom/client'
import * as stylex from '@stylexjs/stylex'
import { colors } from '@stylexjs/open-props/lib/colors.stylex'
import { sizes } from '@stylexjs/open-props/lib/sizes.stylex'
import { fonts } from '@stylexjs/open-props/lib/fonts.stylex'

const styles = stylex.create({
main: {
width: '100vw',
height: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: colors.pink7,
},
card: {
backgroundColor: colors.blue9,
padding: sizes.spacing5,
borderRadius: sizes.spacing2,
justifyContent: 'center',
display: 'flex',
alignItems: 'center',
color: colors.gray0,
fontFamily: fonts.mono,
},
})

function App() {
return (
<div {...stylex.props(styles.main)}>
<div {...stylex.props(styles.card)}>
<span>Blue rounded rectangle</span>
</div>
</div>
)
}

createRoot(document.getElementById('root')!).render(<App />)
16 changes: 16 additions & 0 deletions examples/vite-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler",
"useDefineForClassFields": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
3 changes: 2 additions & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@eryue0220/unplugin-stylex",
"version": "0.3.2",
"version": "0.4.0",
"exports": {
"./index": "./src/index.ts",
"./esbuild": "./src/esbuild.ts",
"./farm": "./src/farm.ts",
"./rollup": "./src/rollup.ts",
"./rspack": "./src/rspack.ts",
"./vite": "./src/vite.ts",
Expand Down
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "unplugin-stylex",
"version": "0.3.2",
"version": "0.4.0",
"packageManager": "[email protected]",
"description": "Unplugin for stylex",
"repository": "https://github.com/eryue0220/unplugin-stylex",
"keywords": [
"unplugin",
"stylex",
"stylex-plugin",
"farm",
"esbuild",
"rollup",
"rspack",
Expand All @@ -30,6 +31,11 @@
"require": "./dist/esbuild.cjs",
"import": "./dist/esbuild.js"
},
"./farm": {
"types": "./dist/farm.d.ts",
"require": "./dist/farm.cjs",
"import": "./dist/farm.js"
},
"./rollup": {
"types": "./dist/rollup.d.ts",
"require": "./dist/rollup.cjs",
Expand Down Expand Up @@ -74,25 +80,25 @@
"@stylexjs/stylex": "^0.5.1"
},
"dependencies": {
"@babel/core": "^7.24.5",
"@babel/plugin-syntax-flow": "^7.24.1",
"@babel/plugin-syntax-jsx": "^7.24.1",
"@babel/plugin-syntax-typescript": "^7.24.1",
"@babel/core": "^7.24.7",
"@babel/plugin-syntax-flow": "^7.24.7",
"@babel/plugin-syntax-jsx": "^7.24.7",
"@babel/plugin-syntax-typescript": "^7.24.7",
"@rollup/pluginutils": "^5.1.0",
"@stylexjs/babel-plugin": "^0.5.1",
"unplugin": "^1.10.1"
"unplugin": "^1.11.0"
},
"devDependencies": {
"@stylistic/eslint-plugin-ts": "^1.8.1",
"@types/node": "^20.12.11",
"@types/node": "^20.14.10",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitest/coverage-v8": "^1.6.0",
"babel-plugin-syntax-hermes-parser": "^0.19.2",
"eslint": "^8.57.0",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"tsup": "^8.1.0",
"typescript": "^5.5.3",
"vite": "^5.3.3",
"vitest": "^1.6.0"
}
}
Loading
Loading