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

Viewport Addon: Custom Viewports Do Not Build #10291

Closed
jdiponziano opened this issue Apr 2, 2020 · 2 comments
Closed

Viewport Addon: Custom Viewports Do Not Build #10291

jdiponziano opened this issue Apr 2, 2020 · 2 comments

Comments

@jdiponziano
Copy link

Describe the bug
I built an app using create-react-app. I create custom viewport types to add to my storybook. When I use yarn start everything builds fine and works. But when I build the app the viewports that I globally defined my preview.js file are not loading on the build. It is still the defaults. And for the life of me I can't figure out why. As far as I can tell I set it up the way the documentation explains.

This is my preview.js file

import { configure, addDecorator, addParameters } from '@storybook/react';
import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks';
import { withA11y } from '@storybook/addon-a11y';
import { GlobalStyle } from '../src/styles/global-styles';

const loaderFn = () => {
  const allExports = [];
  const styles = require.context('../src/styles', true, /\.stories\.(js|mdx)$/);
  const req = require.context('../src/components', true, /\.stories\.(js|mdx)$/);
  addDecorator(withA11y, GlobalStyle);
  styles.keys().forEach(fname => allExports.push(styles(fname)));
  req.keys().forEach(fname => allExports.push(req(fname)));
  return allExports;
};

const customViewports = {
  phoneSmall: {
    name: 'Phone (320px min width)',
    styles: {
      width: '320px',
      height: '667px',
    },
  },
  tabletSmall: {
    name: 'Tablet Small & Portrait (600px min width)',
    styles: {
      width: '600px',
      height: '801px',
    },
  },
  tabletLarge: {
    name: 'Tablet Large & Landscape (960px min width)',
    styles: {
      width: '960px',
      height: '768px',
    },
  },
  desktop: {
    name: 'Desktop (1200px min width)',
    styles: {
      width: '1200px',
      height: '1024px',
    },
  },
};

configure(loaderFn, module);
 
addParameters({
  docs: {
    container: DocsContainer,
    page: DocsPage,
  },
  viewport: { viewports: customViewports },
});

My main.js file

module.exports = {
  stories: ['../src/**/*.stories.(js|mdx)'],
  addons: [
    '@storybook/preset-create-react-app',
    '@storybook/addon-knobs/',
    '@storybook/addon-actions',
    '@storybook/addon-links',
    '@storybook/addon-notes',
    '@storybook/addon-storysource',
    '@storybook/addon-a11y',
    '@storybook/addon-docs',
    '@storybook/addon-viewport',
  ]
}

Package.json

{
  "name": "tamman-ui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@storybook/addon-a11y": "^5.3.17",
    "@storybook/addon-actions": "^5.3.17",
    "@storybook/addon-docs": "^5.3.17",
    "@storybook/addon-knobs": "^5.3.17",
    "@storybook/addon-links": "^5.3.17",
    "@storybook/addon-notes": "^5.3.17",
    "@storybook/addon-storyshots-puppeteer": "^5.3.17",
    "@storybook/addon-storysource": "^5.3.17",
    "@storybook/addon-viewport": "^5.3.17",
    "@storybook/addons": "^5.3.17",
    "@storybook/preset-create-react-app": "^2.1.0",
    "@storybook/react": "^5.3.17",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "autoprefixer": "^9.7.5",
    "camel-case": "^4.1.1",
    "core-js": "^3.6.4",
    "del": "^5.1.0",
    "fs": "^0.0.1-security",
    "node-sass": "^4.13.1",
    "pascal-case": "^3.1.1",
    "path": "^0.12.7",
    "prop-types": "^15.7.2",
    "puppeteer": "^2.1.1",
    "react": "^16.12.0",
    "react-dom": "^16.13.1",
    "react-scripts": "^3.4.1",
    "styled-components": "^5.0.1",
    "xml2js": "^0.4.23"
  },
  "scripts": {
    "start": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts start",
    "build-page": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "storybook": "start-storybook -p 9009 -s public",
    "build": "yarn build-page && build-storybook -o build/storybook"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "homepage": ".",
  "browserslist": [
    "since 2010"
  ],
  "devDependencies": {
    "babel-loader": "^8.1.0",
    "react-is": "^16.12.0"
  }
}

System:
System:
OS: macOS Mojave 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.7 - ~/.nvm/versions/node/v12.13.0/bin/npm
Browsers:
Chrome: 80.0.3987.149
Firefox: 74.0
Safari: 12.1.1
npmPackages:
@storybook/addon-a11y: ^5.3.17 => 5.3.17
@storybook/addon-actions: ^5.3.17 => 5.3.17
@storybook/addon-docs: ^5.3.17 => 5.3.17
@storybook/addon-knobs: ^5.3.17 => 5.3.17
@storybook/addon-links: ^5.3.17 => 5.3.17
@storybook/addon-notes: ^5.3.17 => 5.3.17
@storybook/addon-storyshots-puppeteer: ^5.3.17 => 5.3.17
@storybook/addon-storysource: ^5.3.17 => 5.3.17
@storybook/addon-viewport: ^5.3.17 => 5.3.18
@storybook/addons: ^5.3.17 => 5.3.17
@storybook/preset-create-react-app: ^2.1.0 => 2.1.0
@storybook/react: ^5.3.17 => 5.3.17

@shilman
Copy link
Member

shilman commented Apr 3, 2020

Try moving your addParameters code before configure.

Also, unrelated but I recommend moving to the main.js configuration: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#to-mainjs-configuration

@jdiponziano
Copy link
Author

Thank you so much @shilman ! Feel so stupid it was so simple lol!

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

2 participants