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

Commit

Permalink
chore: update css module example to correctly handle <styles module> …
Browse files Browse the repository at this point in the history
…related options (#356)

Co-authored-by: Rahul Kadyan <[email protected]>
  • Loading branch information
przemkow and znck authored Oct 22, 2020
1 parent ce25256 commit 09c41b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions examples/css-modules/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ const config = [
// Resolve packages from `node_modules` e.g. `style-inject` module
// used by `rollup-plugin-postcss` to inline CSS.
NodeResolve(),
VuePlugin(),
// Process only `<style module>` blocks.
PostCSS({
modules: {
VuePlugin({
// PostCSS-modules options for <style module> compilation
cssModulesOptions: {
generateScopedName: '[local]___[hash:base64:5]',
},
include: /&module=.*\.css$/,
}),
// Process all `<style>` blocks except `<style module>`.
PostCSS({ include: /(?<!&module=.*)\.css$/ }),
PostCSS(),
],
external(id) {
return /^(vue)$/.test(id)
Expand Down
2 changes: 1 addition & 1 deletion examples/css-modules/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export default {

<style scoped>
.green {
color: red;
color: green;
}
</style>
6 changes: 3 additions & 3 deletions test/core.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ describe('css-modules', () => {
expect(result.output[0].code).not.toEqual(
expect.stringContaining('.red {\n color: red;\n}')
)
expect(result.output[0].code).toEqual(expect.stringContaining('._red_'))
expect(result.output[0].code).toEqual(expect.stringContaining('.red___'))
expect(result.output[0].code).toEqual(
expect.stringContaining('{"red":"_red_')
expect.stringContaining('{"red":"red___')
)
})

Expand All @@ -67,7 +67,7 @@ describe('css-modules', () => {
expect.stringContaining('.__scopeId = "data-v-')
)
expect(result.output[0].code).not.toEqual(
expect.stringContaining('.green {\n color: red;\n}')
expect.stringContaining('.green {\n color: green;\n}')
)
expect(result.output[0].code).toEqual(
expect.stringContaining('.green[data-v-')
Expand Down

0 comments on commit 09c41b7

Please sign in to comment.