@@ -81,7 +81,7 @@ export class CSSBlocksApplicationPlugin extends Filter {
81
81
}
82
82
debug ( `Loaded ${ blocksUsed . size } blocks.` ) ;
83
83
debug ( `Loaded ${ optimizer . analyses . length } analyses.` ) ;
84
- let cssFileName = cssBlocksOutputFilename ( this . appName , this . cssBlocksOptions ) ;
84
+ let cssFileName = cssBlocksOutputFilename ( this . cssBlocksOptions ) ;
85
85
let sourceMapFileName = `${ cssFileName } .map` ;
86
86
let optLogFileName = `${ cssFileName } .optimization.log` ;
87
87
let optimizationResult = await optimizer . optimize ( cssFileName ) ;
@@ -153,20 +153,32 @@ export class CSSBlocksStylesProcessorPlugin extends Plugin {
153
153
previousSourceTree : FSTree ;
154
154
cssBlocksOptions : ResolvedCSSBlocksEmberOptions ;
155
155
constructor ( appName : string , cssBlocksOptions : ResolvedCSSBlocksEmberOptions , inputNodes : InputNode [ ] ) {
156
- super ( inputNodes ) ;
156
+ super ( inputNodes , { persistentOutput : true } ) ;
157
157
this . appName = appName ;
158
158
this . previousSourceTree = new FSTree ( ) ;
159
159
this . cssBlocksOptions = cssBlocksOptions ;
160
160
}
161
161
async build ( ) {
162
+ let mergeIntoAppStyles = true ;
162
163
if ( this . cssBlocksOptions . output ) {
163
164
// if the output filename is explicitly declared, we don't merge it with
164
165
// the application styles.
165
- return ;
166
+ mergeIntoAppStyles = false ;
166
167
}
167
168
// Read the optimized CSS Blocks styles file, generated previously by the CSSBlocksApplicationPlugin.
168
- let stylesheetPath = cssBlocksOutputFilename ( this . appName , this . cssBlocksOptions ) ;
169
- let entries = this . input . entries ( "." , { globs : [ stylesheetPath ] } ) ;
169
+ let stylesheetPath = cssBlocksOutputFilename ( this . cssBlocksOptions ) ;
170
+ let applicationStylesheetPath = `app/styles/app.css` ;
171
+ if ( ! this . input . existsSync ( applicationStylesheetPath ) ) {
172
+ mergeIntoAppStyles = false ;
173
+ debug ( `No app/styles/app.css file found. Blocks content is in ${ stylesheetPath } . The application should handle it.` ) ;
174
+ }
175
+ let globs : Array < string > ;
176
+ if ( mergeIntoAppStyles ) {
177
+ globs = [ stylesheetPath , applicationStylesheetPath ] ;
178
+ } else {
179
+ globs = [ stylesheetPath ] ;
180
+ }
181
+ let entries = this . input . entries ( "." , { globs} ) ;
170
182
let currentFSTree = FSTree . fromEntries ( entries ) ;
171
183
let patch = this . previousSourceTree . calculatePatch ( currentFSTree ) ;
172
184
if ( patch . length === 0 ) {
@@ -175,19 +187,26 @@ export class CSSBlocksStylesProcessorPlugin extends Plugin {
175
187
this . previousSourceTree = currentFSTree ;
176
188
}
177
189
178
- const blocksFileEntry = entries [ 0 ] ;
179
-
180
190
// And read the application CSS that was previously built by Ember and ignored by CSS Blocks.
181
- const blocksFileContents = this . input . readFileSync ( blocksFileEntry . relativePath , { encoding : "utf8" } ) ;
182
- const appCssFileContents = this . input . readFileSync ( "app/styles/app.css" , { encoding : "utf8" } ) ;
191
+ const blocksFileContents = this . input . readFileSync ( stylesheetPath , { encoding : "utf8" } ) ;
192
+ let outputContents : string ;
193
+ let outputPath : string ;
194
+ if ( mergeIntoAppStyles ) {
195
+ const appCssFileContents = this . input . readFileSync ( applicationStylesheetPath , { encoding : "utf8" } ) ;
196
+ outputContents = `${ appCssFileContents } \n${ blocksFileContents } ` ;
197
+ outputPath = applicationStylesheetPath ;
198
+ } else {
199
+ outputContents = blocksFileContents ;
200
+ outputPath = stylesheetPath ;
201
+ }
183
202
184
203
// Now, write out the combined result of the application CSS and CSS Blocks contents.
185
- this . output . mkdirSync ( "app/styles" , { recursive : true } ) ;
186
- this . output . writeFileSync ( "app/styles/app.css" , ` ${ appCssFileContents } \n ${ blocksFileContents } ` ) ;
204
+ this . output . mkdirSync ( path . dirname ( outputPath ) , { recursive : true } ) ;
205
+ this . output . writeFileSync ( outputPath , outputContents ) ;
187
206
}
188
207
}
189
208
190
- function cssBlocksOutputFilename ( appName , options : ResolvedCSSBlocksEmberOptions ) {
209
+ function cssBlocksOutputFilename ( options : ResolvedCSSBlocksEmberOptions ) {
191
210
let outputName = options . output || "css-blocks.css" ;
192
- return `${ appName } /styles/${ outputName } ` ;
211
+ return `app /styles/${ outputName } ` ;
193
212
}
0 commit comments