reacttips-dev / stylex Goto Github PK
View Code? Open in Web Editor NEWWrite CSS-in-JS with atomic support. Like Facebook's Stylex!
License: MIT License
Write CSS-in-JS with atomic support. Like Facebook's Stylex!
License: MIT License
I cannot install depencies when forking project with yarn 1.22.10 and node 12.4.0 but npm it's fine
$ yarn
yarn install v1.22.10
[1/4] Resolving packages...
Couldn't find any versions for "@ladifire-opensource/stylex-webpack-plugin" that matches "0.0.1-beta1"
? Please choose a version of "@ladifire-opensource/stylex
-webpack-plugin" from this list: (Use arrow keys)
Couldn't find any versions for "@ladifire-opensource/stylex" that matches "0.0.1-beta1"
? Please choose a version of "@ladifire-opensource/stylex
" from this list: (Use arrow keys)
Couldn't find any versions for "@ladifire-opensource/babel-plugin-transform-stylex" that matches "0.0.1-beta1"
? Please choose a version of "@ladifire-opensource/babel-
plugin-transform-stylex" from this list: (Use arrow keys)
> 0.0.1-beta.0 (node:13924) MaxListenersExceededWarning: ? Please choose a version of "@ladifire-opensource/babel-
plugin-transform-stylex" from this list: 0.0.1-beta.0
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
error @parcel/[email protected]: The engine "node" is incompatible with this module. Expected version "^10 || ^12.18.3 || >=14". Got "12.4.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
This is my file webpack.config.js
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const StylexPlugin = require('@ladifire-opensource/stylex-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const cacheGroups = {
vendorCore: {
name: 'vendor-core',
test: /node_modules\/@ladifire.*/g,
chunks: 'all',
priority: 0,
enforce: true
},
vendors: {
name: 'vendor',
test: /node_modules[\\/](?!@ladifire).*/g,
priority: -10,
enforce: true,
chunks: 'initial'
}
};
const configWebpack = (env, { mode = 'development' }) => {
const isDev = mode === 'development'
const config = {
mode,
entry: { app: path.resolve(__dirname, 'src/presentations/index.tsx') },
output: {
path: path.resolve(__dirname, 'dist'),
// publicPath: './',
filename: '[name].[fullhash:6].min.js',
},
target: isDev ? 'web' : 'browserslist',
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx', '.json'],
alias: {
Lib: path.resolve(__dirname, 'src/_libs'),
Utils: path.resolve(__dirname, 'src/_utils'),
Assets: path.resolve(__dirname, 'src/_assets'),
Constants: path.resolve(__dirname, 'src/_constants'),
'@': path.resolve(__dirname, 'src'),
'@@': path.resolve(__dirname, 'src/presentations'),
Components: path.resolve(__dirname, 'src/presentations/components'),
},
},
optimization: {
splitChunks: {
chunks: 'all',
maxInitialRequests: 5,
maxAsyncRequests: 7,
cacheGroups,
},
removeEmptyChunks: true,
minimize: !isDev,
mangleWasmImports: true,
mergeDuplicateChunks: true,
nodeEnv: mode,
},
module: {
rules: [
{
test: /\.(tsx|ts)$/,
enforce: 'pre',
exclude: /node_modules|browser_components/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
{
loader: StylexPlugin.loader,
options: {
inject: false,
},
},
],
},
{
test: /\.(s[ac]ss|css)$/,
exclude: /node_modules/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader', // Parse the css into js
options: { sourceMap: isDev },
},
{
loader: 'sass-loader', // Convert Scss/sass to css
options: { sourceMap: isDev },
},
],
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true },
},
],
},
{
test: /\.(png|svg|jpe?g|gif)$/i,
include: path.join(__dirname, 'public'),
use: [
{
loader: 'file-loader',
options: {
outputPath: 'images',
name: () => (isDev ? '[path][name].[ext]' : '[chunkhash].[ext]'),
},
},
],
},
],
},
// stats: { warningsFilter: /export .* was not found in/ },
// ignoreWarnings: [/Failed to parse source map/],
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: mode, // use 'development' unless process.env.NODE_ENV is defined
}),
new ForkTsCheckerWebpackPlugin({
async: false,
}),
new StylexPlugin(),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'dist/index.html'),
template: path.resolve(__dirname, 'public/index.html'),
}),
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name].[fullhash].css',
chunkFilename: isDev ? '[id].css' : '[id].[fullhash].css',
}),
new CleanWebpackPlugin(),
],
}
if (isDev) {
config.devtool = 'inline-source-map'
config.module.rules.push({
test: /\.js$/,
enforce: 'pre',
exclude: /node_modules/,
use: ['source-map-loader'],
})
config.watchOptions = {
aggregateTimeout: 200,
poll: 1000,
ignored: /node_modules/,
}
config.plugins = [
...config.plugins,
new webpack.ProgressPlugin(),
new webpack.HotModuleReplacementPlugin(),
]
config.devServer = {
clientLogLevel: 'silent',
transportMode: 'ws',
contentBase: path.resolve(__dirname, 'src'),
hot: true,
open: true,
port: 9000,
overlay: false,
inline: true,
compress: true,
publicPath: '/',
historyApiFallback: true,
stats: {
colors: true,
hash: false,
version: false,
timings: true,
assets: false,
chunks: false,
modules: false,
reasons: false,
children: false,
source: false,
errors: true,
errorDetails: true,
warnings: true,
publicPath: false,
entrypoints: false,
},
}
}
return config
}
How do I use configure this package with create-react-app without eject the app npm run eject
Due to newest type definition update from @somibuon. We need improve this:
const styles = stylex.create({
root: {
a: 150, // ??
b: "foo", // ??
width: 150,
height: 150,
backgroundColor: "red",
color: "#fff",
padding: 8,
display: "flex",
alignItems: "center",
justifyContent: "center",
marginTop: 12,
"@media (max-width: 899px)": {
width: "100%",
}
},
})
We don't want "a: 150" still exits in our code, this is dead code. So we need to check for CSS Properties.
I think you need to take type from css.Properties.
With media query, you can define custom type, then extends the CSS Object type
"@media (max-width: 899px)": {
width: "100%",
}
I noticed that this repo hasn't changed recently, and also that Meta still didn't open source Stylex, so I wonder if it's working well for you.
Are you happy with this approach?
I would like to define styles once and import throughout my app.
[styles.js]
import { margin } from './margin'
const styles = stylex.create({
margin
});
export default styles
[margin.js]
export const margin = {
micro: {
margin: 4
},
small: {
margin: 8
},
top: {
micro: {
marginTop: 4
},
small: {
marginTop: 8
}
}
}
[component.js]
import styles from './styles'
function Component() {
return (
<div className={stylex(styles.margin.small)}>
<button className={stylex(styles.margin.top.micro)}>
Click Me!
</button>
</div>
)
}
backgroundContainerDialog: {
"@media (max-width: 899px)": {
// TODO: check here, miss "a@media"
height: "calc(50vh)",
},
},
Consider changing it to something like this
backgroundContainerDialog: {
[stylex.breakpoints.up('md')]: {
// TODO: check here, miss "a@media"
height: "calc(50vh)",
},
},
"scripts": {
"run": "webpack --progress --watch", --> "start:watch": "webpack --progress --watch"
"start:server": "node server.js"
}
We might need to support SWC since the current boilerplate to integrate stylex with NextJS (app folder) will have performance impacts
Need check:
statsMain: {
gridArea: 'main',
position: 'relative',
borderRadius: 'var(--radius)',
background: '#fff',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginTop: -25,
marginBottom: -25,
marginRight: 0,
marginLeft: 0,
boxShadow: '0 0 0 1px var(--accents-2)',
filter: 'drop-shadow(0 8px 30px rgba(0, 0, 0, .12))',
':before': {
content: '""',
background: '#fff',
width: 12,
height: 12,
position: 'absolute',
left: '100%',
borderRight: '1px solid var(--accents-2)',
borderTop: '1px solid var(--accents-2)',
borderTopRightRadius: 4,
transform: 'translateX(-45%) rotate(45deg)',
},
'@media screen and (max-width:768px)': {
margin: 0,
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
':before': {
left: 'unset',
top: '100%',
transform: 'translateY(-45%) rotate(135deg)',
},
},
},
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.