8
0
Просмотр исходного кода

Merge pull request #1528 from ckeditor/t/1525

Other: Allowed dynamic environment configuration setup for docs by supporting variable injections via `snippetOptions.definitions`. Closes #1525.
Piotr Jasiun 7 лет назад
Родитель
Сommit
4ec0e26839
1 измененных файлов с 12 добавлено и 2 удалено
  1. 12 2
      scripts/docs/snippetadapter.js

+ 12 - 2
scripts/docs/snippetadapter.js

@@ -27,7 +27,8 @@ module.exports = function snippetAdapter( data ) {
 		entry: data.snippetSource.js,
 		outputPath,
 		language: snippetConfig.language,
-		production: data.options.production
+		production: data.options.production,
+		definitions: data.options.definitions || {}
 	} );
 
 	let promise;
@@ -83,6 +84,14 @@ module.exports = function snippetAdapter( data ) {
 };
 
 function getWebpackConfig( config ) {
+	// Stringify all definitions values. The `DefinePlugin` injects definition values as they are so we need to stringify them,
+	// so they will become real strings in the generated code. See https://webpack.js.org/plugins/define-plugin/ for more information.
+	const definitions = {};
+
+	for ( const definitionKey in config.definitions ) {
+		definitions[ definitionKey ] = JSON.stringify( config.definitions[ definitionKey ] );
+	}
+
 	return {
 		mode: config.production ? 'production' : 'development',
 
@@ -117,7 +126,8 @@ function getWebpackConfig( config ) {
 			new webpack.BannerPlugin( {
 				banner: bundler.getLicenseBanner(),
 				raw: true
-			} )
+			} ),
+			new webpack.DefinePlugin( definitions )
 		],
 
 		// Configure the paths so building CKEditor 5 snippets work even if the script