-
Notifications
You must be signed in to change notification settings - Fork 314
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: add esbuild
plugin
#113
Merged
nmn
merged 40 commits into
facebook:release/v0.5.0
from
nedjulius:nedjulius/add-esbuild-plugin
Jan 7, 2024
Merged
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
7d0268a
Add eslint-plugin package
nedjulius 94b7407
Add initial test suite
nedjulius 14637f0
Improve CSS handling and tests
nedjulius 6fe9c5f
Address some of the comments
nedjulius d3a0f5f
Add babel scripts for jsx, flow and ts
nedjulius cd62e9f
Add package diff
nedjulius 4a287db
Add snapshots and fix nits
nedjulius 7811896
Fix conflicts
nedjulius 17011de
Fix rename bug
nedjulius eb94b3c
Add esbuild example app
nedjulius 90b06c3
Fix incorrect loaders
nedjulius 083de80
Update package-lock.json
nedjulius 891c561
Remove unnecessary file
nedjulius bad0b30
Fix some nits in example
nedjulius 9c1ee21
Add additional style to text fixture
nedjulius 0aa6583
Remove ext from import in example
nedjulius 96324ac
Address some of the comments
nedjulius 52caaf3
Update package-lock.json
nedjulius 35f164d
Add missing function call and snapshot
nedjulius 27dcb73
Remove comment
nedjulius 0fcd813
Pluralize function name
nedjulius 922f158
Merge branch 'main' of github.com:nedjulius/stylex into nedjulius/add…
nedjulius 7a788d0
Add types
nedjulius 99da76c
Fix build script
nedjulius f4ff4da
Add docs
nedjulius 8b9fca8
Fix tabulation
nedjulius e48090a
Retake snapshots
nedjulius a12edd2
Format prettier
nedjulius 3e1692f
Add more missing types
nedjulius 2608220
Run formatter
nedjulius 6b25103
Fix formatting
nedjulius 736c1f2
Lock dependency and fix import
nedjulius 9338cb8
Disable unused key
nedjulius 4ff83a5
Add docs
nedjulius ac9caa0
Merge conflict
nedjulius a07f5bb
Update package-lock.json
nedjulius 91f6eca
Update package-lock.json
nedjulius cd1f8b9
Add snapshots
nedjulius 9615a5b
Address comments
nedjulius 6fa1540
Merge branch 'main' into nedjulius/add-esbuild-plugin
nedjulius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
.*/lib/.* | ||
.*/malformed_package_json/.* | ||
.*/next-example/.* | ||
.*/esbuild-example/.* | ||
|
||
[include] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* 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. | ||
* | ||
* | ||
*/ | ||
|
||
module.exports = { | ||
plugins: ['@stylexjs'], | ||
rules: { | ||
'@stylexjs/valid-styles': 'error', | ||
'ft-flow/space-after-type-colon': 0, | ||
'ft-flow/no-types-missing-file-annotation': 0, | ||
'ft-flow/generic-spacing': 0, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added an example package that provides a simple build script example for a React application. it is also easier to develop the plugin this way. |
||
"name": "esbuild-example", | ||
"version": "0.0.0", | ||
"description": "Simple esbuild example for @stylexjs/esbuild-plugin", | ||
"main": "src/App.jsx", | ||
"scripts": { | ||
"build": "node scripts/build.mjs", | ||
"lint": "eslint \"**/*.{js,jsx}\"" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@stylexjs/stylex": "^0.3.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@stylexjs/esbuild-plugin": "^0.0.0", | ||
nedjulius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@stylexjs/eslint-plugin": "^0.3.0", | ||
"esbuild": "^0.19.9", | ||
"eslint": "^8.55.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>@stylexjs/esbuild-plugin</title> | ||
<meta charset="utf-8" /> | ||
<style> | ||
@layer reset { | ||
body { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} | ||
</style> | ||
<link rel="stylesheet" type="text/css" href="./dist/stylex.css" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="./dist/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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 path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import esbuild from 'esbuild'; | ||
import stylexPlugin from '@stylexjs/esbuild-plugin'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const BUILD_DIR_NAME = 'public/dist'; | ||
const OUTFILE = `${BUILD_DIR_NAME}/bundle.js`; | ||
const STYLEX_BUNDLE_PATH = path.resolve( | ||
__dirname, | ||
'..', | ||
`${BUILD_DIR_NAME}/stylex.css`, | ||
); | ||
|
||
esbuild | ||
.build({ | ||
entryPoints: [path.resolve(__dirname, '..', 'src/App.jsx')], | ||
bundle: true, | ||
outfile: OUTFILE, | ||
minify: true, | ||
plugins: [ | ||
stylexPlugin({ | ||
useCSSLayers: true, | ||
generatedCSSFileName: STYLEX_BUNDLE_PATH, | ||
stylexImports: ['@stylexjs/stylex'], | ||
unstable_moduleResolution: { | ||
type: 'commonJS', | ||
rootDir: path.resolve(__dirname, '../../..'), | ||
}, | ||
}), | ||
], | ||
}) | ||
.catch(() => process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
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> | ||
); | ||
} | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
/* eslint-disable ft-flow/no-types-missing-file-annotation */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
declare module 'fs/promises' { | ||
nedjulius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
declare module.exports: any; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added esbuild plugin example to the installations page in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be patient as it may take me a few days to review this properly.