Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No CSS files when running 'vue-cli-service build --watch'

I have a simple project generated with vue-cli. When I run the vue-cli-service build command it produces CSS file correctly. When I run the vue-cli-service build --watch command it only builds JavaScript files. There are no CSS files.

How can I generate CSS files in watch mode?

like image 292
Grzegorz Żur Avatar asked Sep 24 '19 22:09

Grzegorz Żur


People also ask

How do I add CSS to Vue?

In Vue. js, we can add an inline style to our element by binding the style attribute in the HTML tag. For reference, :style is shorthand for v-bind:style . Inline styling can be done in two ways: using object syntax or array syntax.

Do you need CSS with Vue?

Before we move on to add more advanced features to our app, we should add some basic CSS to make it look better. Vue has three common approaches to styling apps: External CSS files.

What does Vue-CLI-service build?

vue-cli-service build produces a production-ready bundle in the dist/ directory, with minification for JS/CSS/HTML and auto vendor chunk splitting for better caching. The chunk manifest is inlined into the HTML.

How do I import CSS into vue3?

Importing CSS in Vue components If you are setup and using webpack, you should be able to import css directly from inside <style> tags in component files. More info here: https://cli.vuejs.org/guide/css.html. https://github.com/vuejs/vue-loader.


2 Answers

You can achieve this by adding this line of code in your vue.config.js

//vue.config.js

module.exports = {
//adding extract css true solves this issue
 css: {
    extract: true
  }
}

https://cli.vuejs.org/config/#css-extract

like image 105
Emmanuel David Avatar answered Oct 24 '22 11:10

Emmanuel David


There is a good chance that you have to use an extract plugin for webpack.

I know that in my vue.config.js file I'm using :

  chainWebpack: config => {
    if (config.plugins.has('extract-css')) {
      const extractCSSPlugin = config.plugin('extract-css');
      extractCSSPlugin &&
        extractCSSPlugin.tap(() => [
          {
            filename: 'build.css',
            chunkFilename: 'build.css'
          }
        ]);
    }
  }

Hopefully this help you. However vue inject your css in watch mode right at the top of your file for automatic re-rendering purpose I think.

like image 1
Baldráni Avatar answered Oct 24 '22 10:10

Baldráni