@@ -16,6 +16,45 @@ const addon = new Addon({
16
16
destDir : 'dist' ,
17
17
} ) ;
18
18
19
+ // Custom SCSS compilation plugins for Rollup
20
+ function addScssCompilationPlugins ( options ) {
21
+ return options . map ( ( { inputFile, outputFile } ) => ( {
22
+ name : `rollup custom plugin to generate ${ outputFile } ` ,
23
+ generateBundle ( ) {
24
+ try {
25
+ const inputFileFullPath = `src/styles/@hashicorp/${ inputFile } ` ;
26
+ const outputFileFullPath = `styles/@hashicorp/${ outputFile } ` ;
27
+
28
+ const result = sass . compile ( inputFileFullPath , {
29
+ sourceMap : true ,
30
+ // equivalent to includePaths in rollup-plugin-scss
31
+ loadPaths : [ 'node_modules/@hashicorp/design-system-tokens/dist' ] ,
32
+ } ) ;
33
+
34
+ // Emit the compiled CSS
35
+ this . emitFile ( {
36
+ type : 'asset' ,
37
+ fileName : outputFileFullPath ,
38
+ source : result . css ,
39
+ } ) ;
40
+
41
+ // Emit the source map
42
+ if ( result . sourceMap ) {
43
+ this . emitFile ( {
44
+ type : 'asset' ,
45
+ fileName : `${ outputFileFullPath } .map` ,
46
+ source : JSON . stringify ( result . sourceMap ) ,
47
+ } ) ;
48
+ }
49
+ } catch ( error ) {
50
+ this . error (
51
+ `Failed to compile SCSS file "${ inputFile } ": ${ error . message } `
52
+ ) ;
53
+ }
54
+ } ,
55
+ } ) ) ;
56
+ }
57
+
19
58
const plugins = [
20
59
// These are the modules that users should be able to import from your
21
60
// addon. Anything not listed here may get optimized away.
@@ -60,122 +99,23 @@ const plugins = [
60
99
fileName : 'styles/@hashicorp/design-system-power-select-overrides.css' ,
61
100
} ) ,
62
101
63
- // Custom plugins to compile the "themed" SCSS files
64
- {
65
- name : 'compile-scss-themed-with-css-selectors' ,
66
- generateBundle ( ) {
67
- // Compile the themed SCSS file
68
- try {
69
- const result = sass . compile (
70
- 'src/styles/@hashicorp/design-system-components-theming-with-css-selectors.scss' ,
71
- {
72
- sourceMap : true ,
73
- // equivalent to includePaths in rollup-plugin-scss
74
- loadPaths : [ 'node_modules/@hashicorp/design-system-tokens/dist' ] ,
75
- }
76
- ) ;
77
-
78
- const cssFileName =
79
- 'styles/@hashicorp/design-system-components-theming-with-css-selectors.css' ;
80
-
81
- // Emit the compiled CSS
82
- this . emitFile ( {
83
- type : 'asset' ,
84
- fileName : cssFileName ,
85
- source : result . css ,
86
- } ) ;
87
-
88
- // Emit the source map
89
- if ( result . sourceMap ) {
90
- this . emitFile ( {
91
- type : 'asset' ,
92
- fileName : `${ cssFileName } .map` ,
93
- source : JSON . stringify ( result . sourceMap ) ,
94
- } ) ;
95
- }
96
- } catch ( error ) {
97
- this . error (
98
- `Failed to compile themed ("with CSS selectors") SCSS: ${ error . message } `
99
- ) ;
100
- }
102
+ // Custom SCSS compilation plugin function
103
+ ...addScssCompilationPlugins ( [
104
+ {
105
+ inputFile : 'design-system-components.scss' ,
106
+ outputFile : 'design-system-components-ALT.css' ,
101
107
} ,
102
- } ,
103
- {
104
- name : 'compile-scss-alt' ,
105
- generateBundle ( ) {
106
- // Compile the themed SCSS file
107
- try {
108
- const result = sass . compile (
109
- 'src/styles/@hashicorp/design-system-components.scss' ,
110
- {
111
- sourceMap : true ,
112
- // equivalent to includePaths in rollup-plugin-scss
113
- loadPaths : [ 'node_modules/@hashicorp/design-system-tokens/dist' ] ,
114
- }
115
- ) ;
116
-
117
- const cssFileName =
118
- 'styles/@hashicorp/design-system-components-ALT.css' ;
119
-
120
- // Emit the compiled CSS
121
- this . emitFile ( {
122
- type : 'asset' ,
123
- fileName : cssFileName ,
124
- source : result . css ,
125
- } ) ;
126
-
127
- // Emit the source map
128
- if ( result . sourceMap ) {
129
- this . emitFile ( {
130
- type : 'asset' ,
131
- fileName : `${ cssFileName } .map` ,
132
- source : JSON . stringify ( result . sourceMap ) ,
133
- } ) ;
134
- }
135
- } catch ( error ) {
136
- this . error ( `Failed to compile ALT SCSS: ${ error . message } ` ) ;
137
- }
108
+ {
109
+ inputFile : 'design-system-components-theming-with-css-selectors.scss' ,
110
+ outputFile : 'design-system-components-theming-with-css-selectors.css' ,
138
111
} ,
139
- } ,
140
- {
141
- name : 'compile-scss-themed-with-prefers-color-scheme' ,
142
- generateBundle ( ) {
143
- // Compile the themed SCSS file
144
- try {
145
- const result = sass . compile (
146
- 'src/styles/@hashicorp/design-system-components-theming-with-prefers-color-scheme.scss' ,
147
- {
148
- sourceMap : true ,
149
- // equivalent to includePaths in rollup-plugin-scss
150
- loadPaths : [ 'node_modules/@hashicorp/design-system-tokens/dist' ] ,
151
- }
152
- ) ;
153
-
154
- const cssFileName =
155
- 'styles/@hashicorp/design-system-components-theming-with-prefers-color-scheme.css' ;
156
-
157
- // Emit the compiled CSS
158
- this . emitFile ( {
159
- type : 'asset' ,
160
- fileName : cssFileName ,
161
- source : result . css ,
162
- } ) ;
163
-
164
- // Emit the source map
165
- if ( result . sourceMap ) {
166
- this . emitFile ( {
167
- type : 'asset' ,
168
- fileName : `${ cssFileName } .map` ,
169
- source : JSON . stringify ( result . sourceMap ) ,
170
- } ) ;
171
- }
172
- } catch ( error ) {
173
- this . error (
174
- `Failed to compile themed ("with CSS selectors") SCSS: ${ error . message } `
175
- ) ;
176
- }
112
+ {
113
+ inputFile :
114
+ 'design-system-components-theming-with-prefers-color-scheme.scss' ,
115
+ outputFile :
116
+ 'design-system-components-theming-with-prefers-color-scheme.css' ,
177
117
} ,
178
- } ,
118
+ ] ) ,
179
119
180
120
// Ensure that standalone .hbs files are properly integrated as Javascript.
181
121
addon . hbs ( ) ,
0 commit comments