GithubHelp home page GithubHelp logo

storybookjs / addon-styling-webpack Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 3.0 951 KB

Successor to @storybook/addon-styling. Configure the styles of your webpack storybook with ease!

License: MIT License

JavaScript 26.04% TypeScript 73.96%
hacktoberfest hacktoberfest2023

addon-styling-webpack's People

Contributors

jreinhold avatar shaunevening avatar shilman avatar stefanovolpatti avatar tylerlaws0n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

addon-styling-webpack's Issues

[Bug]: Misc issues with the addon

Describe the bug

When adding the addon to an existing Storybook via npx storybook@latest add @storybook/addon-styling-webpack there are a couple of issues that may yield some confusion and inconsistencies when running Storybook with the addon enabled.

Steps to reproduce the behavior

Running npx storybook@latest add @storybook/addon-styling-webpack prompts users with a bit of a misleading message mentioning that there are some uncommitted changes in the local repository and prompts them to continue the process or not. The only actionable item being performed is the install process, which yields a change in the repository state as the required files (i.e., package.json, yarn.lock/package-lock.json and .storybook/main.js|ts) are getting updated accordingly to account for the addon installation as shown below

Styling-addon-install-message-issue

We'll need to tweak the wording so that it's more clear on what's happening.

Additionally, during the installation process, users are prompted to select from a list of available options to aid in the addon's configuration. However, as displayed below, the addon adds a second addon entry to Storybook's configuration file with some configuration (that can be further optimized with some linting). I'm aware that this may be a tricky item to solve, but we should address it at some time in the near future to avoid any unwanted issues that may surface due to this misconfiguration.

workflow-issue-before-css-questions

workflow-issue

Environment

Storybook Environment Info:

  System:
    OS: macOS 13.5.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn <----- active
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.1.1 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 118.0.5993.117
    Edge: 116.0.1938.62
    Safari: 16.6
  npmPackages:
    @storybook/addon-essentials: ^7.5.2 => 7.5.2
    @storybook/addon-interactions: ^7.5.2 => 7.5.2
    @storybook/addon-links: ^7.5.2 => 7.5.2
    @storybook/addon-onboarding: ^1.0.8 => 1.0.8
    @storybook/addon-styling-webpack: ^0.0.5 => 0.0.5
    @storybook/blocks: ^7.5.2 => 7.5.2
    @storybook/preset-create-react-app: ^7.5.2 => 7.5.2
    @storybook/react: ^7.5.2 => 7.5.2
    @storybook/react-webpack5: ^7.5.2 => 7.5.2
    @storybook/testing-library: ^0.2.2 => 0.2.2
    storybook: ^7.5.2 => 7.5.2

Looking forward to hearing your thoughts on this @integrayshaun

Storybook 8 support?

Describe the bug

I just upgraded to storybook 8 and this warning appear
Screenshot 2024-03-13 at 16 35 05

Steps to reproduce the behavior

Just setup a new project with Storybook 8 and install this library.

Expected behavior

Just want to make sure if this library is already support Storybook 8 yet or not.

Screenshots and/or logs

WARN The following packages are incompatible with Storybook 8.0.0 as they depend on different major versions of Storybook packages:
WARN - @storybook/[email protected]

Environment

Storybook Environment Info:

  System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M1
    Shell: 3.6.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 19.3.0 - ~/.nvm/versions/node/v19.3.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.2.0 - ~/.nvm/versions/node/v19.3.0/bin/npm
    pnpm: 8.6.1 - /opt/homebrew/bin/pnpm <----- active
  Browsers:
    Chrome: 122.0.6261.112
    Safari: 17.4
  npmPackages:
    @storybook/addon-docs: ^8.0.0 => 8.0.0
    @storybook/addon-essentials: ^8.0.0 => 8.0.0
    @storybook/addon-links: ^8.0.0 => 8.0.0
    @storybook/addon-styling-webpack: ^0.0.6 => 0.0.6
    @storybook/manager-api: ^8.0.0 => 8.0.0
    @storybook/nextjs: ^8.0.0 => 8.0.0
    @storybook/react: ^8.0.0 => 8.0.0
    @storybook/storybook-deployer: ^2.8.16 => 2.8.16
    @storybook/theming: ^8.0.0 => 8.0.0
    storybook: ^8.0.0 => 8.0.0
    storybook-addon-apollo-client: ^5.0.0 => 5.0.0

Autorelease is failing

Describe the bug

