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

postcss + css modules + imported styles #203

Closed
@lancetharper

Description

@lancetharper

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions