瀏覽代碼

Docs: Don't include CSS files which were not generated by Webpack. [skip ci]

Piotrek Koszuliński 8 年之前
父節點
當前提交
e6a521792b
共有 1 個文件被更改,包括 13 次插入5 次删除
  1. 13 5
      scripts/docs/snippet-adapter/snippetadapter.js

+ 13 - 5
scripts/docs/snippet-adapter/snippetadapter.js

@@ -15,26 +15,34 @@ const BabelMinifyPlugin = require( 'babel-minify-webpack-plugin' );
 
 module.exports = function snippetAdapter( data ) {
 	const snippetConfig = readSnippetConfig( data.snippetSource.js );
+	const outputPath = path.join( data.outputPath, data.snippetPath );
 
 	const webpackConfig = getWebpackConfig( {
 		entry: data.snippetSource.js,
-		outputPath: path.join( data.outputPath, data.snippetPath ),
+		outputPath,
 		language: snippetConfig.language,
 		minify: data.options.production
 	} );
 
 	return runWebpack( webpackConfig )
 		.then( () => {
+			const wasCSSGenerated = fs.existsSync( path.join( outputPath, 'snippet.css' ) );
+			const cssFiles = [
+				path.join( data.basePath, 'assets', 'snippet-styles.css' )
+			];
+
+			// CSS may not be generated by Webpack if a snippet's JS file didn't import any SCSS files.
+			if ( wasCSSGenerated ) {
+				cssFiles.unshift( path.join( data.relativeOutputPath, data.snippetPath, 'snippet.css' ) );
+			}
+
 			return {
 				html: fs.readFileSync( data.snippetSource.html ),
 				assets: {
 					js: [
 						path.join( data.relativeOutputPath, data.snippetPath, 'snippet.js' )
 					],
-					css: [
-						path.join( data.relativeOutputPath, data.snippetPath, 'snippet.css' ),
-						path.join( data.basePath, 'assets', 'snippet-styles.css' )
-					]
+					css: cssFiles
 				}
 			};
 		} );