Skip to content

Commit

Permalink
Merge pull request #1528 from ckeditor/t/1525
Browse files Browse the repository at this point in the history
Other: Allowed dynamic environment configuration setup for docs by supporting variable injections via `snippetOptions.definitions`. Closes #1525.
  • Loading branch information
Piotr Jasiun authored Feb 15, 2019
2 parents bcc8642 + 0478df8 commit 4ec0e26
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/docs/snippetadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ec0e26

Please sign in to comment.