66import { Addon } from '@embroider/addon-dev/rollup' ;
77import { babel } from '@rollup/plugin-babel' ;
88import copy from 'rollup-plugin-copy' ;
9- import scss from 'rollup-plugin-scss' ;
109import process from 'process' ;
1110import path from 'node:path' ;
11+ import * as sass from 'sass' ;
1212
1313const addon = new Addon ( {
1414 srcDir : 'src' ,
1515 destDir : 'dist' ,
1616} ) ;
1717
18+ // Custom SCSS compilation plugin for Rollup
19+ function addScssCompilationPlugins ( options ) {
20+ return options . map ( ( { inputFile, outputFile, loadPaths } ) => ( {
21+ name : `rollup custom plugin to generate ${ outputFile } ` ,
22+ generateBundle ( ) {
23+ try {
24+ const inputFileFullPath = `src/styles/@hashicorp/${ inputFile } ` ;
25+ const outputFileFullPath = `styles/@hashicorp/${ outputFile } ` ;
26+
27+ const result = sass . compile ( inputFileFullPath , {
28+ sourceMap : true ,
29+ loadPaths,
30+ } ) ;
31+
32+ // Emit the compiled CSS
33+ this . emitFile ( {
34+ type : 'asset' ,
35+ fileName : outputFileFullPath ,
36+ source : result . css ,
37+ } ) ;
38+
39+ // Emit the source map
40+ if ( result . sourceMap ) {
41+ this . emitFile ( {
42+ type : 'asset' ,
43+ fileName : `${ outputFileFullPath } .map` ,
44+ source : JSON . stringify ( result . sourceMap ) ,
45+ } ) ;
46+ }
47+ } catch ( error ) {
48+ this . error (
49+ `Failed to compile SCSS file "${ inputFile } ": ${ error . message } `
50+ ) ;
51+ }
52+ } ,
53+ } ) ) ;
54+ }
55+
1856const plugins = [
1957 // These are the modules that users should be able to import from your
2058 // addon. Anything not listed here may get optimized away.
21- addon . publicEntrypoints ( [
22- '**/*.{js,ts}' ,
23- 'index.js' ,
24- 'template-registry.js' ,
25- 'styles/@hashicorp/design-system-components.scss' ,
26- ] ) ,
59+ addon . publicEntrypoints ( [ '**/*.{js,ts}' , 'index.js' , 'template-registry.js' ] ) ,
2760
2861 // These are the modules that should get reexported into the traditional
2962 // "app" tree. Things in here should also be in publicEntrypoints above, but
@@ -50,16 +83,22 @@ const plugins = [
5083 // package names.
5184 addon . dependencies ( ) ,
5285
53- scss ( {
54- fileName : 'styles/@hashicorp/design-system-components.css' ,
55- includePaths : [
56- 'node_modules/@hashicorp/design-system-tokens/dist/products/css' ,
57- ] ,
58- } ) ,
59-
60- scss ( {
61- fileName : 'styles/@hashicorp/design-system-power-select-overrides.css' ,
62- } ) ,
86+ // We use a custom plugin for the Sass/SCSS compilation
87+ // so we can have multiple input and multiple outputs
88+ ...addScssCompilationPlugins (
89+ // files that will be compiled
90+ [
91+ {
92+ inputFile : 'design-system-components.scss' ,
93+ outputFile : 'design-system-components.css' ,
94+ loadPaths : [ 'node_modules/@hashicorp/design-system-tokens/dist' ] ,
95+ } ,
96+ {
97+ inputFile : 'design-system-power-select-overrides.scss' ,
98+ outputFile : 'design-system-power-select-overrides.css' ,
99+ } ,
100+ ]
101+ ) ,
63102
64103 // Ensure that standalone .hbs files are properly integrated as Javascript.
65104 addon . hbs ( ) ,
@@ -85,12 +124,20 @@ const plugins = [
85124 // to leave alone and keep in the published output.
86125 addon . keepAssets ( [ '**/*.css' , '**/*.scss' ] ) ,
87126
88- // Copy readme and license files into published package
89127 copy ( {
90128 targets : [
129+ // Copy readme and license files into published package
91130 { src : 'README.md' , dest : 'dist' } ,
92131 { src : 'LICENSE.md' , dest : 'dist' } ,
132+ // Copy sass mixins for consumers to use directly
133+ { src : 'src/styles/mixins' , dest : 'dist/styles' } ,
134+ // Copy sass components for consumers to use directly
135+ { src : 'src/styles/components' , dest : 'dist/styles' } ,
93136 ] ,
137+ hook : 'writeBundle' ,
138+ copySync : true ,
139+ copyOnce : true ,
140+ // verbose: true,
94141 } ) ,
95142] ;
96143
0 commit comments