jhamlet / svg-react-loader

Webpack SVG to React Component Loader
MIT License
559 stars 82 forks source link

Crash when I pass object query to this loader #15

Closed gbk closed 8 years ago

gbk commented 8 years ago

My webpack config is like this:

{
    test: /\.svg$/,
    loaders: [
        'babel?' + JSON.stringify({
            presets: [
                'es2015',
                'stage-0',
                'react'
            ]
        }),
        'svg-react?' + JSON.stringify({
            attrs: {
                style: {},
                width: 'auto',
                height: 'auto'
            }
        })
    ]
}

I got

Module build failed: SyntaxError: Unexpected identifier
    at Object.module.exports (/home/caoke/git/alinw-tools/nowa-webpack/node_modules/svg-react-loader/index.js:84:46)

at

eval('assign(attrs, ' + params.attrs + ');');

Query string with , will be splited, So I have to use query object. Can you support this ?

jhamlet commented 8 years ago

I think you want to do this:

'svg-react?attrs=' + JSON.stringify({ style: {}, width: 'auto', height: 'auto' })
gbk commented 8 years ago

For example:

xx-loader?a={foo:1,bar:2}

loader-util will parse this query to

{
  "a": "{foo:1",
  "bar:2}": true
}

This result is not we want.

If svg-react-loader can support json query, may fix this issue.

gbk commented 8 years ago

I made a pr.

Please let me know if there are any questions.

jhamlet commented 8 years ago

I made a comment on the PR commit

And, thanks in advance.

jhamlet commented 8 years ago

Fixed with 96e04b8d

Merged to master and revved to npm svg-react-loader@0.3.3.

gbk commented 8 years ago

Thank you :+1: