Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed when first time trying out storybook-angular. Could you please provide more comprehensive example for Angular? #2616

Closed
dereklin opened this issue Jan 2, 2018 · 43 comments

Comments

@dereklin
Copy link

dereklin commented Jan 2, 2018

I am new to storybook. I have just given storybook-angular a try.

Here is my repo: https://github.com/dereklin/nx-demo-jest/tree/trying-out-storybook

The set up was quick easy.

Then I tried to test (write a story) my tab-nav component.

The first problem:

When I tried to do this

import { TabNavComponent } from '@nx-demo-jest/tab-nav';

'@nx-demo-jest/tab-nav' can't be resolved. Is there an option to map @nx-demo-jest to my libs folder?

So I had to do this instead:

import { TabNavComponent } from '../libs/tab-nav/src/tab-nav/tab-nav.component';

I go to localhost:6006 and click on my story. In the console log, I see

Unhandled Promise rejection: Expected 'styles' to be an array of strings. ; Zone: <root> ; Task: Promise.then ; Value: Error: Expected 'styles' to be an array of strings.
    at assertArrayOfStrings (compiler.js:2522)
    at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:14951)
    at CompileMetadataResolver._getEntryComponentMetadata (compiler.js:15839)
    at compiler.js:15309

It seems like scss is not supported out of the box. How can I enable scss?

So I switch to css for now, just want to see some component UI.

Then I see this error:

compiler.js:485 Uncaught Error: Template parse errors:
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("<ul class="nav nav-tabs">
  <li *ngFor="let tab of tabs" class="nav-item">

So I need to some how load all the dependencies, one being the RouterModule. How do I do that?

It would be great if there was a more comprehensive example.

Just to rule out simeple mistakes on my part, I forked the storybook project, cd into examples/angular-cli. I ran npm i, then npm run storybook. I got a lot of errors:

ERROR in ./src/stories/component-with-di/di.component.stories.ts
(2,33): error TS2307: Cannot find module '@storybook/addon-knobs/angular'.

ERROR in ./src/stories/custom-metadata.stories.ts
(2,33): error TS2307: Cannot find module '@storybook/addon-knobs/angular'.

ERROR in ./src/stories/addon-knobs.stories.ts
(14,8): error TS2307: Cannot find module '@storybook/addon-knobs/angular'.

ERROR in ./node_modules/@storybook/angular/dist/client/preview/angular/app.token.ts
Module build failed: Error: Typescript emitted no output for C:\Users\Derek\sandbox\storybook\examples\angular-cli\node_modules\@storybook\angular\dist\client\preview\angular\app.token.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Users\Derek\sandbox\storybook\examples\angular-cli\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Users\Derek\sandbox\storybook\examples\angular-cli\node_modules\ts-loader\dist\index.js:29:12)
 @ ./node_modules/@storybook/angular/dist/client/preview/angular/helpers.ts 10:18-40
 @ ./node_modules/@storybook/angular/dist/client/preview/render.js
 @ ./node_modules/@storybook/angular/dist/client/preview/index.js
 @ ./node_modules/@storybook/angular/dist/client/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js
....
@dereklin dereklin changed the title Could you please provide more comprehensive example for Angular? Failed when first time trying out storybook-angular. Could you please provide more comprehensive example for Angular? Jan 2, 2018
@dereklin
Copy link
Author

dereklin commented Jan 2, 2018

Digging through the examples I found this to help me set up the dependencies:

  moduleMetadata: {
    imports: [],
    schemas: [NO_ERRORS_SCHEMA],
    declarations: [],
    providers: []
  },

Now I need to figure out how to supply styles on the story level.

How to use scss

How to use mapped modules

@igor-dv
Copy link
Member

igor-dv commented Jan 2, 2018

Hey, @dereklin , thanks for the feedback. We will improve our docs to make it easier.
Regarding the storybook/angular-cli - Storybook is a monorepo, you need to build it in the appropriate way before running the examples - you can check it here.
Scss - yeah, there is no support for this out of the box, but you can extend the webpack.config to make it possible for your project - check this

