melange: introduce `melange.root` stanza, to avoid duplicated .js artifacts
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 1.9k
- Forks
- 500
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 277
Description
At the moment, every melange.emit stanza generates its own version of the js artifacts produced by the libs it consumes. It there are N melange.emit stanzas using the same library foo, the js artifacts for foo will be found N times under the _build folder.
Besides unnecessary disk space usage, this is problematic for build tools like webpack, that become slower as they have to process the same files multiple times. It is also punitive for the resulting JavaScript bundle size, as it is not possible out of the box to reuse the same library js bundle in multiple places, unless one goes going through complex webpack configurations.
To avoid this, @rgrinberg suggested the idea of introducing a new stanza melange.root. This new stanza would define a target, and the javascript_extension and module_system used by that target, e.g.:
(melange.root
(target tools_es6)
(module_system es6)
(javascript_extension js))
Then, afaiu, melange.emit stanzas that are spread across the project folders would be used to define "entry points", referencing the target already defined in melange.root, e.g.
(melange.emit
(target tools_es6)
(alias melange)
(libraries lib))
The fields module_system and javascript_extension would be removed from melange.emit.
Some open questions:
- Should
melange.rootbe induneordune-projectfile? - Is it possible to solve the duplication problem without adding a new stanza?
- If
melange.rootwas ultimately added, would it make sense to rethink stanza naming? e.g.melange.emitcould be rathermelange.entry_pointormelange.executable, as it would not be really emitting anything anymore. Andmelange.rootcould bemelange.emitinstead.
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 how melange.emit stanzas produce JavaScript artifacts and how targets, module_system, and javascript_extension are handled. Compare the proposed melange.root design with the alternative of solving duplication without a new stanza, including whether it belongs in dune or dune-project. Done means shared library artifacts are no longer duplicated across entry points and the stanza naming and configuration are settled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100