Skip to content

Commit

Permalink
feat: add vite example
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Dec 6, 2023
1 parent 4528a35 commit 31983cc
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 2 deletions.
17 changes: 17 additions & 0 deletions apps/vite-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vite-example",
"version": "0.0.0",
"description": "A simple rollup example to test stylexjs/vite-plugin",
"main": "index.js",
"scripts": {
"build": "vite build"
},
"license": "MIT",
"dependencies": {
"@stylexjs/stylex": "0.3.0"
},
"devDependencies": {
"vite": "^5.0.6",
"@stylexjs/vite-plugin": "0.0.0"
}
}
40 changes: 40 additions & 0 deletions apps/vite-example/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use strict';

import * as stylex from '@stylexjs/stylex';
import otherStyles from './npmStyles.js';
import npmStyles from './npmStyles';

const fadeAnimation = stylex.keyframes({
'0%': {
opacity: 0.25,
},
'100%': {
opacity: 1,
},
});

const styles = stylex.create({
foo: {
animationName: fadeAnimation,
display: 'flex',
marginStart: 10,
marginBlockStart: 99,
height: 500,
':hover': {
background: 'red',
},
},
});

export default function App() {
return stylex.props(otherStyles.bar, styles.foo, npmStyles.baz).className;
}
21 changes: 21 additions & 0 deletions apps/vite-example/src/npmStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use strict';

import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
bar: {
display: 'block',
width: '100%',
},
});

export default styles;
21 changes: 21 additions & 0 deletions apps/vite-example/src/otherStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use strict';

import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
bar: {
display: 'block',
width: '100%',
},
});

export default styles;
22 changes: 22 additions & 0 deletions apps/vite-example/vite.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
import { defineConfig } from 'vite'
import stylexPlugin from '@stylexjs/vite-plugin'
import path from 'path'

export default defineConfig({
plugins: [stylexPlugin()],
build: {
lib: {
entry: path.join(__dirname, 'src/index.js'),
formats: ['es']
},
outDir: path.join(__dirname, '.build')
}
})
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/vite-plugin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = function stylexPlugin({
let cssPostPlugin;
let baseDir = '/';
return {
enforce: 'post',
name: 'vite-plugin-stylex',
buildStart() {
stylexRules = {};
Expand All @@ -51,7 +50,6 @@ module.exports = function stylexPlugin({
},
async transform(inputCode, id) {
if (!stylexImports.some((importName) => inputCode.includes(importName))) {
// In rollup, returning null from any plugin phase means "no changes made".
return null;
}
const { code, map, metadata } = await babel.transformAsync(inputCode, {
Expand Down

0 comments on commit 31983cc

Please sign in to comment.