question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow devServer to serve a named library on the window object

See original GitHub issue

What 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.mylibrarywhen 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:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
adriaanmeuriscommented, Mar 15, 2019

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 the background-color of the parent page to red.

Having this library available on the window object with the devServer allows to:

  • implement the paint method while seeing changes directly in the browser while developing
  • write e2e tests which can automatically trigger these methods in the browser and validate their results (background is red)
5reactions
alonsohkicommented, Jun 12, 2020

Had a look at the configuration of the devServer. It looks this is possible by adding the library name to the webpack configuration in vue.config.js:

module.exports = {
  configureWebpack: {
    output: {
      library: 'mylibrary', // Add this line to expose the library in the devServer
      libraryExport: 'default',
    }
  },
};

Will keep this issue open as I see 2 possible improvements:

  • add this to the documentation, or
  • add options target and name to vue-cli-service serve which passes these to the devServer

Can 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DevServer - webpack
This option allows you to allowlist services that are allowed to access the dev server. webpack.config.js module.exports = { //... devServer: ...
Read more >
A problem when I use webpack-5's libraryTarget:window
So, I use libraryTarget:'window' in app1's webpack config. devServer: { //... libraryTarget:'window' },. It works fine when I use webpack4. But ...
Read more >
Configuration Reference | Vue CLI
devServer.proxy #. Type: string | Object. If your frontend app and the backend API server are not running on the same host, you ......
Read more >
How to build a complete JavaScript library using ES6 and ...
We are going to develop a JavaScript plugin/library in step by step ... webpack-dev-server allows us to have automatic live code updates.
Read more >
DevServer - webpack 3 documentation
devServer. object. This set of options is picked up by webpack-dev-server and can be used to change its behavior in various ways.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found