Skip to content

Commit

Permalink
feat(admin-ui): Export minified theme css for ui extensions dev
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Mar 16, 2020
1 parent fd7f9d1 commit 99073c9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ng": "ng",
"start": "node scripts/set-version.js && ng serve",
"build:app": "ng build --prod",
"build": "node scripts/copy-package-json.js && node scripts/set-version.js && node scripts/build-public-api.js && ng build vendure-admin-lib --prod",
"build": "node scripts/copy-package-json.js && node scripts/set-version.js && node scripts/build-public-api.js && ng build vendure-admin-lib --prod && node scripts/compile-styles.js",
"watch": "ng build --watch=true",
"test": "ng test --watch=false --browsers=ChromeHeadlessCI --progress=false",
"lint": "tslint --fix",
Expand Down Expand Up @@ -35,8 +35,8 @@
"@ng-select/ng-select": "^3.7.2",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@vendure/common": "^0.9.0",
"@vendure/ui-devkit": "^0.9.0",
"@vendure/common": "^0.10.0",
"@vendure/ui-devkit": "^0.10.0",
"@webcomponents/custom-elements": "^1.2.4",
"apollo-angular": "^1.8.0",
"apollo-cache-inmemory": "^1.6.5",
Expand Down
37 changes: 37 additions & 0 deletions packages/admin-ui/scripts/compile-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path');
const fs = require('fs');
const sass = require('sass');

// Compiles the Admin UI styles into a css file for consumption by
// non-Angular ui extensions.
const outFile = path.join(__dirname, '../package/static/theme.min.css');
const result = sass.renderSync({
file: path.join(__dirname, '../src/lib/static/styles/theme.scss'),
importer,
includePaths: [path.join(__dirname, '../src/lib/static/styles')],
outputStyle: 'compressed',
outFile,
});

fs.writeFileSync(outFile, result.css, 'utf8');


function importer(url, prev, done) {
let file = url;
// Handle the imports prefixed with ~
// which are usually resolved by Webpack.
if (/^~@clr/.test(url)) {
const sansTilde = url.substr(1);
const fullPath = path.extname(sansTilde) === '' ? sansTilde + '.scss' : sansTilde;
file = require.resolve(fullPath);
}

// Ignore the contents of the Angular-specific
// library styles which are not needed in external
// apps.
if (/^~@(ng-select|angular)/.test(url)) {
return false;
}

return { file };
}
6 changes: 1 addition & 5 deletions packages/admin-ui/src/lib/static/styles/styles.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Clarity Component SCSS
@import "~@clr/ui/src/main";
@import "theme";
@import "~@clr/icons/clr-icons.min.css";

@import "theme/theme";

@import "~@ng-select/ng-select/themes/default.theme.css";
@import '~@angular/cdk/overlay-prebuilt.css';
6 changes: 6 additions & 0 deletions packages/admin-ui/src/lib/static/styles/theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is used to compile the theme.min.css file which can be used
// by ui extensions to get the same styles as the main app.

// Clarity Component SCSS
@import "~@clr/ui/src/main";
@import "theme/theme";

0 comments on commit 99073c9

Please sign in to comment.