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

Path to webpack config #1641

Closed
motleydev opened this issue Apr 6, 2017 · 16 comments
Closed

Path to webpack config #1641

motleydev opened this issue Apr 6, 2017 · 16 comments

Comments

@motleydev
Copy link
Contributor

I'm incorporating Styleguidist to my app and want to reuse the next.js webpack config. I can define a path to my projects config file but I can't seem to figure out what that would be with next. There are several component documenting libs that need this type of ability - perhaps creating some kind of api for accessing the config object for merging into the styleguidist config file?

@arunoda
Copy link
Contributor

arunoda commented Apr 6, 2017

Use this: https://github.com/zeit/next.js#customizing-webpack-config
With that, you can access our webpack config.

@arunoda arunoda closed this as completed Apr 6, 2017
@motleydev
Copy link
Contributor Author

Hi @arunoda - thanks for the reply! Both here and in Slack. Unfortunately as we discussed there, and as you advised to open an issue here, it doesn't solve the issue.
I need to be able to explicitly import the webpack config so that Styleguidist is able to re-use the settings. It's a separate server process and so things like conf and dev are not available envs.

What I need is to basically have /path/to/config.js

does that make sense?

https://github.com/styleguidist/react-styleguidist/blob/master/docs/Webpack.md#reusing-your-projects-webpack-config

@sapegin
Copy link

sapegin commented Apr 30, 2017

Looks like there’s no config that you can reuse in Styleguidist unless it will be extracted to a separate module.

@motleydev Could you find a workaround?

@motleydev
Copy link
Contributor Author

Yes, recreate the webpack env manually. :) I think there might be a solution hidden in the fact that there's some kind of "parent" function that consumes the next.config.js file and is able to pass the entire config into the webpack function here https://github.com/zeit/next.js/#customizing-webpack-config - but I haven't taken the time to figure it out as I'm attempting to keep my code base as "vanilla" as possible and so recreating the config didn't represent substantial overhead.

@trungdq88
Copy link

Can we reopen this?

@renancouto
Copy link
Contributor

renancouto commented Jul 26, 2017

I was able to get styleguidist running with just this piece of config:

// styleguide.config.js
module.exports = {
    components: './components/**/*.js',
    webpackConfig: {
        module: {
            loaders: [{
                test: /\.js(\?[^?]*)?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    cacheDirectory: true,
                    presets: ['react'],
                },
            }],
        },
    },
};

But when I run styleguide:build I get an error:

Building style guide...

clean-webpack-plugin: .../styleguide/build has been removed.
Failed to compile.
Error in build/bundle.1aa4b834.js from UglifyJs
Unexpected token: punc (}) [build/bundle.1aa4b834.js:6019,31]

Any ideas? @sapegin ?

@sapegin
Copy link

sapegin commented Jul 26, 2017

@renancouto UglifyJS doesn’t support ES6, you need to transpile your JS to ES5.

P. S. What this part of regexp does — (\?[^?]*)?? :-|

@renancouto
Copy link
Contributor

@sapegin not sure, I just copied from next.js webpack config.

@sapegin
Copy link

sapegin commented Jul 26, 2017

I see now — it’s an optional query string, like foo.js?bar=42 ;-)

@renancouto
Copy link
Contributor

renancouto commented Jul 26, 2017

Cool! BTW, adding 'es2015' to query.presets and babel-preset-es2015 as a devDependency works like a charm! Thanks @sapegin for pointing that out.

// styleguide.config.js
module.exports = {
    components: './components/**/*.js',
    webpackConfig: {
        module: {
            loaders: [{
                test: /\.js(\?[^?]*)?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    cacheDirectory: true,
                    presets: ['react', 'es2015'],
                },
            }],
        },
    },
};

Looks like this config is enough to run styleguidist server and styleguidist build.

@sapegin
Copy link

sapegin commented Jul 26, 2017

Or better babel-preset-env with uglify option ;-)

@renancouto
Copy link
Contributor

Ah, even better! Thanks again @sapegin 😉

@billgloff
Copy link

I'm having an issue when trying to incorporate react-styleguidist into a NextJS 3 app:

image

I even used the webpackConfig mentioned above.

Anyone see this before or is there something else I have to do to get it to work? Thanks in advance for the help.

@sapegin
Copy link

sapegin commented Aug 11, 2017

@billgloff Looks like something is overwriting our webpack aliases. I need a repo that I can debug to say more.

@hmontes
Copy link

hmontes commented Aug 18, 2017

So. I need to customize webpack config or not?

A tutorial would be nice. Styleguidist and Storybook are great tools for React Design.

Thank you

@woro83c
Copy link

woro83c commented Aug 20, 2017

The following styleguide.config.js did the trick for me:

module.exports = {
  components: 'components/**/*.js',
  webpackConfig: {
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        }
      ]
    }
  }
};

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants