Docsity

Configuración de Webpack para un proyecto React, Apuntes de Agronomía

Toggle sidebar
bg1
1- Instalamos webpack
npm install --save-dev webpack
npm install --save-dev webpack-cli
2- Crear carpeta de recursos src y crear los archivos index.html y index.js
3- Crear archivo webpack.config.js en la raíz del proyecto
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname + 'dist'),
filename: 'bundle.js'
}
}
4- Modificamos archivo index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viweport" constent="width=device=width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>React Webpack config</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
5- Instalamos el modulo html-webpack-plugin para transpilar código html.
Instalarmos el modulo npm install --save-dev html-webpack-plugin
6- Instalar moduelo webpack-dev-server un servidor de desarrollo
npm install --save-dev webpack-dev-server
7- Instalamos el transpilador de codigo babel
npm install --save-dev @babel/core @babel/cli @babel/preset-env
8- Crear arhcivo de configuracion de babelñ .babelrc
{
"presets": [
"@babel/preset-env"
pf3
pf4

Vista previa parcial del texto

¡Descarga Configuración de Webpack para un proyecto React y más Apuntes en PDF de Agronomía solo en Docsity!

1- Instalamos webpack npm install --save-dev webpack npm install --save-dev webpack-cli 2- Crear carpeta de recursos src y crear los archivos index.html y index.js 3- Crear archivo webpack.config.js en la raíz del proyecto const path = require('path'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname + 'dist'), filename: 'bundle.js' } } 4- Modificamos archivo index.html

React Webpack config

5- Instalamos el modulo html-webpack-plugin para transpilar código html. Instalarmos el modulo npm install --save-dev html-webpack-plugin 6- Instalar moduelo webpack-dev-server un servidor de desarrollo npm install --save-dev webpack-dev-server 7- Instalamos el transpilador de codigo babel npm install --save-dev @babel/core @babel/cli @babel/preset-env 8- Crear arhcivo de configuracion de babelñ .babelrc { "presets": [ "@babel/preset-env"

]

9- Modificar archivo webpack.config.js const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname , 'dist'), filename: 'bundle.js' }, devServer: { port: 4000 }, resolve: { extensions: ['.js','.jsx'] }, module: { rules: [ { test: /.(js|jsx)$/, use: ['babel-loader'], exclude: /node_modules/ } ] }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html' }) ] } 10- Instalar React npm i react react-dom --save 11- Modificar achivo index.js import React from 'react'; import { render } from 'react-dom'; render(

npm install redux-thunk npm i --save redux-logger npm install --save redux npm install –-save react-redux npm i jsx-control-statements npm install --save-dev babel-plugin-jsx-control-statements