Site icon port135.com

How to add JavaScript pages to React Core Boilerplate template?

If you use a Visual Studio template that comes with TypeScript by default, you may need to extend the capability of it to use JavaScript. In this post, we will learn how to add JavaScript pages to React Core Boilerplate template.

React is a JavaScript library that is developed by Facebook and used by developers to create interactive user interfaces. It updates and render only the specific components on your page when the data changes.

React Core Boilerplate is a Visual Studio template that helps developers to easily embed and use React in their web applications.

Add JavaScript pages to React Core Boilerplate template

React Core Boilerplate template automatically creates TypeScript files (.tsx extension) for application logic. Therefore, you need to put some extra effort to enable this template to render JavaScript files.

How a JavaScript page looks in Visual Studio’s React Core Boilerplate

Follow the steps below to add JavaScript files to React Core Boilerplate template:

import React, { Component } from 'react';
 
export default class Home extends Component {
    render() {
        return (
            

Hello, world! (JS Page)

Welcome to your new single-page application

); } }
import Home from '@Pages/Home.js';
<approute layout="{AuthorizedLayout}" exact="" path="/test" component="{Home}"></approute>
module: {
	rules: [
		{ test: /\.tsx?$/, include: /ClientApp/, use: ['babel-loader', 'ts-loader', 'ts-nameof-loader'] },
		{
			test: /\.(gif|png|jpe?g|svg)$/i,
			use: [
				'file-loader',
				{
					loader: 'image-webpack-loader'
				}
			]
		}, 
		{ test: /\.js?$/, include: /ClientApp/, use: ['babel-loader'] }
	]
},
npm install @babel/preset-env
npm install @babel/preset-react
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ]
}

Looking for steps to publish ASP.NET web site in Visual Studio and deploy it in IIS? Check this post out.

References

Exit mobile version