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

140
Visualizações
Split multiple entry points into distinguishable builds that work on their own

I have written a React app that has a standalone version and an embedded version. The difference is that the embedded version misses afew components and that it does a lot of lazy loading (it is heavily reduced in size versus the standalone version). Because of the lazy loading the embedded version generates a lot of js files. Now what I'm trying to achieve is that whenever I build my project(s) that it creates two folders;

  • build/standalone => all JS files needed to import the standalone application into any html project
  • build/embedded => all JS files needed to import the embedded application into any html project

How could I do this?

webpack.common.js

module.exports = {
    entry: {
        standalone: path.resolve(__dirname, '../src/index.standalone.tsx'),
        embedded: path.resolve(__dirname, '../src/index.embedded.tsx')
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    output: {
        path: path.resolve(__dirname, '..', './build'),
        filename: '[name].[contenthash].bundle.js' // I know I could do ./[name]/[contenthash].bundle.js but this also results in folders for chunks
    },
    optimization: {
        runtimeChunk: 'single',
        splitChunks: {
            chunks: 'all'
        }
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, '..', './public/index.html')
        })
    ]
};

What I get right now, which is not what I want;

enter image description here

With this its nearly impossible to know what files you need to, for example, implement the embedded version on my webpage.

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

0

One straightforward way to achieve this is to make output.filename a function and use the chunk name.

output: {
  path: path.resolve(__dirname, '..', './build'),
  filename: (pathData) => {
    return `${pathData.chunk.name}/[name].[contenthash].bundle.js`;
  },
},

There are more examples in the linked docs.

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