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

Rename file to JSX before passing it to the next loader #2

Closed
fregante opened this issue Dec 7, 2019 · 2 comments
Closed

Rename file to JSX before passing it to the next loader #2

fregante opened this issue Dec 7, 2019 · 2 comments

Comments

@fregante
Copy link

fregante commented Dec 7, 2019

Thank you for this loader! It seems to work but some loaders won't recognize a JSX file with an SVG extension and end up not parsing it (example: microsoft/TypeScript#10939)

Would it be possible for this loader to rename the file from .svg to .jsx so that loaders down the line automatically recognize it correctly?

@frenzzy
Copy link
Owner

frenzzy commented Dec 9, 2019

You can apply as many loaders as you need per a specific file extension like this:

// webpack.config.js
{
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: [
          { loader: 'third-loader' }, // apply this loader after:
          { loader: 'seond-loader' }, // apply this loader after:
          { loader: 'svg-to-jsx-loader' }
        ]
      }
    ]
  }
}

Also I suggest to use babel-plugin-inline-react-svg or similar solution instead of webpack loaders.
(I am considering to deprecate this package in favor of Babel plugin)

@fregante
Copy link
Author

fregante commented Dec 9, 2019

Thank you for your reply!

Indeed I can inline them but TypeScript still refuses to do anything with it.

I don’t have Babel in my pipeline and I’d rather keep it off since TypeScript does all of the work now.

In this case I ended up using buble-loader to load the SVG straight into React.createElement calls (faster than Babel) and a micro loader to add export default in front of it, completely bypassing both TypeScript and this loader.

@fregante fregante closed this as completed Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants