If you’re using the Bundler & Minifier package in ASP.NET Core (instead of something like Webpack, Gulp, or the new hotness Parcel) and your bundleconfig.json
has these properties set on your JavaScript files:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"minify": { | |
"enabled": true, | |
"renameLocals": true | |
}, | |
"sourceMap": false |
You can remove those, because those are the default. On a project I’m working on that uses it, it shaved ~50 LOC on our bundleconfig.json
which kept things less noisy.
Before:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"outputFileName": "wwwroot/js/site.min.js", | |
"inputFiles": [ | |
"wwwroot/js/site.js" | |
], | |
"minify": { | |
"enabled": true, | |
"renameLocals": true | |
}, | |
"sourceMap": false | |
} | |
] |
After:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"outputFileName": "wwwroot/js/site.min.js", | |
"inputFiles": [ | |
"wwwroot/js/site.js" | |
] | |
} | |
] |
If you have those options listed, that shouldn’t come as much of a surprise. The ASP.NET Core templates have these options explicitly listed by default, so I would expect most people who use the Bundler & Minifier to follow suit.
If you want to verify that the bundles are the same, it’s easy to test it out in Visual Studio.
- Go to the Task Runner Explorer in Visual Studio
- Go to bundleconfig.json
- Right-click on Update all files
- Click Run
Then check to see if your version control picks up any changes. Spoiler: it won’t. 🙂
Hope this helps!
According to this:
https://github.com/madskristensen/BundlerMinifier/wiki/JavaScript-Minifier-settings
renameLocals defaults to False.
Hmm. Looks to me like that docs page is wrong, because, unless I’m missing something, according to the code the default is true.
https://github.com/madskristensen/BundlerMinifier/blob/baa449b0f5206b4cfb4cd3d2105f24f109e0393e/src/BundlerMinifier.Core/Minify/JavaScriptOptions.cs#L16
Ah, thanks. I’ll notify or edit the repo. That threw me off the track. True makes more sense, it’s part of the essence of minifying. It would be ideal if there was a mechanism for setting the defaults once at the start rather than repeating the same set of non-defaults.
Agree. That’d be a great feature. It’s super verbose otherwise, which is the heart of why I made the blog post. Thanks for updating those docs!