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

308
Visualizações
How does Typescript know where dist/index.js is, if it doesn't exist?

There is something I don't understand about this. I am trying to learn Typescript and I got me this boilerplate code using Snowpack and it contains an index.html file which refers to "dist/index.js" as its script, look below:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="description" content="Web site created using create-snowpack-app" />
    <link rel="stylesheet" type="text/css" href="/index.css" />
    <title>Snowpack App</title>
  </head>
  <body>
    <img id="img" src="/logo.svg" />
    <canvas id="canvas"></canvas>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <script type="module" src="/dist/index.js"></script>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

This index.html thing is in the "public" folder. I also have "index.ts" file in the "src" folder, which only does a console.log("hello is this typescript or javascript idk"). It does give me this console log so it seems to be working.

What I don't understand is how the index.html tries to look for a folder "dist" containing a "index.js" file while neither the "dist" folder nor the "index.js" file exist. I also have a node_modules folder but it doesn't exist there either.

How does this work? Is the "dist" folder simulated or something, while containing a non-existing index.js file when this whole thing is running?

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

0

Typescript itself doesn't know except that when you compile all your other js files the compiler (babel/webpack etc.) will generate a dist/index.js file.

Basically it's like compiling your C++ file to build Google Chrome. C++ does not know where or what the chrome.exe file is except that the build script/command tells it to generate chrome.exe from source code.

Note: Depending on your build process the directory can be named dist or build or target or mootdrafters_website etc. The react-create-app script for example does not name it's output folder dist but generates build/index.js instead.

about 4 years ago · Juan Pablo Isaza Relatório

0

How did you run your boilerplate code, by using cmd 'snowpack dev'?

If so, snowpack provides a web server running in nodejs process, and the 'src/index.ts' has been transpiled to 'dist/index.js' (in memory).When your browser requests 'dist/index.js' , the snowpack server responses the file content in memory.That's why there is no such 'dist' folder.

More futher, if you try cmd 'snowpack build', you will see the 'dist' folder.

'snowpack dev' for development, using a web server locally

'snowpack build' for production, you can deploy the 'dist' folder to any other web servers

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