@dereklin
Copy link
Author

dereklin commented Jan 2, 2018

@igor-dv Thanks for all good work.

I followed the link you gave me to try to set up scss: https://storybook.js.org/configurations/custom-webpack-config/

It's still not working

Here is my repo: https://github.com/dereklin/nx-demo-jest/tree/trying-out-storybook

I have these loaders installed: "style-loader", "css-loader", "sass-loader"

@igor-dv
Copy link
Member

igor-dv commented Jan 2, 2018

You need to use raw-loder instead of the style-loader

Something like this:

{
  test: /\.scss$/,
  loaders: ["raw-loader", "sass-loader"],
  include: path.resolve(__dirname, '../')
}

Not sure if you need css-loader.

@karlos1337
Copy link

karlos1337 commented Jan 2, 2018

But to expand the webpack configuration you need to run an' ng eject' and this removes other CLI capabilities and can't be undone.

Is there a solution that doesn't involve edit the CLI webpack configuration?

@igor-dv
Copy link
Member

igor-dv commented Jan 2, 2018

I am not sure, but maybe for Storybook you don't need to eject the CLI. Try to put webpack.config.js to the .storybook dir and fill there only missing scss things.

@karlos1337
Copy link

Thanks @igor-dv, it works, now have problems with providers dependencies, can't find any Angular documentation and don't want to make more rubbish in your github issues, are there any forum or channel for support?

@igor-dv
Copy link
Member

igor-dv commented Jan 2, 2018

Yeah, we have to provide a better documentation. For now, you can check this: https://github.com/storybooks/storybook/blob/master/examples/angular-cli/src/stories/custom-metadata.stories.ts

And we have a slack

@igor-dv
Copy link
Member

igor-dv commented Jan 2, 2018

Here is the right slack link - https://now-examples-slackin-rrirkqohko.now.sh/

@dereklin
Copy link
Author

dereklin commented Jan 2, 2018

@igor-dv Thanks for the tip on getting scss to work.

Does storybook config provide any module name mapper feature like jest?:

    "moduleNameMapper": {
      "@nx-demo-jest/(.*)": "<rootDir>/libs/$1"
    }

So that I can do this:

import { TabNavComponent } from '@nx-demo-jest/tab-nav';

instead of

import { TabNavComponent } from "../libs/tab-nav";

I can create .storybook/preview-head.html and include style frameworks like bootstrap. That's on the global level. Can I use different styles on the individual story level?

Should I be asking these questions in slack? Will it be under the #support channel?

@igor-dv
Copy link
Member

igor-dv commented Jan 3, 2018

Storybook itself doesn't provide any module aliasing api. Maybe you can use the webpack alias to achieve this, but I think it doesn't scale. You can think about "story" like about some part of your component - you have css, html and spec alongside with you component js code, so you can place there the .story.js file as well, and everything will be relative.

Can I use different styles on the individual story level?

Can you elaborate?

Should I be asking these questions in slack? Will it be under the #support channel?

You can ask these questions in slack as well. Yeah, #support or #angular channels.

@igor-dv
Copy link
Member

igor-dv commented Jan 4, 2018

Closing it for now. @dereklin feel free to reopen if you are still having issues.

@dereklin
Copy link
Author

@igor-dv Hi Igor, I tried on a very simple example last time and put storybook on hold. Now I am picking it up creating more complicated stories.

My repo is at https://github.com/dereklin/nx-demo-jest/tree/storybook
It's the storybook branch I am referring to in this issue

I am run my app fine with npm run start:app1
But when I run npm run storybook, I see two errors:

ERROR in ./libs/dummy1-service/src/dummy1-service.ts
(5,14): error TS7006: Parameter 'name' implicitly has an 'any' type.

Can storybook ignore the implicit any issue? Since neither vscode, typescript, nor linting complains about the implicit any.

ERROR in ./libs/tab-nav/src/tab-nav/tab-nav.component.ts
(3,31): error TS2307: Cannot find module '@nx-demo-jest/dummy1-service'.

My component imports from a mapped path. It works with ng serve and ng build. Does it mean storybook has to understand what @nx-demo-jest means before storybook can work in this case?

@igor-dv
Copy link
Member

igor-dv commented Jan 26, 2018

@dereklin , let's try to solve meanwhile the first issue =) In the latest beta release we have an ability to override tsconfig.json file.
Can you please try:

  1. Change the @storybook/* to v3.4.0-beta.5
  2. add tsconfig.json to your .storybook dir. You can extend there your default one and override noImplicitAny prop (though I'm not sure why you are getting these errors).

so the config may look like this:

{
  "extends": "path to defautlt config",
  "exclude": [
    "you can exclude things here, for example test/spec files"
  ],
  "include": [
    "I think you need to include here your src dir again"
  ],
  "compilerOptions": {
    "noImplicitAny": false // <-- override the noImplicitAny
  }
}

@dereklin
Copy link
Author

@igor-dv Thanks for responding so quickly.
I think you mean v3.4.0-alpha.5 right? v3.4.0-beta.5 was not found for me.

Here is my new branch:
https://github.com/dereklin/nx-demo-jest/tree/storybook-implicit-any

I am getting these errors:

ERROR in ./libs/tab-nav/src/tab-nav/tab-nav.component.scss
Module build failed:

             ^
      Invalid CSS after "module.exports": expected "{", was '= ""'
      in C:\Users\Derek\sandbox\nrwl\nx-demo-jest\libs\tab-nav\src\tab-nav\tab-nav.component.scss (line 1, column 15)
 @ ./libs/tab-nav/src/tab-nav/tab-nav.component.ts 29:21-56
 @ ./libs/tab-nav/index.ts
 @ ./stories/tab-nav.stories.js
 @ ./stories .stories.js$
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js

ERROR in ./node_modules/@storybook/angular/dist/client/preview/angular/app.token.ts
Module build failed: Error: Typescript emitted no output for C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\dist\client\preview\angular\app.token.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:29:12)
 @ ./node_modules/@storybook/angular/dist/client/preview/angular/helpers.ts 10:18-40
 @ ./node_modules/@storybook/angular/dist/client/preview/render.js
 @ ./node_modules/@storybook/angular/dist/client/preview/index.js
 @ ./node_modules/@storybook/angular/dist/client/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js

ERROR in ./node_modules/@storybook/angular/dist/client/preview/angular/components/app.component.ts
Module build failed: Error: Typescript emitted no output for C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\dist\client\preview\angular\components\app.component.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:29:12)
 @ ./node_modules/@storybook/angular/dist/client/preview/angular/helpers.ts 7:22-59
 @ ./node_modules/@storybook/angular/dist/client/preview/render.js
 @ ./node_modules/@storybook/angular/dist/client/preview/index.js
 @ ./node_modules/@storybook/angular/dist/client/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js

ERROR in ./node_modules/@storybook/angular/dist/client/preview/angular/components/error.component.ts
Module build failed: Error: Typescript emitted no output for C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\dist\client\preview\angular\components\error.component.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:29:12)
 @ ./node_modules/@storybook/angular/dist/client/preview/angular/helpers.ts 8:24-63
 @ ./node_modules/@storybook/angular/dist/client/preview/render.js
 @ ./node_modules/@storybook/angular/dist/client/preview/index.js
 @ ./node_modules/@storybook/angular/dist/client/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js

ERROR in ./node_modules/@storybook/angular/dist/client/preview/angular/components/no-preview.component.ts
Module build failed: Error: Typescript emitted no output for C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\dist\client\preview\angular\components\no-preview.component.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
    at successLoader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:47:15)
    at Object.loader (C:\Users\Derek\sandbox\nrwl\nx-demo-jest\node_modules\@storybook\angular\node_modules\ts-loader\dist\index.js:29:12)
 @ ./node_modules/@storybook/angular/dist/client/preview/angular/helpers.ts 9:29-73
 @ ./node_modules/@storybook/angular/dist/client/preview/render.js
 @ ./node_modules/@storybook/angular/dist/client/preview/index.js
 @ ./node_modules/@storybook/angular/dist/client/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js

ERROR in ./libs/tab-nav/src/tab-nav/tab-nav.component.ts
Module not found: Error: Can't resolve '@nx-demo-jest/dummy1-service' in 'C:\Users\Derek\sandbox\nrwl\nx-demo-jest\libs\tab-nav\src\tab-nav'
 @ ./libs/tab-nav/src/tab-nav/tab-nav.component.ts 13:23-62
 @ ./libs/tab-nav/index.ts
 @ ./stories/tab-nav.stories.js
 @ ./stories .stories.js$
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./node_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js
Child html-webpack-plugin for "index.html":
         Asset    Size  Chunks  Chunk Names
    index.html  569 kB       0
       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./node_modules/@storybook/angular/dist/server/index.html.ejs 1.69 kB {0} [built]
       [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [3] (webpack)/buildin/module.js 517 bytes {0} [built]
Child html-webpack-plugin for "iframe.html":
          Asset    Size  Chunks  Chunk Names
    iframe.html  568 kB       0
       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./node_modules/@storybook/angular/dist/server/iframe.html.ejs 974 bytes {0} [built]
       [1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [3] (webpack)/buildin/module.js 517 bytes {0} [built]

@igor-dv
Copy link
Member

igor-dv commented Jan 26, 2018

I think you mean v3.4.0-alpha.5 right? v3.4.0-beta.5 was not found for me.

Yeah, exactly. =)

I've played with your repo, and here are my findings:

  1. You need to delete the scss rule from the .storybook/webpack.config.js, since style rules in "v3.4.0-beta.5" are taken according to the angular-cli.
  2. In order to solve paths issue, you need to change stories to be *.ts
  3. You will need to add ../stories/**/*.ts and ../node_modules/@storybook/**/*.ts (we are currently not distributing our .ts files) to the "include" of the .storybook/tsconfig.json

