write react in single file with webpack
- combine jsx and css in single file
- support less,sass
- support style scoped
//about.react
<script>
var About = ()=>{
return (
<div className='container'>
about
</div>
)
}
export default About;
</script>
<style>
.container{
color:red;
}
</style>
1.install the single-react-loader package with npm
npm install single-react-loader
2.config your webpack
//webpack.config.js
module: {
loaders: [
{
test: /\.react$/,
exclude: /node_modules/,
loader: 'single-react'
}
]
}
//webpack.config.js
module: {
rules: [
{
test: /\.react$/,
exclude: /node_modules/,
loader: 'single-react-loader'
}
]
}
3.write single file react,and import
import About from 'About.react'
// app.react
<script>
...
</script>
<style lang="sass(or less)">
...
</style>
// app.react
<script>
...
</script>
<style scoped>
...
</style>
Place the following snippet into your settings file.
{
"files.associations": {
"*.react": "html"
}
}
- open
*.react
file - click view-->syntax-->open all with current extension as.. --> HTML
1.support sourceMap
2.support style scope
And then i will write plugin with common editor such as sublime
for code snnipets and highlight
You can contact me if you have any idea.You also can join us to help single-react stronger.