storybook icon indicating copy to clipboard operation
storybook copied to clipboard

Framework support - Stencil.js

Open maraisr opened this issue 5 years ago • 142 comments

Describe the solution you'd like I'd like to see Stencil.js support, as I see Storybook to be very component focused, and Stencil being a very component focus framework - these tools would compliment each other very well.

Are you able to assist bring the feature to reality? yes, I can...

maraisr avatar Oct 28 '18 23:10 maraisr

Duplicate to #1870 and #3423. Let's continue a discussion there

igor-dv avatar Oct 29 '18 08:10 igor-dv

New Starter build for Current stencil and SB 5 to be created

Edd-Strickland avatar Jan 18 '19 13:01 Edd-Strickland

@Edd-Strickland want to work on a stencl support version 🎉

ndelangen avatar Jan 18 '19 13:01 ndelangen

I've upgraded the polymer starter with stencil to the latest version of SB need some help in removing polymer and adding in stencil complier now

Edd-Strickland avatar Jan 25 '19 13:01 Edd-Strickland

Hi,

@Edd-Strickland just for information, i have implemented Stencil inside Storybook like you did in your starter, in this project : https://github.com/vogloblinsky/nutrition-web-components

I have used the HTML starter of Storybook.

For now with Storybook & Stencil, i just had to :

  • add a custom header pointing to each root JavaScript file generated by Stencil
  • add static files generated by Stencil in Storybook

The main problem i think is the usage of Webpack by Storybook to handle JavaScript files imported inside a story. The ideal workflow is to only imported the JS file of the Web Component.

vogloblinsky avatar Jan 25 '19 13:01 vogloblinsky

Yeah this is what have done previously but with the polymer version however what this means is that by importing as plain static W/C implementations is you need to update each time into your story's which feels limiting.

Edd-Strickland avatar Jan 25 '19 14:01 Edd-Strickland

Hi All, I have created a wrapper that can be installed on a stencil component type project. Hope it helps. https://github.com/nisheed2440/stencil-storybook-wrapper

nisheed2440 avatar Feb 08 '19 17:02 nisheed2440

looks really good I'll test on Monday. Good work :)

Edd-Strickland avatar Feb 08 '19 17:02 Edd-Strickland

Will this be made into an official part of Storybook? I have a desperate need for this!

o-t-w avatar Feb 13 '19 15:02 o-t-w

@o-t-w We're trying, would you be able to help us?

ndelangen avatar Feb 14 '19 13:02 ndelangen

@ndelangen I would be happy to test things and provide feedback/bug reports.

o-t-w avatar Feb 14 '19 20:02 o-t-w

Would this work with LitElement (and web components in general) or just Stencil?

o-t-w avatar Feb 20 '19 11:02 o-t-w

@nisheed2440 your wrapper seems promising, I will test this soon! But it could be great to have a "native" integration documented by Storybook 👌

Nightbr avatar Mar 06 '19 17:03 Nightbr

@nisheed2440 I have been very busy(sorry everyone) but have had a very small window today to test a very vanilla version of this locally and it's really good. works really well.

going to spend some time on this next week trying to incorporate it into an existing project to see how this might work for existing stencil users / projects.

Edd-Strickland avatar Mar 07 '19 16:03 Edd-Strickland

I have tested it this morning and it works pretty well too! GJ it's really easy to setup. I have installed and tested some addons:

import '@storybook/addon-backgrounds/register';
import '@storybook/addon-knobs/register';
import '@storybook/addon-actions/register';
import '@storybook/addon-notes/register';

Everything works fine, just found one issue with addon-knobs https://github.com/storybooks/storybook/issues/5017 But there is a workaround and this should be fixed pretty soon I think.

Nightbr avatar Mar 07 '19 16:03 Nightbr

I spent the last 2 weeks playing with StencilJS and Storybook and did a livestream where I cover my solution. I feel there is a much better way, but I was able to get HMR, and most plugins to work with little issue. Would love any feedback you guys have on how to improve or import the loaders from the distribution stencil bundle.

https://www.youtube.com/watch?v=XwHtPw3izLE

And here is the repo! ^_^ https://github.com/MadnessLabs/enjin-components

popcorn245 avatar Mar 17 '19 05:03 popcorn245

@nisheed2440 Hello, i m using an approach very similar to yours and everything is working expect chromatic. were you able to make chromatic work with stencil/storybook? when i run, it does discover all my stories but all the screenshots are empty. it s probably missing the stencil when trying to render the component screenshot on chromatic server

ghaiat avatar Mar 22 '19 11:03 ghaiat

@nisheed2440 Thank you so much for this really great effort. Hopefully this gives the team here a head start in the right direction. Stencil and Storybooks are ideal for each other.

dougestey avatar Mar 28 '19 13:03 dougestey

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

stale[bot] avatar Apr 18 '19 14:04 stale[bot]

Anybody want to pick this up?

shilman avatar Apr 19 '19 04:04 shilman

