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

181
Visualizações
How to insert a javascript file in another javascript at build time using comments

Is there something on npm or in VS Code or anywhere that can bundle or concatenate Javascript files based on comments, like:

function myBigLibrary(){
    //@include util.js
    //@include init.js

    function privateFunc(){...}

    function publicFunc(){
      //@include somethingElse.js
      ...
    }

    
    
    return {
        init, publicFunc, etc
    }
}

Or something like that? I would think that such a thing is common when your javascript files get very large. All I can find are complicated things like webpack.

I'm looking for any equivalent solution that allows you to include arbitrary code in arbitrary positions in other code. I suppose that would cause trouble for intellisense, but an extension could handle that.

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

0

I'm not sure what you really means but if you means linking variables from other javascript files. probably this will help you
const { variable name } = require(the javascript file path)
example:
in index.js

const { blue } = require('./../js/blue.js)
console.log(blue)


Meanwhile in blue.js

const blue = "dumbass"

if this doesnt help you just ignore this

about 4 years ago · Juan Pablo Isaza Relatório

0

So here is a bare bones way to to what I wanted. I have been learning more about how you can do things with esbuild or other bundlers, but I didn't quite figure out something that fit my needs. And this is simpler and more flexible. It can work for any file type. You can do automatic updates when files change using nodemon instead of node to run this code.

const fs = require('fs')
/////////////////////////

const input  = 'example.js'
const output = 'output.js'

const ext    = '.js'

// looks for file with optional directory as: //== dir/file
const regex  = /\/\/== *([\w-\/]+)/g


const fileContent = fs.readFileSync(input).toString()


// replace the comment references with the corresponding file content
const replacement = fileContent.replace(regex, (match, group)=>{

    const comment = '//////// '+group+ext+' ////////\n\n'
    const replace = fs.readFileSync(group+ext).toString()
    return comment + replace

})

// write replacement to a file
fs.writeFileSync(output, replacement)
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