Is it possible that we can use JSX as a template engine? #87
Unanswered
mybardaklar
asked this question in
Q&A
Replies: 1 comment 6 replies
-
Hello @mybardaklar,
For example, there is your import React from 'react';
import ReactDOM from 'react-dom';
const App = () => {
return (
<>
<h1>Hello World!</h1>
</>
);
}
ReactDOM.render(<App />, document.getElementById('root')); Then add this <!DOCTYPE html>
<html lang="en">
<head>
<title>The React App</title>
<script src="./index.tsx" defer="defer"></script> <!-- HERE define your main JSX/TSX file -->
<link href="./styles.scss" rel="stylesheet" /> <!-- here you can load source style files -->
</head>
<body>
<div id="root"></div> <!-- HERE will be rendered your JSX file -->
</body>
</html> The webpack config: const path = require('path');
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
module.exports = {
mode: 'production',
output: {
path: path.join(__dirname, 'dist'),
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'], // <= add resolving for the extensions of JSX/TSX files
},
plugins: [
new HtmlBundlerPlugin({
// define HTML templates here
entry: {
index: 'src/index.html', // => dist/index.html
},
}),
],
module: {
rules: [
{
test: /\.(css|scss)$/,
use: ['css-loader', 'sass-loader'],
},
{
test: /\.tsx?$/, // <= define here the rule for tsx files
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
}; See please the working example How to use JSX/TSX files with the Bundler Plugin. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use JSX as template engine. Is it possible? If it is, how to do?
Thank you! ❤
Beta Was this translation helpful? Give feedback.
All reactions