I wasn't able to run the app, though, because some of your dependencies were incompatible with my node version, but probably it won't be a problem for you.

@dereklin
Copy link
Author

@igor-dv I made those three changes, when I run npm run storybook, nothing crashes, but I don't see any stories at all. Here is the repo: https://github.com/dereklin/nx-demo-jest/tree/storybook-implicit-any-2

I looked at .storybook/config.js. It's loading the .js files:

const req = require.context('../stories', true, /.stories.js$/);

I changed it to ts:

const req = require.context('../stories', true, /.stories.ts$/);

I am getting the same mapping problem:

ERROR in ./libs/tab-nav/src/tab-nav/tab-nav.component.ts
Module not found: Error: Can't resolve '@nx-demo-jest/dummy1-service' in 'C:\Use
rs\delin\sandbox\nrwl\nx-demo-jest\libs\tab-nav\src\tab-nav'
 @ ./libs/tab-nav/src/tab-nav/tab-nav.component.ts 13:23-62
 @ ./libs/tab-nav/index.ts
 @ ./stories/tab-nav.stories.ts
 @ ./stories .stories.ts$
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/angular/dist/server/config/polyfills.js ./nod
e_modules/@storybook/angular/dist/server/config/globals.js (webpack)-hot-middlew
are/client.js?reload=true ./.storybook/config.js
Child html-webpack-plugin for "index.html":
                                   Asset      Size  Chunks             Chunk Nam

@igor-dv
Copy link
Member

igor-dv commented Jan 26, 2018

Ah, I forgot about the config.js 🤦‍♂️ .

Let's try another workaround. Maybe you can add a NormalModuleReplacementPlugin to the .storybook/webpack.config.js that will replace '@nx-demo-jest' with an absolute path?

@dereklin
Copy link
Author

dereklin commented Jan 26, 2018

@igor-dv This works, but like you have mentioned before, it's not scalable:

    new webpack.NormalModuleReplacementPlugin(
      /@nx-demo-jest\/dummy1-service/,
      '../../../../libs/dummy1-service'
    )

I will have different files importing Dummy1Service, and they are in different nested levels. So while this set up works for one nested level, it will not work for another.