It looks like y'all attempted to release a version compatible with Storybook 8, but the release job failed. It's been long enough that I'm guessing no one noticed :)

Steps to reproduce the behavior

n/a

Expected behavior

Version 1.0 was released

Screenshots and/or logs

Version 1.0 was not released

Environment

n/a

Additional context

n/a

Replace addon-styling-webpack with webpack for scss and sass

First of all, thanks a lot for building @storybook/addon-styling and @storybook/addon-styling-webpack! The first one worked well for me for a long time. Since it was deprecated, the new one gave me helpful insights on how to use scss in the storybook without extra addons.
I hope that in the future such workarounds won't be required.

Summary

The addon doesn't work for me given the instructions provided in README. For anyone faced the same issue I'd like to suggest an alternative approach.

Solution

Use webpack directly instead. Add the snippet below to the root of your config in main.js or main.ts:

webpackFinal: async (config, { configType }) => {
    config.module.rules.push({
      test: /\.s[ac]ss$/i,
      use: [
        'style-loader',
        {
          loader: 'css-loader',
          options: {
            importLoaders: 2,
          },
        },
        {
          loader: 'sass-loader',
          options: {
            sourceMap: true,
            sassOptions: {
              implementation: 'sass',
            },
          },
        },
      ],
    });
    return config;
  },

You might also want to run npm i -D sass sass-loader css-loader style-loader.

Make sure to completely delete @storybook/addon-styling and @storybook/addon-styling-webpack from addons and the package.json file!

[Bug] Error when using the plugin in combination with Angular component styleUrls

Hi, I'm having a Storybook setup for a project in Nx, based on Angular. This library is containing components and global styling. I want to load color variables into one of my stories from the global styling files. I have setup the plugin to bundle my scss files and I'm able to import correctly my colors into my story.

The issue that I'm having however is that from the moment I configure a styleUrl in one of my components, the stories where I use a component are broken on this piece of Angular code:

if (meta.styles && meta.styles.length) {
    const styleValues = meta.encapsulation == ViewEncapsulation.Emulated ? compileStyles(meta.styles, CONTENT_ATTR, HOST_ATTR) : meta.styles;
    const styleNodes = styleValues.reduce((result, style) => {
      if (style.trim().length > 0) {
        result.push(constantPool.getConstLiteral(literal(style)));
      }
      return result;
    }, []);
    if (styleNodes.length > 0) {
      definitionMap.set('styles', literalArr(styleNodes));
    }
  }

When debugging is see that meta.styles equals this: [undefined], so the trim() will fail.

I'm using version 0.0.4 of @storybook/addon-styling-webpack.

This is how my main.js file is looking like:

const config = {
  stories: [
    '../**/*.stories.@(js|jsx|ts|tsx|mdx)'
  ],
  addons: ['@storybook/addon-essentials', {
    name: '@storybook/addon-styling-webpack',
    options: {
      rules: [{
        test: /\.scss$/,
        sideEffects: true,
        use: [
          require.resolve('style-loader'),
          {
            loader: require.resolve('css-loader'),
            options: {
              // Want to add more CSS Modules options? Read more here: https://github.com/webpack-contrib/css-loader#modules
              modules: {
                auto: true,
              },
              importLoaders: 2,
            },
          },
          require.resolve('resolve-url-loader'),
          {
            loader: require.resolve('sass-loader'),
            options: {
              // Want to add more Sass options? Read more here: https://webpack.js.org/loaders/sass-loader/#options
              implementation: require.resolve('sass'),
              sourceMap: true,
              sassOptions: {},
            },
          },
        ],
      }, ],
    }
  }],
  framework: {
    name: '@storybook/angular',
    options: {
    },
  },
};

[Bug] can't load scss file

in my theme provider i have an import
import breakpoints from "../../sass/variables/_breakpoints.scss";

which has

