ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
753 stars 113 forks source link

Source file order in bundles is not preserved #252

Closed peitschie closed 1 year ago

peitschie commented 1 year ago

I'm using the WebOptimizer bundler to concatenate a few IIFE modules together, but have hit a quirk in that the order of the files are not preserved when explicitly supplied.

For example, based this input:

pipeline.AddJavaScriptBundle("/bundles/js/vue.bundle.min.js",
  "lib/vue/dist/vue.global.js",
  "lib/vue-demi/index.iife.js",
  "lib/pinia/dist/pinia.iife.js");

I'd expect the generated vue.bundle.min.js to have included the modules in the order as supplied. Instead, the output it somewhat suprisingly ordered as:

  1. "lib/vue/dist/vue.global.js"
  2. "lib/pinia/dist/pinia.iife.js"
  3. "lib/vue-demi/index.iife.js"

This output order is unaffected by the order of files I pass in.

Perhaps this issue is caused by the use of a dictionary in the AssetContext to gather the file contents together: https://github.com/ligershark/WebOptimizer/blob/master/src/WebOptimizer.Core/AssetContext.cs#L17

peitschie commented 1 year ago

Scratch that... closer analysis shows an earlier step in my own pipeline was dropping the dependency out.