Last active
May 11, 2017 00:49
-
-
Save shisama/23fd4fcb66197cdc8f22444679077a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import svg from "./sample.svg"; | |
export default class Sample extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
return ( | |
<div> | |
<span className="logo" dangerouslySetInnerHTML={{__hrml: svg}} /> | |
</div> | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
entry: entries, | |
output: { | |
path: dst, | |
filename: '[name].bundle.js' | |
}, | |
resolve: { | |
root: [path.resolve('./vlsn/js')], | |
extensions: ['', '.js', '.jsx', '.es6'] | |
}, | |
plugins: [], | |
module: { | |
loaders: [ | |
{ | |
test: /\.(js|jsx|es6)$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/, | |
query: { | |
plugins: ["transform-class-properties"] | |
} | |
}, | |
{ | |
test: /\.css?$/, | |
loaders: ['style-loader', 'css-loader?modules&localIdentName=[path][name]__[local]--[hash:base64:5]'] | |
}, | |
{ | |
test: /\.svg$/, | |
loader: 'svg-inline-loader?classPrefix' | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
svgファイルをReactコンポーネント化してもいいのですが、面倒くさい場合とかに有効そう。
imgタグで読み込んでもいいけど、jsに入れ込みたい需要はどこかでありそう。
肝はwebpackのloaderでsvg-inline-loaderを呼んでいるところ。
これでcss-modulesみたいにsvgをimportすることができるようになる
でも、このやりかただとstorybookでは正しく表示されなかった。
innderHTMLだからかな・・・