Explorar el Código

Extended the snippetAdapter to allow customization of SASS variables by loading a 3rd-party SASS file before compilation.

Aleksander Nowodzinski hace 8 años
padre
commit
0860cd3da0
Se han modificado 1 ficheros con 13 adiciones y 2 borrados
  1. 13 2
      scripts/docs/snippet-adapter/snippetadapter.js

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

@@ -16,12 +16,18 @@ 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 );
+	let sassImportPath;
+
+	if ( snippetConfig.sassImportPath ) {
+		sassImportPath = path.join( path.dirname( data.snippetSource.js ), snippetConfig.sassImportPath );
+	}
 
 	const webpackConfig = getWebpackConfig( {
 		entry: data.snippetSource.js,
 		outputPath,
 		language: snippetConfig.language,
-		minify: data.options.production
+		minify: data.options.production,
+		sassImportPath
 	} );
 
 	return runWebpack( webpackConfig )
@@ -107,7 +113,12 @@ function getWebpackConfig( config ) {
 									minimize: config.minify
 								}
 							},
-							'sass-loader'
+							{
+								loader: 'sass-loader',
+								options: {
+									data: config.sassImportPath ? `@import '${ config.sassImportPath }';` : ''
+								}
+							}
 						]
 					} )
 				}