Parcourir la source

Added value stringifying for values passed to DefinePlugin.

Maciej Bukowski il y a 6 ans
Parent
commit
0478df803b
1 fichiers modifiés avec 9 ajouts et 1 suppressions
  1. 9 1
      scripts/docs/snippetadapter.js

+ 9 - 1
scripts/docs/snippetadapter.js

@@ -84,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',
 
@@ -119,7 +127,7 @@ function getWebpackConfig( config ) {
 				banner: bundler.getLicenseBanner(),
 				raw: true
 			} ),
-			new webpack.DefinePlugin( config.definitions )
+			new webpack.DefinePlugin( definitions )
 		],
 
 		// Configure the paths so building CKEditor 5 snippets work even if the script