Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

postcss + css modules + imported styles #203

Closed
lancetharper opened this issue May 18, 2018 · 5 comments
Closed

postcss + css modules + imported styles #203

lancetharper opened this issue May 18, 2018 · 5 comments

Comments

@lancetharper
Copy link

lancetharper commented May 18, 2018

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!

@gregorskii
Copy link

+1

@htmlin
Copy link

htmlin commented Aug 22, 2018

+1
use cssnano

@channg
Copy link

channg commented Aug 31, 2018

+1 me too

@znck
Copy link
Member

znck commented Jan 14, 2019

Fixed. To be released soon.

@znck znck closed this as completed Jan 14, 2019
@lancetharper
Copy link
Author

lancetharper commented Mar 5, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants