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

chore: update css-module example to correctly handle <styles module> … #356

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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