浏览代码

Changed template-comment-laoder to DefinePlugin. Changed `templateCommentLoaderConfig` to `definitions`.

Maciej Bukowski 6 年之前
父节点
当前提交
00535e3423
共有 2 个文件被更改,包括 4 次插入45 次删除
  1. 4 8
      scripts/docs/snippetadapter.js
  2. 0 37
      scripts/docs/template-comment-loader.js

+ 4 - 8
scripts/docs/snippetadapter.js

@@ -28,7 +28,7 @@ module.exports = function snippetAdapter( data ) {
 		outputPath,
 		language: snippetConfig.language,
 		production: data.options.production,
-		templateCommentLoaderConfig: data.options.templateCommentLoaderConfig || {}
+		definitions: data.options.definitions || {}
 	} );
 
 	let promise;
@@ -118,7 +118,8 @@ function getWebpackConfig( config ) {
 			new webpack.BannerPlugin( {
 				banner: bundler.getLicenseBanner(),
 				raw: true
-			} )
+			} ),
+			new webpack.DefinePlugin( config.definitions )
 		],
 
 		// Configure the paths so building CKEditor 5 snippets work even if the script
@@ -152,12 +153,7 @@ function getWebpackConfig( config ) {
 							} )
 						}
 					]
-				},
-				{
-					test: /\.js$/,
-					loader: require.resolve( './template-comment-loader' ),
-					query: config.templateCommentLoaderConfig
-				},
+				}
 			]
 		}
 	};

+ 0 - 37
scripts/docs/template-comment-loader.js

@@ -1,37 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* eslint-env node */
-
-/*
- * Matches `// @if param // someCode` and evaluates the `option.param`.
- * If the param is evaluated to true, then uncomments the code.
- *
- * Note: Use this only for conditional imports. Otherwise use the webpack define plugin.
- */
-module.exports = function templateCommentLoader( source, map ) {
-	source = source.replace( /\/\/ @if (!?[\w]+) \/\/(.+)/g, ( match, option, body ) => {
-		// this.query comes from the webpack loader config.
-		// Missing param in webpack loader config.
-		if ( !( option in this.query ) ) {
-			return match;
-		}
-
-		const optionValue = this.query[ option ];
-
-		// Do nothing when the option is falsy.
-		if ( !optionValue ) {
-			return match;
-		}
-
-		// Replace the option in body with evaluated value.
-		body = body.replace( new RegExp( option, 'g' ), this.query[ option ] );
-
-		// Uncomment the following code otherwise.
-		return `/* @if ${ option } */ ${ body }`;
-	} );
-
-	this.callback( null, source, map );
-};