Git Product home page Git Product logo

Comments (9)

patricklafrance avatar patricklafrance commented on July 17, 2024 4

I know it's been a while but it should work now with the new API.

Documentation available here.

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

Hi @jgoux

craco doesn't return any config.

The way it works is that it make some tweaking according to how craco si setup and then call CRA.

You can try to leverage the plugin system of craco to write a plugin that will output the webpack config somewhere accessible to storybook.

from craco.

jgoux avatar jgoux commented on July 17, 2024

Thanks for your answer @patricklafrance

I wish the ecosystem was more collaborative about webpack's config overwrite.

Project such as https://github.com/andywer/webpack-blocks would be a good start, then craco or storybook's configs could be just a thin layer over this primitive.

Have a nice day! 🌞

from craco.

gajus avatar gajus commented on July 17, 2024

@patricklafrance shouldn't that example be:

/* eslint-disable import/first */

const {
  createWebpackDevConfig,
} = require('@craco/craco');
const cracoConfig = require('../craco.config.js');

module.exports = (webpackConfig) => {
  const config = createWebpackDevConfig({
    ...cracoConfig,
    webpack: {
      configure: webpackConfig.config,
    },
  });

  return config;
};

?

Otherwise you would be just loading the main app webpack config, not Storybook webpack config.

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

Hi @gajus

Did you have problems with the original exemple?

Storybook support "full control mode" for the webpack config so I thought that would be enough. A merge might be necessary.

Not sure about the webpack key in your example though.

Patrick

from craco.

gajus avatar gajus commented on July 17, 2024

I didn't manage to get it working with either your approach or my approach. With your approach webpack was bundling the main application, not Storybook. With my approach I started getting loads of Babel errors (cannot recall what they were now).

I ended up just patching webpack config injected by Storybook:

/* eslint-disable import/first */

module.exports = ({ config }) => {
  const babelLoaderOptions = config.module.rules[0].use[0].options;

  config.module.rules = config.module.rules.filter((rule) => {
    return !(rule.use && rule.use[0].loader && rule.use[0].loader.includes('eslint-loader'));
  });

  // The last rule is the rule added by Storybook to pre-process project files.
  const babelRule = config.module.rules[config.module.rules.length - 1];

  if (!babelRule.loader.includes('babel-loader')) {
    throw new Error('Unexpected state.');
  }

  babelRule.options.plugins = [
    [
      'babel-plugin-styled-components',
      {
        diplayName: true,
      },
    ],
    ...babelRule.options.plugins,
  ];

  config.module.rules.push({
    test: /\.stories\.js?$/,
    loaders: [
      {
        loader: require.resolve('@storybook/addon-storysource/loader'),
        options: {
          parser: 'flow',
        },
      },
    ],
    enforce: 'pre',
  });

  return config;
};

from craco.

patricklafrance avatar patricklafrance commented on July 17, 2024

ok thank you, thank you for your feedback, I will remove the example and revisit it later

from craco.

liokm avatar liokm commented on July 17, 2024

Simply merge seems not work. With the help of preset-create-react-app it could work. I have raised an issue here storybookjs/presets#109

from craco.

danielknell avatar danielknell commented on July 17, 2024

I hit problems with Craco and storybook last night so built an experimental preset based on preset-create-react-app to use the webpack config from Craco instead of pulling it directly from react-scripts.

This means any Craco plugins, changes postcss plugins, manual webpack tweaks, etc will also be applied to storybook.

Its a bit hackey at the moment and calls out to internal apis inside preset-create-react-app but that seemed like a better choice than re-inventing the wheel.

Any feedback, contributions, fixes, etc are welcome, it would be good to have solid integration between storybook and Craco.

from craco.

Related Issues (20)

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.