Transform prefixed strings into imports. Works with babel 6/7.
To allow .jsx
to have the equivalent of vue-loader
'stransformAssetUrls
,
so we can use <Icon name="~image.jpg"/>
in jsx too, as the same in .vue
.
var a = '~iconName'
function foo() {
return <icon name="~iconName"/>
}
import _iconName from 'iconName';
var a = _iconName;
function foo() {
return <icon name={_iconName} />;
}
and then let webpack handle import _iconName from 'iconName';
$ npm install babel-plugin-transform-string-to-import
.babelrc
{
"plugins": ["transform-string-to-import"]
}
$ babel --plugins transform-string-to-import script.js
require("babel-core").transform("code", {
plugins: ["transform-string-to-import"]
});
string
, defaults to '~'
The prefix of the strings to transform