compile-styles.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const path = require('path');
  2. const fs = require('fs');
  3. const sass = require('sass');
  4. // Compiles the Admin UI styles into a css file for consumption by
  5. // non-Angular ui extensions.
  6. const outFile = path.join(__dirname, '../package/static/theme.min.css');
  7. const result = sass.renderSync({
  8. file: path.join(__dirname, '../src/lib/static/styles/ui-extension-theme.scss'),
  9. importer,
  10. includePaths: [
  11. path.join(__dirname, '../src/lib/static/styles'),
  12. path.join(__dirname, '../src/lib/static/fonts'),
  13. path.join(__dirname, '../node_modules'),
  14. path.join(__dirname, '../../../node_modules'),
  15. ],
  16. outputStyle: 'compressed',
  17. outFile,
  18. });
  19. fs.writeFileSync(outFile, result.css, 'utf8');
  20. function importer(url, prev) {
  21. let file = url;
  22. // Handle the imports prefixed with
  23. // which are usually resolved by Webpack.
  24. if (/^~@clr/.test(url)) {
  25. const sansTilde = url.substr(1);
  26. const fullPath = path.extname(sansTilde) === '' ? sansTilde + '.scss' : sansTilde;
  27. file = require.resolve(fullPath);
  28. }
  29. // Ignore the contents of the Angular-specific
  30. // library styles which are not needed in external
  31. // apps.
  32. if (/^~@(ng-select|angular)/.test(url)) {
  33. return null;
  34. }
  35. return { file };
  36. }