Docz: Using Custom Webpack Config and react-svg-loader

Created on 2 Apr 2019  路  4Comments  路  Source: doczjs/docz

Question

Using Custom Webpack with react-svg-loader
I have setup a doczrc.js and added my module aliases, but now I am running into an error where I am using react-svg-loader to load SVG files setup with my existing webpack.

I have tried to add my loader rule that I have in my webpack.config.js for SVGs but it still causes an error.

doczrc.js extract:

  [
      {
        loader: 'babel-loader',
      },
      {
        loader: 'react-svg-loader',
        options: {
          jsx: true,
        },
      },
    ]

My first attempt was to config.module.rules.push, and then I tried replacing the use part in the existing config.module.rules that was testing for SVGs.

Neither seems to solve the issue. So I am struggling to resolve this. I'm open to suggestions.

image

Most helpful comment

I will try a few things and see if I can resolve this.

Will post back here when I find the solution.

All 4 comments

Try to use onCreateWebpackChain method instead of modifyBundler, can be easy to do that:

export default {
  onCreateWebpackChain: config => {
    config.module
      .rule('js')
      .use('svg-loader')
        .loader('react-svg-loader')
        .options({ jsx: true })
  }
}

Thanks, that seems to now use the react-svg-loaderbut the SVG file going through that loader is now causing an error:
image

Perhaps it's conflicting with the existing loader.

I will try a few things and see if I can resolve this.

Will post back here when I find the solution.

Just reporting back, seems like I couldn't use react-svg-loader but instead I replaced the file-loader in the webpack config as in this issue https://github.com/pedronauck/docz/issues/169 and that fixed all my errors 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bichotll picture bichotll  路  3Comments

capaj picture capaj  路  3Comments

YardWill picture YardWill  路  3Comments

danburzo picture danburzo  路  3Comments

ilyanoskov picture ilyanoskov  路  3Comments