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

Changing loaders #256

Closed
2 of 4 tasks
TimonVS opened this issue Feb 2, 2017 · 11 comments
Closed
2 of 4 tasks

Changing loaders #256

TimonVS opened this issue Feb 2, 2017 · 11 comments

Comments

@TimonVS
Copy link

TimonVS commented Feb 2, 2017

This issue is a:

  • Bug report
  • Feature request
  • Question / support request
  • Other

I want to change the loaders used for SVG images. Basically I want to SVG's to be inlined, so that I can change the fill color etc.
Am I correct in assuming that it isn't possible right now?

module.exports = () => {
  return {
    type: 'react-app',
    webpack: {
      rules: {
        svg: {
          use: ['svg-inline-loader?classPrefix, image-webpack-loader'] // <-- this doesn't work
        }
      },
      extra: {
        resolve: {
          modules: [path.resolve(__dirname, 'src'), 'node_modules']
        },
        module: {
          rules: [
            {
              // This will add the rule as the last entry in the Webpack config, but doesn't do anything
              // It doesn't overwrite the current rule for svg :(
              test: /\.svg$/,
              use: ['svg-inline-loader?classPrefix, image-webpack-loader']
            }
          ]
        }
      }
    }
  }
}
@insin
Copy link
Owner

insin commented Feb 2, 2017

This isn't supported at the moment - adding support for replacing the default loader with your own loader or use config seems like a nice way to go, which should make your first attempt using webpack.rules.svg work.


Something else I've been keeping for when someone asks for config which can't be made declarative is passing the generated config to a function to allow you to manuallymake whichever changes you want. Combined with allowing default rules to be disabled by passing false, this would look like:

module.exports = {
  webpack: {
    rules: {
      svg: false
    },
    config(config) {
      config.module.rules.push({...})
    }
  }
}

@insin
Copy link
Owner

insin commented Feb 2, 2017

On second thoughts you might be able to override the loader config for the default .svg rule, but I'm not sure what Webpack will do with the default options configured for url-loader.

module.exports = {
  webpack: {
    rules: {
      svg: {
        loader: 'svg-inline-loader?classPrefix!image-webpack-loader'
      }
    }
  }
}

I'm still going to add support for replacing loader with your own loader (dropping the default options/using yours instead) or use config, though.

@TimonVS
Copy link
Author

TimonVS commented Feb 2, 2017

I tried that, but instead of overriding the loader it gets merged in the options.

https://i.imgur.com/uE6mv46.png

@TimonVS
Copy link
Author

TimonVS commented Feb 2, 2017

Do you have a timeframe for when support will be added? I'm willing to help.

@insin insin added the bug label Feb 2, 2017
@insin
Copy link
Owner

insin commented Feb 2, 2017

That's a bug right there.

Quick workaround which will also work after I fix this - add an empty options object to your svg config. The code which moves top-level options into an options object for you (causing this bug, as it's not excluding loader) won't run then.

I have a bunch of free time coming up in about 7 hours, so will be able to tackle upgrading to use config then. I'm in the middle of a major refactor this might get in the way of, so looking to knock this change out quickly.

insin added a commit that referenced this issue Feb 2, 2017
- Don't move `loader` config into an `options` object
- Validate that rule `use` config is an Array
- Add a `path` property to user config when sucessfully loaded
- Default rules can now be disabled by configuring them as false
- Default rule loader and options are now omitted if you configure `loader` or `use`
- Add a separate factory for loaders, which only handles loader+options
- Add support for a webpack.config() function which receives the generated config to be edited and returned.
insin added a commit that referenced this issue Feb 6, 2017
- Don't move `loader` config into an `options` object
- Validate that rule `use` config is an Array
- Add a `path` property to user config when sucessfully loaded
- Default rules can now be disabled by configuring them as false
- Default rule loader and options are now omitted if you configure `loader` or `use`
- Add a separate factory for loaders, which only handles loader+options
- Add support for a webpack.config() function which receives the generated config to be edited and returned.
@mikkelwf
Copy link

mikkelwf commented Feb 9, 2017

Any eta on release..?

@insin
Copy link
Owner

insin commented Feb 9, 2017

The next release will be after #223 lands.

@mikkelwf
Copy link

mikkelwf commented Feb 9, 2017

Ok..

i'm struggling with getting svg's to load inline, it doesn't seem to work with the current setup..

insin added a commit that referenced this issue Feb 14, 2017
- Don't move `loader` config into an `options` object
- Validate that rule `use` config is an Array
- Add a `path` property to user config when sucessfully loaded
- Default rules can now be disabled by configuring them as false
- Default rule loader and options are now omitted if you configure `loader` or `use`
- Add a separate factory for loaders, which only handles loader+options
- Add support for a webpack.config() function which receives the generated config to be edited and returned.
@kabriel
Copy link

kabriel commented Mar 21, 2017

+1 I would also like to change the loader used for svg.

@ekwonye-richard
Copy link

ekwonye-richard commented May 7, 2017

I have a workaround which worked out for me. I included the loader inside my component.

<span dangerouslySetInnerHTML={{__html: require('!svg-inline-loader!./svg/icon.svg')}} />

insin added a commit that referenced this issue May 18, 2017
- Don't move `loader` config into an `options` object
- Validate that rule `use` config is an Array
- Add a `path` property to user config when sucessfully loaded
- Default rules can now be disabled by configuring them as false
- Default rule loader and options are now omitted if you configure `loader` or `use`
- Add a separate factory for loaders, which only handles loader+options
- Add support for a webpack.config() function which receives the generated config to be edited and returned.
@insin
Copy link
Owner

insin commented May 30, 2017

Fixed in v0.16

@insin insin closed this as completed May 30, 2017
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

5 participants