File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed
lib/style-compiler/plugins Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,18 @@ var selectorParser = require('postcss-selector-parser')
33
44module . exports = postcss . plugin ( 'add-id' , function ( opts ) {
55 return function ( root ) {
6+ var keyframes = Object . create ( null )
7+
68 root . each ( function rewriteSelector ( node ) {
79 if ( ! node . selector ) {
810 // handle media queries
9- if ( node . type === 'atrule' && node . name === 'media' ) {
10- node . each ( rewriteSelector )
11+ if ( node . type === 'atrule' ) {
12+ if ( node . name === 'media' ) {
13+ node . each ( rewriteSelector )
14+ } else if ( node . name === 'keyframes' ) {
15+ // register keyframes
16+ keyframes [ node . params ] = node . params = node . params + '-' + opts . id
17+ }
1118 }
1219 return
1320 }
@@ -23,5 +30,13 @@ module.exports = postcss.plugin('add-id', function (opts) {
2330 } )
2431 } ) . process ( node . selector ) . result
2532 } )
33+
34+ if ( Object . keys ( keyframes ) . length ) {
35+ root . walkDecls ( decl => {
36+ if ( / - ? a n i m a t i o n $ / . test ( decl . prop ) && keyframes [ decl . value ] ) {
37+ decl . value = keyframes [ decl . value ]
38+ }
39+ } )
40+ }
2641 }
2742} )
Original file line number Diff line number Diff line change 88h1 {
99 color : green ;
1010}
11+ .anim {
12+ animation : color ;
13+ }
14+ @keyframes color {
15+ from { color : red ; }
16+ to { color : green ; }
17+ }
1118 </style >
1219
1320<template >
Original file line number Diff line number Diff line change @@ -193,9 +193,12 @@ describe('vue-loader', function () {
193193
194194 var style = window . document . querySelector ( 'style' ) . textContent
195195 style = normalizeNewline ( style )
196- expect ( style ) . to . contain ( '.test[' + id + '] {\n color: yellow;\n}' )
197- expect ( style ) . to . contain ( '.test[' + id + ']:after {\n content: \'bye!\';\n}' )
198- expect ( style ) . to . contain ( 'h1[' + id + '] {\n color: green;\n}' )
196+ expect ( style ) . to . contain ( `.test[${ id } ] {\n color: yellow;\n}` )
197+ expect ( style ) . to . contain ( `.test[${ id } ]:after {\n content: \'bye!\';\n}` )
198+ expect ( style ) . to . contain ( `h1[${ id } ] {\n color: green;\n}` )
199+ // scoped keyframes
200+ expect ( style ) . to . contain ( `.anim[${ id } ] {\n animation: color-${ id } ;\n}` )
201+ expect ( style ) . to . contain ( `@keyframes color-${ id } {` )
199202 done ( )
200203 } )
201204 } )
You can’t perform that action at this time.
0 commit comments