It would be best if storybook can support this mapping dynamically

@dereklin
Copy link
Author

BTW, partial match like this doesn't work:

    new webpack.NormalModuleReplacementPlugin(
      /@nx-demo-jest/,
      '../../../../libs'
    )

And absolute path doesn't work

@dereklin
Copy link
Author

I am curious, don't people use lerna for react projects as well? Do you know how they solve the mapping problem?

@igor-dv
Copy link
Member

igor-dv commented Jan 27, 2018

We use lerna and yarn workspaces in Storybook monorepo, afaik it works with symlinks. Maybe @ndelangen can shed more light on this.

Anyway, this change in webpack config worked for me:

const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');

const libPath = path.resolve('libs');

module.exports = {
  module: {
    rules: [
    ]
  },
  plugins: [
    new CopyWebpackPlugin([
      {
        from: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
        to: 'assets/bootstrap/bootstrap.min.css'
      }
    ]),
    new webpack.NormalModuleReplacementPlugin(/@nx-demo-jest/, function(resource) {
      resource.request = resource.request.replace(/@nx-demo-jest/, libPath);
    })
  ]
};

@dereklin
Copy link
Author

@igor-dv Thanks for the awesome solution! Now I can even import from mapped path in the stories. Here is the working repo: https://github.com/dereklin/nx-demo-jest/tree/storybook-mapped-import

Last time you mention there was going to be more documentation on storybook-angular, do you know if they are available.

If you look at this, https://github.com/dereklin/nx-demo-jest/blob/storybook-mapped-import/apps/playground/src/app/tab-nav.component.sandbox.ts, I can specify custom styles for the component:

styles: [`
    app-tab-nav {
      background-color: yellow;
      font-size: 25px;
    }
  `]

What is the equivalent of that with storybook-angular?

@igor-dv
Copy link
Member

igor-dv commented Jan 27, 2018

Last time you mention there was going to be more documentation on storybook-angular, do you know if they are available.

Not really. We still need more work (and help) on it. We do improve our examples in the monorepo, which is kinda documentation. Every new usecase we find we try to put there, so maybe it worth adding yours as well. Or even adding the module replacement by default based on angular-cli (CC @Quramy , @alterx )

Regarding the custom styles, IMO we have no a direct equivalent to this. Can you elaborate how does it work?

@dereklin
Copy link
Author

It seems like in angular-playground, each sandbox is also like a component, a host component. The styles property is for styling the host's child, in my case, my TabNavComponent

@igor-dv
Copy link
Member

igor-dv commented Jan 28, 2018

Interesting. I think we can do something like this too. I'll check today.

@dereklin
Copy link
Author

@igor-dv In a mono repo, you could have multiple AboutComponent's from different apps. How do you name space them in storybook?

@igor-dv
Copy link
Member

igor-dv commented Jan 30, 2018

You have an option to add hierarchy. Since v3.4 you also may use multiple hierarchies feature

Hierarchy separator is "/" by default. And for multiple hierarchies you need to add it explicitly. Both can be configured with addon-options like this:

// config.js

import { setOptions } from '@storybook/addon-options';

setOptions({
  hierarchySeparator: /\/|\./,
  hierarchyRootSeparator: /\|/,
});

And then used like this:

storiesOf('App|Some/Context/AboutComponent', module)
  .add('blah blha', () => {...})

@dereklin
Copy link
Author

@igor-dv The / works beautifully, but how is | supposed to work?

Here is my repo: https://github.com/dereklin/nx-demo-jest/tree/storybook-hierarchy

The | is just added to the name of my first level hierarchy: Test|libs:

storybook-hierarchy

Is this the expected behavior?

@igor-dv
Copy link
Member

igor-dv commented Jan 30, 2018

@dereklin looks like you didn't register addon-options in the addons.js

@dereklin
Copy link
Author

Thanks @igor-dv !

@dereklin
Copy link
Author

@igor-dv I was listening AngularAir storybook episode: https://www.youtube.com/watch?v=hMK4UedZUKY
Norbert mentioned is recommended to colocation stories with the components.

