Jujubes
Jujubes

Reputation: 434

How to keep CSS/SCSS with Vue component file

I am creating a component library where I do not want to have global CSS. Therefore, every component is scoped.

When running the production build via vue-cli-service build --target lib --name sc components/index.js, everything is compiled into sc.css and dist/css/1.392e001d.css.

If possible, I want to keep the css and/or scss combined with the vue file or js.

The reason I want to do this is to enable users of the library to import a singular component from the library. The users could then use the component anywhere without having to import/include a css file.

If this is not possible, is there a way to accomplish the desired functionality?

Upvotes: 2

Views: 1563

Answers (1)

tony19
tony19

Reputation: 138216

From the Vue CLI docs for css.extract:

When building as a library, you can also set this to false to avoid your users having to import the CSS themselves.

// vue.config.js
module.exports = {
  css: {
    extract: false
  }
}

Upvotes: 3

Related Questions