UMD - include params like window & document for better compression
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 26.3k
- Forks
- 1.8k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 20
Description
I'm building a front-end library.
I'm using the UDM module format and right now it looks like this:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.demo = factory());
})(this, (function () { 'use strict';
However, I would like to include on the function params the window and document global variables.
Something like this:
(function (global, factory, document, window) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.demo = factory());
})(this, factory, document, window(function (document, window) { 'use strict';
'use strict';
The main reason for that is to get a smaller output size when compressing it through Tester or any other plugin.
Adding these variables to the closure function allows them to get minified.
So, if I have a bundle file with 500 repetitions of the word document, that's 4Kb of data that can be reduced to 500bytes using a single word.
The same applies to window or any other global variable such as Math.
Any way to add these to the UMD module declaration?
This is my current config:
output: [
{
file: "build/demo.js",
name: "demo",
format: "umd",
globals: {
'document': 'document',
'window': 'window'
},
},
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Rollup's UMD output generation and how the output.globals configuration is currently handled. Compare the requested window, document, and Math bindings with the existing UMD declaration; done means a configured bundle exposes those globals as parameters and produces the intended smaller compressed output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100