For this, I am changing my config.js to this:

const req = require.context('../', true, /libs\/.*\.stories.ts$|apps\/.*\.stories.ts$/);
function loadStories() {
  req.keys().forEach((filename) => req(filename));
}

Here is my repo: https://github.com/dereklin/nx-demo-jest/tree/storybook-colocate

Does this make sense or is there a better way?

@igor-dv
Copy link
Member

igor-dv commented Jan 31, 2018

It is indeed a preferred way by most of us (as I mentioned here 👆 #2616 (comment) ), You can think of a story like a part of your "component's ecosystem". The same way you place styles and tests alongside the component =)

@ndelangen
Copy link
Member

@dereklin 👋 Awesome to hear you watched the show and got something out of it!

@dereklin
Copy link
Author

@igor-dv @ndelangen Thanks very much for contributing to this great product! I definitely have to watch the show again for the more advanced stuff. I think I am only scratching the surface at this point, and there are a lot of advanced features to be discovered.

In the show, Austin was saying storybook angular can hook onto the angular cli config, is that only for single app environment?

I am using nrwl/nx mono repo. But it will be nice if storybook angular can just leverage the .angular-cli.json some how for setup, so that I don't have to repeat the setup in a separate webpack config file or having to create a preview-head.html to include third party css or javascript. But I would imagine it's not a small undertaking. This sounds it would be an effort between you guys and the angular-cli team.

@ndelangen
Copy link
Member

I think @alterx might know about that

@igor-dv
Copy link
Member

igor-dv commented Feb 1, 2018

@dereklin, maybe you can elaborate more on how the angular app mono repo is built and what you have to do in order to use storybook on it? And we can probably think of a better support or about the concrete features?

@dereklin
Copy link
Author

dereklin commented Feb 1, 2018

@igor-dv I am currently setting up another github repo with I have learned from using the nrwl/nx mono repo and storybook. Once that's set up I can point out the issues I have faced more clearly.

But the biggest setup pain point is that I have to use webpack to "repeat" what .angular-cli.json does. But to be fair, .angular-cli.json is doing things at the app level. And I want to have one storybook for all the apps and the shared libs.

If .angular-cli can integrate with storybook that would be awesome. Think about unit testing. There is tsconfig.spec.json and there is test.js, and that's it to set up. And if you are using jest, the test.js is replaced with the jest config.

So imagine for storybook, there is some storybook config, either storybook.js or storybook block in the package.json (similar to jest) and another tsconfig.storybook.json. And then you can just put the stories.ts files alongside the .spec.ts files. That will be great. But again, that might be asking too much :)

@alterx
Copy link
Member

alterx commented Feb 1, 2018

Yeah @dereklin, our current implementation doesn't integrate with @nrwl/nx. It only uses the .angular-cli.json file to get the styling configuration. This work was done by @Quramy here: #2735

Let us know once you've setup this repo and let's open a new issue with your feedback so we can continue the conversation there.

Also, it sounds like you have a pretty solid understanding of what you'd like to see, are familiar with the .angular-cli.json file and have done the manual webpack configuration to make it work with storybook. We do accept PRs wink wink

@dereklin
Copy link
Author

dereklin commented Feb 1, 2018

@alterx Do you know if there is some guide on how to create PR's in general and then for storybook specifically?

I think I need to fork the project first.
I need to be able to build it.
I need to npm link it.
I need to have a local project using this linked "local storybook".
Modify the local storybook and my usage and see the changes
Then submit the pull request.
Is this about right?

@igor-dv
Copy link
Member

igor-dv commented Feb 1, 2018

@eweap
Copy link

eweap commented Dec 1, 2018

@dereklin @igor-dv Thanks a lot both of you for your usefull conversation, it helped me to implement storybook in my angular multi apps project with shared lib !

@igor-dv
Copy link
Member

igor-dv commented Dec 1, 2018

@eweap, would be great if you can document it in some way to help others 😉

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

No branches or pull requests

6 participants