Browse Source

Added value stringifying for values passed to DefinePlugin.

Maciej Bukowski 6 years ago
parent
commit
0478df803b
1 changed files with 9 additions and 1 deletions
  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