Skip to content

Commit 41401b9

Browse files
committed
feat: Pass CSS Blocks options through Broccoli/Ember-CLI.
1 parent cb43511 commit 41401b9

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

packages/@css-blocks/broccoli/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from "path";
33

44
import { Analyzer, BlockCompiler, StyleMapping } from "@css-blocks/core";
55
import { TemplateTypes } from "@opticss/template-api";
6-
import { Optimizer } from "opticss";
6+
import { OptiCSSOptions, Optimizer } from "opticss";
77
import * as postcss from "postcss";
88
import * as readdir from "recursive-readdir";
99

@@ -14,6 +14,7 @@ export interface BroccoliOptions {
1414
output: string;
1515
analyzer: Analyzer<keyof TemplateTypes>;
1616
transport: {[key: string]: object};
17+
optimization?: Partial<OptiCSSOptions>;
1718
}
1819

1920
class BroccoliCSSBlocks extends BroccoliPlugin {
@@ -22,7 +23,7 @@ class BroccoliCSSBlocks extends BroccoliPlugin {
2223
private entry: string[];
2324
private output: string;
2425
private transport: { [key: string]: object };
25-
private optimizationOptions: object = {};
26+
private optimizationOptions: Partial<OptiCSSOptions>;
2627

2728
// tslint:disable-next-line:prefer-whatever-to-any
2829
constructor(inputNode: any, options: BroccoliOptions) {
@@ -32,6 +33,7 @@ class BroccoliCSSBlocks extends BroccoliPlugin {
3233
this.output = options.output;
3334
this.analyzer = options.analyzer;
3435
this.transport = options.transport;
36+
this.optimizationOptions = options.optimization || {};
3537

3638
if (!this.output) {
3739
throw new Error("CSS Blocks Broccoli Plugin requires an output file name.");

packages/@css-blocks/ember-cli/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ module.exports = {
3838
included(app) {
3939

4040
this._super.included.apply(this, arguments);
41+
4142
let options = app.options["css-blocks"] || {};
43+
let parserOpts = options.parserOpts || {};
44+
let analysisOpts = options.analysisOpts || {};
45+
let optimizerOpts = options.optimization || {};
4246

4347
// Ember-cli is *mostly* used with Glimmer. However, it can technically be
4448
// configured to use other template types. Here we default to the Glimmer
4549
// analyzer, but if a `getAnalyzer` function is provided we defer to the
4650
// user-supplied analyzer.
4751
let analyzer = options.getAnalyzer ?
4852
options.getAnalyzer(app) :
49-
new GlimmerAnalyzer(new Project(app.project.root, MODULE_CONFIG));
53+
new GlimmerAnalyzer(new Project(app.project.root, MODULE_CONFIG), parserOpts, analysisOpts);
5054

5155
// TODO: Better options validation.
5256
if (typeof options.entry !== "string") {
@@ -66,7 +70,8 @@ module.exports = {
6670
entry: [options.entry],
6771
output: options.output,
6872
analyzer,
69-
transport: this.transport // I hate shared memory...
73+
transport: this.transport, // I hate shared memory...
74+
optimization: optimizerOpts,
7075
});
7176

7277
// Remove all source css-blocks stylesheets

packages/@css-blocks/playground/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ module.exports = function(environment) {
77
};
88

99
return ENV;
10-
};
10+
};

packages/@css-blocks/playground/ember-cli-build.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
const GlimmerApp = require('@glimmer/application-pipeline').GlimmerApp;
44

55
module.exports = function(defaults) {
6-
76
let app = new GlimmerApp(defaults, {
8-
97
'css-blocks': {
108
entry: "GlimmerTest",
11-
output: "src/ui/styles/css-blocks.css"
9+
output: "src/ui/styles/css-blocks.css",
10+
parserOpts: {},
11+
analysisOpts: {},
12+
optimization: {
13+
rewriteIdents: true,
14+
mergeDeclarations: true,
15+
removeUnusedStyles: true,
16+
conflictResolution: true,
17+
enabled: process.env.EMBER_ENV !== 'development',
18+
},
1219
}
13-
1420
});
15-
1621
return app.toTree();
17-
};
22+
};

0 commit comments

Comments
 (0)