Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mkdir my-frontend-project
cd my-frontend-project
npm init -y
npm install react react-dom
npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env @babel/preset-react const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
},
};
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
import React from 'react';
import ReactDOM from 'react-dom';
const App = () =>
Hello, world!
;ReactDOM.render(, document.getElementById('root'));
<title>My Frontend Project</title> <script src="bundle.js"></script>npm start
Frontend Setup
Prerequisites
Steps
Set Up Your Development Environment
Initialize Your Project
Install Dependencies
Configure Webpack
webpack.config.js
.Configure Babel
.babelrc
.Create Source Files
src/index.js
.Set Up HTML Template
dist/index.html
.Update
package.json
ScriptsRun Your Project
http://localhost:9000
.const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /.html$/,
use: ['html-loader'],
},
{
test: /.(png|jpe?g|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '[name]-[hash].[ext]',
outputPath: 'images',
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
}),
],
};