assets-webpack-plugin icon indicating copy to clipboard operation
assets-webpack-plugin copied to clipboard

Support chunk sorting options

Open JakeGinnivan opened this issue 6 years ago • 5 comments

It would be awesome to support sorting of the chunks, similar to https://github.com/jantimon/html-webpack-plugin/blob/master/lib/chunksorter.js

I currently use this plugin to create the assets and would like to automatically be able to include the appropriate script tags during SSR in the correct order automatically.

This could probably also supersede the manifestFirst option?

JakeGinnivan avatar Sep 03 '18 07:09 JakeGinnivan

I think this would be a pretty major change as it would require the output to be wrapped in an array or some sortable structure instead of an object.

Not opposed to it, just would require some planning and a major release.

ztoben avatar Sep 07 '18 18:09 ztoben

At worst, could a sort order index attribute be output as a property and leave the sorting up to the file consumer.

{
  "runtime": {
    "js": "runtime.913f0ed272c4b1c945f9.js",
    "sortOrder": 0
  },
  "main": {
    "js": "main.edc1ff76e4c8be6f4c81.js",
    "sortOrder": 3
  },
  "polyfills": {
    "js": "polyfills.ab67acf99a82d53b562f.js",
    "sortOrder": 1
  },
  "styles": {
    "css": "styles.03caaa68356691cce406.css",
    "sortOrder": 0
  },
  "scripts": {
    "js": "scripts.48544e4b8eb1ac0cceaa.js",
    "sortOrder": 2
  }
}

reddogaw avatar Nov 26 '18 00:11 reddogaw

Yeah, that would be a good way to do it. Happy to review any PRs. A little too busy right now to do it myself.

ztoben avatar Nov 26 '18 15:11 ztoben

What is the current order based on? It's not aplhabetical, it's not the same as the order reported by webpack in console (entry points, then chunks). Thanks.

thiemeljiri avatar Jan 17 '19 15:01 thiemeljiri

There isn't any set order, outside of setting the manifestFirst option. If you want to follow it through the code, you could probably start here: https://github.com/ztoben/assets-webpack-plugin/blob/master/lib/output/createOutputWriter.js#L59

ztoben avatar Jan 18 '19 02:01 ztoben