Allow devServer to serve a named library on the window object
See original GitHub issueWhat problem does this feature solve?
CLI service serve
does not allow to serve libraries which expose their default export on the window object. CLI service build
does:
I’m successfully building a library with a .js file as entry, which exposes the default export to the window object (umd build):
vue-cli-service build --target lib --name mylibrary
The library is availabe as window.mylibrary
when loading the library in a script tag.
However, this is not possible when working with the devServer
, as only the build
command accepts the options target
and name
.
What does the proposed API look like?
vue-cli-service serve --target lib --name mylibrary
The library would would be available to the window object when loaded as a script tag in the devServer page (assuming we’re serving a UMD-build)
I currently achieve this by manually adding the library to the window object in code. Any guidance on how to achieve would be very much appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Exactly - the library exposes some methods which can be called by the website that embeds it.
Let’s say for example
window.mylibrary.paint()
would set thebackground-color
of the parent page tored
.Having this library available on the window object with the
devServer
allows to:paint
method while seeing changes directly in the browser while developingCan you give more information of how you got this to work? How do you include the library into the main app to take advantage of the HMR? And how do you reference it?