1
0

compile-styles.js 1.2 KB

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