Skip to content

Instantly share code, notes, and snippets.

@a-x-
Last active March 1, 2018 15:08
Show Gist options
  • Save a-x-/c81cc1391fce44c39434e609a0be9549 to your computer and use it in GitHub Desktop.
Save a-x-/c81cc1391fce44c39434e609a0be9549 to your computer and use it in GitHub Desktop.
Building css-modules library

🚫 Approach 1: converted plain css

pros:

  • much simple lib build

cons:

  • additional requirements to service build config (style-loader, css-loader for node_modules)
  • bug: every library's css file got style tag in a project 😨
  • bug: postcss-icss-selectors rule.parent is undefined — UPD fix
  • bug: css-modules-transform generateScopedName does not work — UPD fix
  • bug: generateScopedName does not apply to postcss optimized selectors — issue

todo:

  • babel-plugin-css-modules-transform preprocessCss + keepImport config
  • script for preprocessCss that should use postcss api

questions:

  • can create-react-app work well with import '*.css' under node_modules? — NO

Approach 2: complete js bundles with css

pros:

  • easy to use

cons:

  • jss runtime
  • prefined build

todo:

  • create babel plugin that will:
    • replace import s from '*.css'; by:
      const s = { selector: 'module-selector' };
      create(jssEmptyPreset()).createStyleSheet(require('./filename.jss.js'))
      
    • check source-maps are still correct
    • create filename.jss.js using something like jss convert -f js -e es6 'build/**/*.css' (from jss-cli package) with css-modules post-processing
    • initial draft: https://github.com/a-x-/babel-plugin-import-css-to-jss-calls
    • similar implementaion babel-plugin-import-css-to-jss
  • install jss as peed-dep (because mui uses it too)

questions:

  • can webpack extract jss style-objects from calls to static files? (dig into ExtractTextPlugin underhood details)
  • postcss async mitigation, postcss.async()
@a-x-
Copy link
Author

a-x- commented Feb 28, 2018

@a-x-
Copy link
Author

a-x- commented Feb 28, 2018

@a-x-
Copy link
Author

a-x- commented Mar 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment