babel-plugin-inline-react-svg icon indicating copy to clipboard operation
babel-plugin-inline-react-svg copied to clipboard

Support passing an alias object to fix issues with babel module resolver

Open Zaggen opened this issue 8 years ago • 12 comments
trafficstars

Given a .babelrc like this

{
  "presets": ["next/babel"],
  "plugins": [
    ["inline-react-svg", {
      "root": "./",
      "alias": {
        "svgs": "svgs"
       }
    }],
   ["module-resolver", {
     "root": ["./"],
     "alias": {
       "svgs": "svgs"
      }
  }]
 ]
}

Supports basically the same syntax as module-resolver but root has to be a string not an array

Closes #14

Let me know what do you think

Zaggen avatar Jul 03 '17 01:07 Zaggen

This one need to be merged @kesne

rohmanhm avatar Jul 12 '17 09:07 rohmanhm

@kesne Would it be possible to get this merged. Thanks!

qualitydixon avatar Sep 21 '17 15:09 qualitydixon

@Zaggen This looks great, any chance you can rebase on master?

kesne avatar Sep 26 '17 17:09 kesne

@kesne Did a rebase, but I din't get a chance to properly check if it doesn't break the functionality, I'll make the changes with the root property as soon as I have time and then you can confirm if everything is ok

Zaggen avatar Sep 26 '17 21:09 Zaggen

Anything I can do to help move this PR along? Seems like there hasn't been any activity in a while but the functionality seems super useful.

hibachrach avatar Nov 08 '19 07:11 hibachrach

I've got a working branch based on this PR, just haven't gotten around to submitting it. https://github.com/OscarBarrett/babel-plugin-inline-react-svg/tree/feature/resolve

With an example config being

['babel-plugin-inline-react-svg', {
  root: path.resolve(__dirname, 'src'),
  alias: {
    images: 'images'
  }
}],

IIRC resolve and resolveFrom didn't seem to work properly so in my branch I switched to path's version.

OscarBarrett avatar Nov 08 '19 09:11 OscarBarrett

@OscarBarrett Could you delivery package since airbnb is sleeping

You can bypass the problem in typescript by reexporting

import AppStore from '../static/appstore.svg' export { AppStore }

then just import {AppStore} from 'styles'

HelloMyDevWorld avatar Mar 12 '20 11:03 HelloMyDevWorld

@patsadow2 nobody's "sleeping".

ljharb avatar Mar 12 '20 17:03 ljharb

I've pulled in @OscarBarrett's rebased branch. This will still need tests.

ljharb avatar Mar 12 '20 17:03 ljharb

Hi guys, as of now, a nextjs project with svg, absolute path and Typescript cant import a svg like import Logo from '~/assets/Logo.svg' and it looks like this PR tried to solve it.

Is this still happening?

ghost avatar Apr 28 '21 20:04 ghost

when it will be merged?

vavilondev avatar Oct 18 '22 04:10 vavilondev

@vavilondev when someone posts a link to a branch that contains tests.

ljharb avatar Oct 18 '22 04:10 ljharb