Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
How can I add modules in node install modules under node_modules to browser?

I am basically starting out with React and I am following on from this tutorial https://reactjs.org/docs/hello-world.html and Getting started guide to React https://reactjs.org/docs/add-react-to-a-website.html.

My template now looks like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HTML 5 Boilerplate</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id="root"></div>

    <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
       ReactDOM.render(<h1>Hello, world!</h1>, document.getElementById('root')
); 
    </script>
  </body>
</html>

This works but some packages I would like to try out don't have CDNs to load them from. Specifically https://www.draftail.org/docs/getting-started.

Do I have to set up a node enviroment next with npm init -y and then npm install --save draftail draft-js@0.10.5 react react-dom ? But I already have react install through the CDN so what should I be doing now as I have no idea if these packages will conflict or not.

How can I bring something installed in node_modules into the browser at this point along with CSS files?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

If the package doesn't exist in a format for immediate browser consumption, the right approach is to build your app from Node so that you can import the package and use it.

You will have to remove all of these script tags:

    <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
       ReactDOM.render(<h1>Hello, world!</h1>, document.getElementById('root')
); 
    </script>

Instead, once your Node project is set up, use Webpack (or whatever bundler you're using)'s bundled output script and host it on your site. It'll probably look something along the lines of

<script src="bundle.js"></script>

Transitioning to a Node-based project has other benefits as well:

  • All the transpiling work will now be done once for each build, on the server, instead of every time a client loads the page
  • It's easy to set up the build process to automatically minify the code sent to the client, so as to reduce bandwidth requirements
  • You can also easily require polyfills as well

Note that create-react-app is a great starting boilerplate for a React project - just install it and you won't really have to mess with much of the setup at all, you'll be able to just start writing the code you want.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda