Replies: 3 comments 4 replies
-
First, follow the steps described in the removing Vue section. Then the excerpt from an older README, that should get you started: React
npm$ npm install react react-dom
$ npm install @babel/preset-react --save-dev yarn$ yarn add react react-dom
$ yarn add @babel/preset-react --dev
...
resolve: {
extensions: [... '.jsx'] // add jsx to extensions array
}
... ...
module: {
rules: [
// add babel-loader for jsx,
// remove the same loader from webpack.prod.js
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [ '@babel/preset-env', '@babel/preset-react' ]
}
},
...
]
}
...
...
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: { // add ecmaFeatures
jsx: true,
modules: true
}
}
...
// eslint-disable-next-line
import React from 'react'
import { render } from 'react-dom'
/**
* react components
* auto-map all react components to dom elements
*/
const reactComponents = require.context('./react/components/', true, /\.(jsx|js)$/)
reactComponents.keys().forEach(key => {
const Component = reactComponents(key).default
// transform file name to PascalCase
const name = key.replace(/\.(\/|jsx|js)/g, '').replace(/(\/|-|_|\s)\w/g, (match) => match.slice(1).toUpperCase())
const domElement = document.querySelector(`[react-component='${name}']`)
render(<Component/>, domElement)
})
import React from 'react'
class MyComponent extends React.Component {
render() {
return(
<div>
My Component
</div>
)
}
}
export default MyComponent
<div react-component="MyComponent"></div> |
Beta Was this translation helpful? Give feedback.
-
This doesn't actually transform the filename to PascalCase as it doesn't transform the first character. I ended up using
to enforce pascal case. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the react version, do you have any ideas to pass the props? |
Beta Was this translation helpful? Give feedback.
-
I’ve been looking for something like this for a while, extremely excited to start using it.
I personally prefer React over Vue, so I would love if someone had or knew of an example they could share using a React implementation.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions