Rollup-plugin-vue: postcss + css modules + imported styles

Created on 18 May 2018  路  5Comments  路  Source: vuejs/rollup-plugin-vue

Relevant SFC code:

<template>
<div :class="$style.test"> <!-- turns into "test___abc" -->
  <p :class="$style.local">CLASS HERE IS EMPTY</p>
</div>
</template>

<style module>
@import 'path/to/globals.pcss'
@import 'localStyle.pcss'

.test {
  background: purple;
}
</style>

Relevant parts of rollup config:

VuePlugin({
  css: false,
  defaultLang: { 
    style: 'postcss'
  },
}),
PostcssPlugin({
  extract: `out.css`,
  modules: {
    generateScopedName: `[local]___abc`,
  }
}),

Classes from localStyle.pcss are never applied via the $style object thus my component has empty classes that should be css-module classes. The css in the output file is all correct (as expected).

It's obvious the imported styles are never considered because the styles haven't been processed by postcss.

Also tried:

Having rollup-plugin-vue handle the postcss by adding this to the config (where postcssConfig comes from my postcssrc file:

style: {
  postcssOptions: postcssConfig.options,
  postcssPlugins: postcssConfig.plugins,
  postcssModulesOptions: {
    generateScopedName: `[local]___abc`,
  }
},

but this results in an error Error: Use process(css).then(cb) to work with async plugins

This has worked fine with vue-loader + webpack.

How is this supposed to work for this plugin? I'm exploring rollup as a replacement for webpack to build a component library so this is all fairly new to me. Any help is appreciated!

Medium In Progress Unknown

Most helpful comment

Fixed. To be released soon.

All 5 comments

+1

+1
use cssnano

+1 me too

Fixed. To be released soon.

As far as I can tell, this has not been fixed. The @import xyz are still not resolved and the class names in them are still ignored and not added to the $style object.

This wasn't a question of how to extract styles like you cover in #208

Some quick debugging on my end leads me to believe that it is because the style imports haven't been done so they are left out of the module object here incompiled. https://github.com/vuejs/rollup-plugin-vue/blob/master/src/index.ts#L351

I've opened an issue with vue-component-compiler as I believe that is where the issue lies.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rayrutjes picture rayrutjes  路  7Comments

2A5F picture 2A5F  路  3Comments

iassasin picture iassasin  路  6Comments

spentacular picture spentacular  路  6Comments

Infeligo picture Infeligo  路  4Comments