`$_XXS: 320;
$_XS: 414;
$_XS_SM: 568;
$_SM: 768;
$_SM_MD: 960;
$_MD: 1024;
$_MD_LG: 1280;
$_LG: 1366;
$_XL: 1920;

$XXS: #{$_XXS}px;
$XS: #{$_XS}px;
$XS_SM: #{$_XS_SM}px;
$SM: #{$_SM}px;
$SM_MD: #{$_SM_MD}px;
$MD: #{$_MD}px;
$MD_LG: #{$_MD_LG}px;
$LG: #{$_LG}px;
$XL: #{$_XL}px;

:export {
  XXS: $_XXS;
  XS: $_XS;
  XS_SM: $_XS_SM;
  SM: $_SM;
  SM_MD: $_SM_MD;
  MD: $_MD;
  MD_LG: $_MD_LG;
  LG: $_LG;
  XL: $_XL;
}

when i start storybook i get "Cannot read properties of undefined (reading 'XS')"

Is this addon supposed to fix this or where should i go?

    "sass-loader": "^13.3.2",
    "node-sass": "^6.0.1",
    "postcss": "^8.1.6",



[Bug] pnpm install fails with "No matching version found for @storybook/addon-styling-webpack@^7.3.2"

Describe the bug

Trying to upgrade and just do just this:

# pnpm dlx storybook@latest add @storybook/addon-styling-webpack                                                               
.../share/pnpm/store/v3/tmp/dlx-16529    | +616 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.../share/pnpm/store/v3/tmp/dlx-16529    | Progress: resolved 637, reused 616, downloaded 0, added 616, done
Verifying @storybook/addon-styling-webpack
Installing @storybook/addon-styling-webpack@^7.3.2

An error occurred while installing dependencies:
PNPM error ERR_PNPM_NO_MATCHING_VERSION  No matching version found for @storybook/addon-styling-webpack@^7.3.2

Please check the logfile generated at ./storybook.log for troubleshooting and try again.
/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:54
An error occurred while installing dependencies:`),logger4.log(e.message),new HandledError(e)}}async removeDependencies(options,dependencies){let{skipInstall}=options;if(skipInstall){let{packageJson}=options;dependencies.forEach(dep=>{packageJson.devDependencies&&delete packageJson.devDependencies[dep],packageJson.dependencies&&delete packageJson.dependencies[dep]}),await this.writePackageJson(packageJson)}else try{await this.runRemoveDeps(dependencies)}catch(e){throw logger4.error("An error occurred while removing dependencies."),logger4.log(e.message),new HandledError(e)}}getVersionedPackages(packages){return Promise.all(packages.map(async pkg2=>{let[packageName,packageVersion]=getPackageDetails(pkg2);return`${packageName}@${await this.getVersion(packageName,packageVersion)}`}))}getVersions(...packageNames){return Promise.all(packageNames.map(packageName=>this.getVersion(packageName)))}async getVersion(packageName,constraint){let current;/(@storybook|^sb$|^storybook$)/.test(packageName)&&(current=versions_default[packageName]);let latest;try{latest=await this.latestVersion(packageName,constraint)}catch(e){if(current)return logger4.warn(`
                                                                          ^

HandledError: PNPM error ERR_PNPM_NO_MATCHING_VERSION  No matching version found for @storybook/addon-styling-webpack@^7.3.2

Please check the logfile generated at ./storybook.log for troubleshooting and try again.
    at PNPMProxy.addDependencies (/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:54:75)
    at async add (/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:127:1955) {
  handled: true,
  cause: Error: PNPM error ERR_PNPM_NO_MATCHING_VERSION  No matching version found for @storybook/addon-styling-webpack@^7.3.2

  Please check the logfile generated at ./storybook.log for troubleshooting and try again.
      at PNPMProxy.runAddDeps (/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:58:5082)
      at async PNPMProxy.addDependencies (/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:53:853)
      at async add (/Users/ar/.local/share/pnpm/store/v3/tmp/dlx-16529/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:127:1955)
}

Node.js v20.5.1

the logfile mentioned looks like

Progress: resolved 0, reused 1, downloaded 0, added 0
Progress: resolved 86, reused 86, downloaded 0, added 0
 ERR_PNPM_NO_MATCHING_VERSION  No matching version found for @storybook/addon-styling-webpack@^7.3.2

This error happened while installing a direct dependency of /Users/ar/src/lincare/classifier/classifier-gui

The latest release of @storybook/addon-styling-webpack is "0.0.2".

If you need the full list of all 2 published versions run "$ pnpm view @storybook/addon-styling-webpack versions".

Steps to reproduce the behavior

  1. be stupid and run pnpm dlx ...

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots and/or logs

If applicable, add screenshots and/or logs to help explain your problem.

Environment

  • OS: Mac OSX 13.4.1
  • Node.js version: v20.5.1
  • pNPM version: 8.6.12

Additional context

i'm stupid...

Just tried to install this on top of an existing 7.0 installation...

[Bug] `npx storybook@latest add @storybook/addon-styling-webpack` throw and error

Describe the bug

A clear and concise description of what the bug is.

Steps to reproduce the behavior

  1. Go to your storybook project
  2. Execute npx storybook@latest add @storybook/addon-styling-webpack
  3. See error

Expected behavior

Should install addon-styling-webpack and works as expected.

Screenshots and/or logs

Need to install the following packages:
  [email protected]
Ok to proceed? (y) y
Verifying @storybook/addon-styling-webpack
Installing @storybook/addon-styling-webpack@^0.0.3
Adding '@storybook/addon-styling-webpack' to main.js addons field.
Running postinstall script for @storybook/addon-styling-webpack
Error running postinstall script for @storybook/addon-styling-webpack
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:399:5)
    at validateString (node:internal/validators:163:11)
    at normalizeSpawnArguments (node:child_process:545:3)
    at Object.spawn (node:child_process:750:13)
    at t (/Users/javierlopezdeancos/Code/AtomicJar/tcc-web/node_modules/@storybook/addon-styling-webpack/bin/postinstall.js:5:130)
    at postinstallAddon (/Users/javierlopezdeancos/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:172:834)
    at add (/Users/javierlopezdeancos/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:172:2421) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Environment

  • OS: MacOs Ventura 13.4.1
  • Node.js version: v18.16.0
  • NPM version: v9.5.1

Vague read me

I'm not sure what this does or how to use it based on the Reed me.

[Bug]

Describe the bug

In IOS Macbook Pro running Sierra, running the addon-styling-webpack and selecting Less in the configuration results in error immediately upon completion of all the scripts.

All of the default Storybook components (button, header, page) have the same error (below).

Changed button.css to button.less and restarted storybook but problem persists.

ERROR in ./src/stories/page.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[5].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[5].oneOf[5].use[2]!./node_modules/style-loader/dist/cjs.js!./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[9].use[1]!./src/stories/page.css)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError

(2:7) /Users/deborah/Desktop/ufw/ufw-v6 2023/dev/ufw/src/stories/page.css Unknown word

  1 | 
> 2 |       import API from "!../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
    |       ^
  3 |       import domAPI from "!../../node_modules/style-loader/dist/runtime/styleDomAPI.js";
  4 |       import insertFn from "!../../node_modules/style-loader/dist/runtime/insertBySelector.js";
 @ ./src/stories/page.css 8:6-335 22:17-24 26:7-21 52:25-39 53:36-47 53:50-64 57:6-67:7 58:54-65 58:68-82 64:42-53 64:56-70 66:21-28 77:0-305 77:0-305 78:22-29 78:33-47 78:50-64 55:4-68:5
 @ ./src/stories/Page.jsx 7:0-20
 @ ./src/stories/Page.stories.js 4:0-30 7:13-17
 @ ./src/ lazy ^\.\/.*$ include: (?:\/src(?:\/(?%21\.)(?:(?:(?%21(?:^%7C\/)\.).)*?)\/%7C\/%7C$)(?%21\.)(?=.)[^/]*?\.stories\.(js%7Cjsx%7Cmjs%7Cts%7Ctsx))$ chunkName: [request] namespace object ./stories/Page.stories.js ./stories/Page.stories
 @ ./storybook-stories.js 25:11-29:5
 @ ./storybook-config-entry.js 8:0-50 27:21-29 30:2-33:4 30:58-33:3 32:31-39

preview compiled with 3 errors
=> Failed to build the preview
99% end closing watch compilationWARN Force closed preview build
SB_BUILDER-WEBPACK5_0003 (WebpackCompilationError): There were problems when compiling your code with Webpack.
Run Storybook with --debug-webpack for more information.
    at starter (./node_modules/@storybook/builder-webpack5/dist/index.js:1:9660)
    at starter.next (<anonymous>)
    at Module.start (./node_modules/@storybook/builder-webpack5/dist/index.js:1:11692)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

[Bug] Angular workspace - Unable to find storybook main.js config

Describe the bug

A clear and concise description of what the bug is.

Steps to reproduce the behavior

  1. Go to storybook project
  2. Execute npx storybook add @storybook/addon-styling-webpack
  3. See error

Expected behavior

Should install addon-styling-webpack and works as expected.

Screenshots and/or logs

❯ npx storybook add @storybook/addon-styling-webpack
Unable to find storybook main.js config

Environment

  • OS: MacOs Sonoma 14.0
  • Node.js version: v18.16.1
  • NPM version: 9.5.1

Additional context

When I try to add the lib in a Angular Workspace, it cannot find storybook project.

It seems that the feature has not yet been implemented and there is no alternative to use it (such as manually configuring it).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.