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.

@storybook/angular does not autoprefix as angular-cli

See original GitHub issue

Describe the bug @storybook/angular does not respect .browserlist or any other way described in angualr story autoprexier

To Reproduce

  1. generate angular projekt: https://storybook.js.org/basics/guide-angular/
  2. add .browserslistrc to root (see code snippet for example)
  3. create component + story with css property that should be autoprefixed (e.g. apperance: none, display: flex, )
  4. start storybook

Expected behavior the generated css with storybook should contain prefixed css properties

Screenshots If applicable, add screenshots to help explain your problem. bildschirmfoto 2019-01-31 um 09 49 58

with work around: bildschirmfoto 2019-01-31 um 09 51 48

Code snippets story

import { moduleMetadata, storiesOf } from '@storybook/angular';
import { CheckboxComponent } from './checkbox.component';

const stories = storiesOf('Input/Checkbox', module)
  .addDecorator(
    moduleMetadata({
      entryComponents: [CheckboxComponent],
      declarations: [CheckboxComponent],
    })
  );

stories.add('unchecked', () => ({
  template: `<input prefix-checkbox type="checkbox">`
}));

component:

@Component({
  selector: 'input[prefix-checkbox]',
  templat: '<ng-content></ng-content>,
  styleUrls: ['./checkbox.component.scss']
})
export class CheckboxComponent {
}

style:

:host {
  appearance: none;
}

.browserslistrc

### Supported Browsers
last 2 version
IE >= 10

generated css should be:

-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

System:

Additional context at the moment I am useing a project webpack config to work around this problem:

module.exports = baseConfig => {
  let cssRule = baseConfig.module.rules.find(
    rule => rule.test.toString() === /\.s(c|a)ss$/.toString()
  );
  if (!cssRule) {
    throw new Error('css rule for modification not found');
  }
  cssRule.use = [
    { loader: require.resolve('raw-loader') },
    { loader: require.resolve('postcss-loader'),
      options: {
        plugins: [
          require('autoprefixer')
        ]
      }
    },
    { loader: require.resolve('sass-loader') },
  ];

  return baseConfig;
};

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexancommented, Feb 10, 2019

I will create a merge request modifying https://github.com/storybooks/storybook/blob/4da246bbe9413510b48d1ab8b9faf4fae4656d92/app/angular/src/server/framework-preset-angular.js to add this behavior to @storybook/angular.

I have two questions:

  • Is there a way to test this?
  • I can’t get my change past your linters
        {
          test: /\.s(c|a)ss$/,
          use: [
            require.resolve('raw-loader'),
            {
              loader: require.resolve('postcss-loader'),
              options: {
                plugins: [require('autoprefixer')],
              },
            },
            require.resolve('sass-loader'),
          ],
        },

will throw

.../storybook/app/angular/src/server/framework-preset-angular.js
40:27  error  Unexpected require()                                                                                  global-require
40:27  error  'autoprefixer' should be listed in the project's dependencies. Run 'npm i -S autoprefixer' to add it  import/no-extraneous-dependencies

but using require.resolve in postcss plugin will not work and throw when used in project

Module build failed (from ./node_modules/postcss-loader/lib/index.js):
Error: .../node_modules/autoprefixer/lib/autoprefixer.js is not a PostCSS plugin
0reactions
shilmancommented, Mar 14, 2019

Yowza!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-alpha.6 containing PR #5612 that references this issue. Upgrade today to try it out!

Because it’s a pre-release you can find it on the @next NPM tag.

Closing this issue. Please re-open if you think there’s still more to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook for Angular fails with default/initial library config ...
Storybook for Angular fails to build with default (initial) library configuration. It'll complain about a missing tsConfig setting. But the ...
Read more >
Build a simple component in isolation - Storybook Tutorials
We'll build our UI following a Component-Driven Development (CDD) methodology. It's a process that builds UIs from the “bottom-up”, starting with components ...
Read more >
NX Storybook - Angular UI Library no automatic recompile ...
Running storybook outside nx or angular 12 is watching for code changes and rebuilds everything once the code has changed. Inside NX context...
Read more >
Manipulate Angular components with content projection in ...
npx @angular/cli@13.3.0 new ng-content-storybook --style=scss --prefix=evil-corp --strict=true --routing=true. Then we can add the Storybook ...
Read more >
Angular & Storybook. Building & Documenting UI Components
Adding Storybook to an Angular project is pretty straight-forward. First, we run the command below to install Storybook in our project, already ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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