File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -594,6 +594,11 @@ css(styles2.globals);
594594
595595It isn't determinate whether divs will be red or blue.
596596
597+ ## Minify class names
598+
599+ Minify class names by setting the environment variable ` process.env.APHRODITE_KEYS `
600+ to the string value ` MINIFIED ` .
601+
597602# Tools
598603
599604- [ Aphrodite output tool] ( https://output.jsbin.com/qoseye ) - Paste what you pass to ` StyleSheet.create ` and see the generated CSS
Original file line number Diff line number Diff line change @@ -21,9 +21,8 @@ const StyleSheet = {
2121 create ( sheetDefinition /* : SheetDefinition */ ) {
2222 return mapObj ( sheetDefinition , ( [ key , val ] ) => {
2323 return [ key , {
24- // TODO(emily): Make a 'production' mode which doesn't prepend
25- // the class name here, to make the generated CSS smaller.
26- _name : `${ key } _${ hashObject ( val ) } ` ,
24+ _name : process . env . APHRODITE_KEYS !== 'MINIFIED' ?
25+ `${ key } _${ hashObject ( val ) } ` : `_${ hashObject ( val ) } ` ,
2726 _definition : val
2827 } ] ;
2928 } ) ;
Original file line number Diff line number Diff line change @@ -229,6 +229,32 @@ describe('StyleSheet.create', () => {
229229
230230 assert . ok ( sheet . empty . _name ) ;
231231 } ) ;
232+
233+ describe ( 'process.env.APHRODITE_KEYS === \'MINIFIED\'' , ( ) => {
234+ beforeEach ( ( ) => {
235+ process . env . APHRODITE_KEYS = 'MINIFIED' ;
236+ } ) ;
237+
238+ afterEach ( ( ) => {
239+ delete process . env . APHRODITE_KEYS ;
240+ } ) ;
241+
242+ it ( 'hashes style names correctly' , ( ) => {
243+ const sheet = StyleSheet . create ( {
244+ test : {
245+ color : 'red' ,
246+ height : 20 ,
247+
248+ ':hover' : {
249+ color : 'blue' ,
250+ width : 40 ,
251+ } ,
252+ } ,
253+ } ) ;
254+
255+ assert . equal ( sheet . test . _name , '_j5rvvh' ) ;
256+ } ) ;
257+ } )
232258} ) ;
233259
234260describe ( 'rehydrate' , ( ) => {
You can’t perform that action at this time.
0 commit comments