My team is using StencilJS + Storybook for our common component library and I'd love to contribute. Maybe a few of us can get this thing back on track...

grahamlucid avatar Apr 29 '19 03:04 grahamlucid

Seems like there's a lot of interest, e.g. https://twitter.com/dboskovic/status/1120336958008348672

One easy win would be publishing a @storybook/preset-stencil package which packages @popcorn245 's config into a storybook preset. I still need to finish off the docs for that, but I'm using it for the upcoming Storybook Docs release and it's straightforward & how most SB config will work in the future.

I'd be happy to guide anybody who wants to pick that up.

shilman avatar Apr 29 '19 04:04 shilman

Hey @shilman, stoked so many people are psyched to pickup on this and implement Stencil with Storybook. That thread has some good things that I have found, but there are many more little bugs like having to return a string of the element in order to use knobs.

A much better implementation would piggy-back off of the Stencil compiler and allow for use of JSX like with React components, but that is MHO.

Also, Stencil One is about to drop with some huge changes so it may be good to put peepers on this Changelog to make sure whoever is working on this is aware of what is coming down the pipeline.

https://github.com/ionic-team/stencil/blob/core-refactor/BREAKING_CHANGES.md

popcorn245 avatar Apr 29 '19 05:04 popcorn245

This thread was immensely helpful to me, especially @popcorn245’s config. Personally I was using @stencil/state-tunnel, which broke that config. Fortunately I was able to get it to work with some minor ~hacks~ tweaks by running:

npm i -D [email protected]

And adding this to .storybook/webpack.config.js:

const { existsSync, readdirSync } = require('fs');
const { resolve } = require('path');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = ({ config }) => {
  // 1. Transpile @stencil modules with Babel
  const babelLoader = config.module.rules.find(
    ({ use }) => use && use[0].loader === 'babel-loader'
  );
  babelLoader.exclude = [/node_modules\/(?!\@stencil).*/];
  if (babelLoader.use[0].options) {
    babelLoader.use[0].options.plugins = ['@babel/plugin-syntax-dynamic-import'];
  }

  // 2. Load JS & CSS from our components
  config.entry.push(resolve(__dirname, '..', 'dist', 'MYCOMPONENTNAME.js'));
  config.entry.push(resolve(__dirname, '..', 'dist', 'MYCOMPONENTNAME.css'));

  const components = resolve(__dirname, '..', 'dist', 'collection', 'components');
  readdirSync(components).map(file => {
    jsFilePath = resolve(components, file, `${file}.js`);
    try {
      if (existsSync(jsFilePath)) config.entry.push(jsFilePath);
    } catch (err) {
      console.error(err);
    }

    cssFilePath = resolve(components, file, `${file}.css`);
    try {
      if (existsSync(cssFilePath)) config.entry.push(cssFilePath);
    } catch (err) {
      console.error(err);
    }
  });

  // 3. Fix dynamic imports for Storybook
  // IMPORTANT: webpack must be at 4.28 due to a bug. See here: https://github.com/webpack/webpack/issues/8656
  config.plugins.push(
    new CopyPlugin([
      {
        from: resolve(__dirname, '..', 'dist'),
        to: resolve(__dirname, '..', 'node_modules', '@storybook', 'core', 'dist', 'public'),
      },
    ])
  );

  return config;
};

drwpow avatar May 06 '19 20:05 drwpow

Starting to experiment with this also and (as mentioned somewhere else) using concurrently seems to work just fine for me (for now). I created a quick starter project that includes everything you need to get up and running with both stencil and storybook. Already using the latest stencil release.

Check it out here: stencil-storybook-starter

fvaldes33 avatar May 22 '19 02:05 fvaldes33

@fvaldes33 Nice! Starred it. I actually just updated to Stencil One beta and my config looks similar—I basically could use the stock webpack setup entirely.

The only difference for me was using stencil build --watch (prod, not dev) because the build times are so fast and it’s easier to consume the prod version in Stencil (especially with global styles and other imports).

drwpow avatar May 22 '19 02:05 drwpow

@fvaldes33 how are you able to reference the build/components.js in your preview-head.html like that? I have to supply the full path e.g. http://localhost:3333/build/components.js. But I would like to not have to do that.

(I'm not using your starter, but i'm using the stencil component starter with a fresh storybook/html install)

EDIT: realized i was starting storybook on port 6006 instead of in the www folder. problem solved!

perkrlsn avatar May 23 '19 14:05 perkrlsn

Looks like lots of us have similar solutions out there (including me https://github.com/jagreehal/stencil-boilerplate), but I'd really like hot/live updates when I edit a Stencil component. Currently I have to manually refresh the browser to reload Storybook.

jagreehal avatar Jun 13 '19 20:06 jagreehal

Is there a bullet list of requirements to complete this? I'd be happy to pitch in if I knew what needed to be built.

chazzmoney avatar Jun 21 '19 21:06 chazzmoney

What is the current state? Can we contribute? I would love to see this!

jeanbenitez avatar Jul 12 '19 14:07 jeanbenitez