Search code examples
vue.jsvue-clivue-cli-3

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?


Solution

  • 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.