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

210
Visualizações
what is the most correct and best way to pack this code with webpack?

I am learning webpack, and i used this official example(i know lodash is a umd module, so i use lodash-es here), and it will generate a lot of code, and two files.

import _ from "lodash-es";
function component() {
  const element = document.createElement("div");
  element.innerHTML = _.join(["Hello", "webpack"],(" "));
  return element;
}
document.body.appendChild(component());

but it will gen one file which only has one line when i change it a little.

function component() {
  const element = document.createElement("div");
  element.innerHTML = ["Hello", "webpack"].join(" ");
  return element;
}
document.body.appendChild(component());
document.body.appendChild(function(){const e=document.createElement("div");return e.innerHTML=["Hello","webpack"].join(" "),e}());

my question is why they are so different and how to achieve the second code's result, when i using lodash. I think it should generate some code which only have the join something function.

maybe my js basics is thin, if you have some books, articles which can help me get the answer, that is also great.

here is the webpack.config.js

const path = require("path");

module.exports = {
  mode: "production",
  entry: "./src/index.js",
  output: {
    filename: "[name].bundle.js",
    chunkFilename: '[id].[hash].js',
    path: path.resolve(__dirname, "dist"),
    clean: true,
  },
  optimization: {
    splitChunks: {
      chunks: 'all',
    },
  },
};
about 4 years ago · Juan Pablo Isaza
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