Code Monkey home page Code Monkey logo

Comments (9)

ScriptedAlchemy avatar ScriptedAlchemy commented on June 27, 2024 2

Fantastic. Apologies for the error! Thank you @akash5474 for reporting it!

Gonna merge this baby

from webpack-flush-chunks.

ScriptedAlchemy avatar ScriptedAlchemy commented on June 27, 2024 1

on npm, let me know if thats better

from webpack-flush-chunks.

alexkrautmann avatar alexkrautmann commented on June 27, 2024

I can verify this error. My optimization config is:

optimization: {
        runtimeChunk: {
            name: 'bootstrap'
        },
        splitChunks: {
            chunks: 'initial',
            cacheGroups: {
                vendors: {
                    test: /[\\/]node_modules[\\/]/,
                    name: 'vendor'
                }
            }
        },
}

And both bootstrap and vendor show up twice from the return of flushChunks.

from webpack-flush-chunks.

slavab89 avatar slavab89 commented on June 27, 2024

I have the same issue and use the same setup.

This is caused because the after assets include the before ones because they are included as part of the entry (which is logical).
I'm not sure what's the impact of just filtering the before assets from the after ones though.

To still be able to work with webpack 4 i'm using my own script to extract the list of files (until a fix will be up)

import { flatten, includes } from 'lodash';

function filesFromChunks(chunkNames, assets, checkChunkNames) {
  const hasChunk = entry => {
    const result = !!assets[entry];
    if (!result && checkChunkNames) {
      console.warn(`Unable to find ${entry} in Webpack chunks.`);
    }

    return result;
  };

  const entryToFiles = entry => assets[entry];

  return [].concat(...chunkNames.filter(hasChunk).map(entryToFiles));
}

export default function chunksMap(clientStats) {
  const publicPath = clientStats.publicPath.replace(/\/$/, '');
  const beforeAssets = filesFromChunks(['bootstrap', 'vendor'], clientStats.assetsByChunkName);
  const afterAssets = filesFromChunks(['main'], clientStats.assetsByChunkName);

  return function flushChunks(chunkNames) {
    const mainAssets = flatten(chunkNames.map(chunkName => clientStats.namedChunkGroups[chunkName].assets));
    const allNeededAssets = [...beforeAssets, ...mainAssets, ...afterAssets];

    const jsAssets = allNeededAssets
      .filter(asset => includes(asset, '.js'))
      .map(file => `<script type='${includes(file, '.map') ? 'application/json' : 'text/javascript'}' src='${publicPath}/${file}' defer></script>`)
      .join('\n');

    return {
      js: jsAssets,
    };
  };
}

That's only for JS files.

from webpack-flush-chunks.

ScriptedAlchemy avatar ScriptedAlchemy commented on June 27, 2024

Thanks for finding this! I’ll patch the duplicate

from webpack-flush-chunks.

ScriptedAlchemy avatar ScriptedAlchemy commented on June 27, 2024

@slavab89 @akash5474 Ill push a next tag on npm as well

from webpack-flush-chunks.

ScriptedAlchemy avatar ScriptedAlchemy commented on June 27, 2024

#62

from webpack-flush-chunks.

alexkrautmann avatar alexkrautmann commented on June 27, 2024

@ScriptedAlchemy I just tried out next and it definitely works for me.

from webpack-flush-chunks.

akash5474 avatar akash5474 commented on June 27, 2024

@ScriptedAlchemy Np and thanks for getting this fixed, working great now. Appreciate all the work you're doing with these libs.

from webpack-flush-chunks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.