Coder Social home page Coder Social logo

reacttips-dev / stylex Goto Github PK

View Code? Open in Web Editor NEW
288.0 288.0 19.0 2.74 MB

Write CSS-in-JS with atomic support. Like Facebook's Stylex!

License: MIT License

JavaScript 46.44% HTML 1.29% TypeScript 50.29% CSS 0.23% Makefile 0.22% Vue 1.54%
css css-in-js

stylex's People

Contributors

adamward459 avatar erjanmx avatar ladifire avatar leoaslan2603 avatar nos-nart avatar somibuon avatar vitomir-lengoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylex's Issues

Cannot find module '@babel/core' when build with webpack + typescript(ts-loader)

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
}

image

CRA example request

How do I use configure this package with create-react-app without eject the app npm run eject

pseudo in media query not working

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)',
      },
    },
  },

Are you using your yourself?

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?

Improve type definition

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%",
    }

Cannot install dependecies with node 12.4.0 and yarn

I cannot install depencies when forking project with yarn 1.22.10 and node 12.4.0 but npm it's fine

Steps:

  • Cd to project
  • Run yarn

Result

$ 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.

New ideas, improve project

  • Media query
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)",
    },
  },
  • Make command in Package.json commands more consise
 "scripts": {
    "run": "webpack --progress --watch", --> "start:watch": "webpack --progress --watch"
    "start:server": "node server.js"
  }
  • Also, please consider using husky before commiting, there are so many liting errors
    Screen Shot 2021-01-20 at 11 38 19
    Screen Shot 2021-01-20 at 11 39 28

Allow nested objects within stylex.create for importing purposes

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>
  )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.