ui: Change approach to loading debug.css (#12242)

We need a way to load certain CSS based on the environment you are viewing, i.e. we have debug CSS that we use for our Eng Documentation and various other DX utilities that shouldn't be compiled into our production or test builds.

Previously we would compile two entirely different CSS files (app and debug) and the load one or the other depending on which environment you were in.

This approach just empties out the debug.css file in certain environments (prod/test) which means we can just import that file from app. When in staging/development this imports the contents of debug.css (quite a bit of CSS) whereas when building for production/test this debug.css is emptied out during the build process.

There is a slight little hack in order to have this work, we import _debug.scss which imports the debug.scss file. I couldn't for the life of me figure out how to have broccoli empty out a file during the build process, so instead we essentially copy over debug.scss during dev and create an empty file during prod to _debug.scss.

When using make build to build an artifact for production CSS remains at ~58kb (during dev its a lot bigger than this)
pull/12259/head
John Cowen 3 years ago committed by GitHub
parent a6f51d8c1b
commit 39f15306d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,8 +5,8 @@ all: build
deps: ../../node_modules clean deps: ../../node_modules clean
# incase we ever need to clean anything again
clean: clean:
rm -rf ./tmp
build-staging: deps build-staging: deps
yarn run build:staging yarn run build:staging
@ -17,6 +17,9 @@ build-ci: deps
build: deps build: deps
yarn run build yarn run build
build-debug:
BROCCOLI_DEBUG=* $(MAKE) build
start: deps start: deps
yarn run start yarn run start

@ -15,3 +15,6 @@
@import 'icons'; @import 'icons';
/* global control of themeable components */ /* global control of themeable components */
@import 'themes'; @import 'themes';
/* debug only, this is empty during a production build */
/* but uses the contents of ./debug.scss during dev */
@import '_debug';

@ -1,4 +1,3 @@
@import './app';
@import './base/icons/debug'; @import './base/icons/debug';
@import 'prism-coldark-dark'; @import 'prism-coldark-dark';

@ -97,14 +97,8 @@ module.exports = function(defaults, $ = process.env) {
// exclude docfy // exclude docfy
'@docfy/ember' '@docfy/ember'
]; ];
} else {
// add debug css is we are not in test or production environments
outputPaths.app = {
css: {
'debug': '/assets/debug.css'
}
}
} }
if(['production'].includes(env)) { if(['production'].includes(env)) {
// everything apart from production is 'debug', including test // everything apart from production is 'debug', including test
// which means this and everything it affects is never tested // which means this and everything it affects is never tested

@ -3,6 +3,8 @@
const Funnel = require('broccoli-funnel'); const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees'); const mergeTrees = require('broccoli-merge-trees');
const writeFile = require('broccoli-file-creator');
const read = require('fs').readFileSync;
module.exports = { module.exports = {
name: require('./package').name, name: require('./package').name,
@ -12,15 +14,18 @@ module.exports = {
* @import 'app-name/components/component-name/index.scss' * @import 'app-name/components/component-name/index.scss'
*/ */
treeForStyles: function(tree) { treeForStyles: function(tree) {
let debug = read(`${this.project.root}/app/styles/debug.scss`);
if (['production', 'test'].includes(process.env.EMBER_ENV)) {
debug = '';
}
return this._super.treeForStyles.apply(this, [ return this._super.treeForStyles.apply(this, [
mergeTrees( mergeTrees([
(tree || []).concat([ writeFile(`_debug.scss`, debug),
new Funnel(`${this.project.root}/app/components`, { new Funnel(`${this.project.root}/app/components`, {
destDir: `app/components`, destDir: `app/components`,
include: ['**/*.scss'], include: ['**/*.scss'],
}), }),
]) ]),
),
]); ]);
}, },
}; };

@ -8,9 +8,7 @@ module.exports = ({ appName, environment, rootURL, config }) => `
<link rel="icon" href="${rootURL}assets/favicon.svg" type="image/svg+xml"> <link rel="icon" href="${rootURL}assets/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="${rootURL}assets/apple-touch-icon.png"> <link rel="apple-touch-icon" href="${rootURL}assets/apple-touch-icon.png">
<link integrity="" rel="stylesheet" href="${rootURL}assets/vendor.css"> <link integrity="" rel="stylesheet" href="${rootURL}assets/vendor.css">
<link integrity="" rel="stylesheet" href="${rootURL}assets/${ <link integrity="" rel="stylesheet" href="${rootURL}assets/${appName}.css">
!['test', 'production'].includes(environment) ? 'debug' : appName
}.css">
${ ${
environment === 'test' ? `<link rel="stylesheet" href="${rootURL}assets/test-support.css">` : `` environment === 'test' ? `<link rel="stylesheet" href="${rootURL}assets/test-support.css">` : ``
} }

Loading…
Cancel
Save