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.

Component built with --target lib does not persist styles when imported

See original GitHub issue

Version

3.0.0-beta.15

Reproduction link

https://github.com/MartinPeverelli/reproduction-app

Steps to reproduce

  • git clone git@github.com:MartinPeverelli/reproduction-app.git
  • npm run install
  • npm run serve

What is expected?

Title on screen should be red, because imported component ReproductionModuleTranspiled has scoped styles defining its text to be red.

What is actually happening?

Title on screen is black, styles are not being applied from imported module


Component ReproductionModuleTranspiled is here: https://github.com/MartinPeverelli/reproduction-module-transpiled Was built using vue-cli-service build --target lib src/main.js and has .env.production with VUE_CLI_CSS_SHADOW_MODE = true The generated dist files do indeed contain the scoped css, but it is not being applied when the component is imported on the main app.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
MartinPeverellicommented, Jun 7, 2018

@yyx990803 just found this in the docs (which I see are under heavy update)

dist/myLib.css: Extracted CSS file (can be forced into inlined by setting css: { extract: false } in vue.config.js)

That appears to produce the desired effect. Thanks!

2reactions
stefanalexlupucommented, Oct 7, 2019

Hey, your solution worked for me but when using it with nuxt ssr, I get the following error:

document is not defined

And this snippet of code is supposedly the reason:

  return styleElement
}

function addStyle (obj /* StyleObjectPart */) {
  var update, remove
  var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]')

  if (styleElement) {
    if (isProduction) {
      // has SSR styles and in production mode.
      // simply do nothing.

in the common.js file

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-cli-service build --target lib does not respect @ paths
The problem is that when building the project using yarn buildLib , vue-cli-service build does not resolve the @ in import paths and...
Read more >
Troubleshooting Guide - React Flow
This guide contains warnings and errors that can occur when using React Flow. We are also adding common questions and pitfalls that we...
Read more >
Styling in React: 5 ways to style React apps - LogRocket Blog
Sharing styles across many React components. The style objects and the components do not have to be in the same file. We can...
Read more >
Angular workspace configuration
In Sass you can make use of the includePaths feature for both component and global styles. This allows you to add extra base...
Read more >
Parcel
The zero configuration build tool for the web. ... All of this is completely automatic and does not require any work by plugin...
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