Code Monkey home page Code Monkey logo

4ga-pruebas-fetch's Introduction

  1. Inicializamos un proyecto.

    npm init -y
  2. Instalamos las dependencias.

    npm install --save-dev webpack webpack-cli
    npm i -D webpack webpack-cli
  3. Añadimos nuestro fichero de configuración webpack.config.js.

    var path = require('path');
    
    module.exports = {
      entry: './src/main.js',
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.bundle.js'
      }
    };
  4. Creamos nuestro fichero de entrada main.js dentro del directorio src

    window.load = function() {
        console.log('Hello world')
    }
  5. Añadimos el comando build a nuestro proyecto en el fichero package.json en la sección scripts.

    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "build": "webpack"
    },
  6. Ejecutamos el comando para comprobar que funciona correctamente. Deberia generar el fichero main.bundle.js en el directorio dist

    npm run build
  7. Instalamos dependenciar para incluir ficheros css.

    npm install --save-dev style-loader css-loader 
    npm i -D style-loader css-loader 
  8. Actualizamos la configuración de webpack en el fichero webpack.config.js.

    var path = require('path');
    
    module.exports = {
      entry: './src/main.js',
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.bundle.js'
      },
      module: {
          rules: [{
            test: /\.css$/,
            use: [ 'style-loader', 'css-loader' ]
        }]
      }
    };
  9. Creamos la hoja de estilos style.css en el directorio src

    body {
        background-color: red;
    }
  10. Incluimos el fichero style.css en el fichero main.js

    require('./style.css')
  11. Ejecutamos de nuevo el comando para paquetizar nuestro proyecto.

    npm run build
  12. Instalamos nuestro primer plugin para nuestra página de entrada.

    npm install --save-dev html-webpack-plugin
    npm i -D html-webpack-plugin
  13. Actualizamos la configuración de webpack en el fichero webpack.config.js.

    var path = require('path');
    
    var HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = {
      entry: './src/main.js',
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.bundle.js'
      },
      module: {
          rules: [{
            test: /\.css$/,
            use: [ 'style-loader', 'css-loader' ]
        }]
      },
      plugins: [new HtmlWebpackPlugin({template: 'src/index.html'})]
    };
  14. Creamos nuestro primer documento index.html en el directorio src.

    <!DOCTYPE html>
    
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <title>Webpack</title>
      </head>
      <body>
        <h1>Webpack</h1>
      </body>
    </html>
  15. Ejecutamos de nuevo el comando para paquetizar nuestro proyecto.

    npm run build
  16. Arrancamos un servidor para visualizar nuestra página.

    python -m http.server 3000 --directory ./dist
  17. Instalamos un servidor para desarrollo.

    npm install --save-dev webpack-dev-server
    npm i -D webpack-dev-server
  18. Añadimos el comando develop a nuestro proyecto en el fichero package.json en la sección scripts.

    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "build": "webpack",
      "develop": "webpack-dev-server --mode development --port 3000"
    }
  19. Ejecutamos el comando develop.

    npm run develop
  20. Creamos un fichero .gitignore para evitar subir ficheros innecesarios al repositorio.

    dist
    node_modules
    
  21. Subimos los cambios a nuestro repositorio.

    git add .
    git commit -m "Initial commit"
    git push origin master
  22. Instalamos babel

    npm i -D @babel/core @babel/preset-react babel-loader
  23. Actualizamos la configuración de webpack en el fichero webpack.config.js.

    var path = require('path');
    
    var HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = {
        mode: 'development',
        entry: './src/main.js',
        output: {
            path: path.resolve(__dirname, 'dist'),
            filename: 'main.bundle.js'
        },
        module: {
            rules: [{
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-react']
                    }
                }
            }, {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            }]
        },
        plugins: [new HtmlWebpackPlugin({ template: 'src/index.html' })]
    };
  24. Instalamos React.

    npm install react react-dom
    npm i react react-dom
  25. Instalamos Boostrap, jQuery y popper.js.

    npm install bootstrap jquery popper.js
    npm i bootstrap jquery popper.js
  26. Añadimos bootstrap en nuestro fichero main.js

    import "bootstrap";
  27. Añadimos bootstrap en nuestro fichero style.css

    @import "~bootstrap/dist/css/bootstrap.min.css";
  28. Instalamos React Router.

    npm install react-router-dom
    npm i react-router-dom

4ga-pruebas-fetch's People

Contributors

aredondovilla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.