question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the best way to publish this component?

See original GitHub issue

I’m creating this issue to roll together #26, #35 and #38 as a central place for feedback and ideas.

It appears there are several issues relating to the build process and use of JSX, including:

  • Unnecessary packages (reactify) are included for the Browserify build process, when you’re using Webpack (#35)
  • Use of .js as the script extension means Webpack needs special config to process the JSX (#26)
  • Node.js gets a syntax error when you try and do server-side rendering (#38)

The simplest way to side-step these issues is to avoid JSX in this and any other packaged component, however I’d much prefer to just figure out how to solve this problem and have a great build and packaging process that works everywhere and doesn’t have these issues.

In addition, I’ve created a common gulp tasks package (react-component-gulp-tasks) and a react component generator (generator-react-component) with the hopes of solving the problems of how to build and maintain react components for other developers too. It would be great to get some consistency in this space, imo.

To recap, my requirements for the build process / tasks are:

  • Hopefully, ability to use JSX
  • Efficient development with on the fly regeneration of scripts (currently implemented via Watchify)
  • Live-reload of scripts and css for the examples
  • Compatibility with Browserify and Webpack build processes
  • Support for server-side rendering with Node.js
  • Generation of standalone package for Bower (is this actually useful?)
  • Easy ability to publish to npm / gh-pages

I would also prefer not to have to rename my javascript files to .jsx files. This is a purely personal preference; I’m willing to be pragmatic but ideally with the right pre-processor setup, you should be able to switch between using JSX or ES6 syntax in a file, and vanilla Javascript, without changing the extension.

I’d really appreciate everyone’s input into how these requirements can be met, hopefully we can achieve all of them.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:25 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
floatdropcommented, Jan 10, 2015

One big problem of packaging React component is how to manage styles:

  • Making styles extendable
  • Solving CSS specificity problem
  • Escaping global scope
  • … all other problems from React CSS in JS.

Like @petehunt says, if you satisfied with inline styles - then you don’t have those problems, but you will need to handle all :hover states for yourself. Downside of this - pseudo-elements (like :before and :after) can not be done this way.

There are couple packages to solve this: RCSS, react-style and others (just search for style in awesome-react). Often they injecting your styles in <style> tag and generate own selector for element (with :before). So it get things working.

But writing CSS in JS is not common in our team (because you have no autocomplete and syntax highlighting is bad).

@nmn can you look at react-styled - is this similar to what you want?

0reactions
eedrahcommented, Apr 5, 2016

Hi @JedWatson - you mentioned writing up your learnings. Any thoughts not already expressed in this thread?

Also, did a consensus come of the css discussion and/or is there a more appropriate place to talk about that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publish styles and components – Figma Help Center
There are a few ways to access the library modal from within a file: ... Right-click on the component and select Show when...
Read more >
How to Publish React Components - Bits and Pieces
The steps, that go from isolating to publishing components, are as follow: Install Bit; Initialize a Bit workspace in the app's root directory ......
Read more >
Create and Publish a React Component Library — the easy way
The easiest way to create a React component library is by using a CLI tool called create-react-library . npx create-react-library.
Read more >
Developing Components: Publishing
Do publish latest standard EcmaScript · Do publish standard es modules · Do include "main": "index. · Do export element classes · Do...
Read more >
How to Create and Publish a React Component Library
This tutorial will take you through the process of creating and publishing your own custom React component library and hosting it on Github....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found