compile-styles.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. ],
  15. outputStyle: 'compressed',
  16. outFile,
  17. });
  18. fs.writeFileSync(outFile, result.css, 'utf8');
  19. function importer(url, prev) {
  20. let file = url;
  21. // Handle the imports prefixed with ~
  22. // which are usually resolved by Webpack.
  23. if (/^~@clr/.test(url)) {
  24. const sansTilde = url.substr(1);
  25. const fullPath = path.extname(sansTilde) === '' ? sansTilde + '.scss' : sansTilde;
  26. file = require.resolve(fullPath);
  27. }
  28. // Ignore the contents of the Angular-specific
  29. // library styles which are not needed in external
  30. // apps.
  31. if (/^~@(ng-select|angular)/.test(url)) {
  32. return null;
  33. }
  34. return { file };
  35. }