compile-styles.js 1.1 KB

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