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

108
Visualizações
How can I create a build from a JavaScript file based on node modules?

I created a new node project using

npm init
npm install apollo-server

I then added a index.js file with the following code:

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const server = new ApolloServer({
  typeDefs,
  mocks: true,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`)
});

While I can run this with node index.js, how could I actually create a build from my index.js so it doesn't directly need the modules during runtime? (goal: deploy it on platforms like e.g. render.com)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It sounds like you want to create a single executable artifact which requires no server-side configuration or setup to run.

There are a few options for this. You're probably looking for a Javascript bundler, like Rollup, Parcel or Webpack. Webpack is the most widely used, but also generally the most difficult to configure.

Using bundlers

Parcel

Install Parcel with npm i -g parcel, then, add this to your package.json:

  "main": "dist/index.js",
  "targets": {
    "main": {
      "includeNodeModules": true
    },
  },

Then run parcel build index.js. That's it!

I've added a simple demo on GitHub.

Webpack

There are a number of great answers on this SO question.

Bundler caveats

Many node packages come with binary/native addons. For example, Cypress downloads and installs a browser. Any package which uses native addons will not work with a bundler, as the bundler is unable to add the binary files. These packages will still need to be installed.

Another option: building a binary

In the processes above, your output artifact is a single Javascript file. Instead of a Javascript file, you could also produce a binary file and thus alleviate the need to install the Node runtime. Check out pkg to do this. While pkg is a fairly mature product, this is generally still considered an experimental technology, so perhaps not suited for a production environment. On the other hand, you shouldn't run into any problems with packages that include native addons. Read the documentation to see if it's appropriate for your use case.

about 4 years ago · Juan Pablo Isaza Relatório

0

https://github.com/vercel/ncc this might help. it includes node_modules in the final artifact

about 4 years ago · Juan Pablo Isaza 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