Skip to content
Discussion options

You must be logged in to vote

the question has been sloved. becase my scene is simple. so i write a simple custom loader to solve the question

/**
 *  Conditional Loader
 */
module.exports = function (source, context) {
  const options = context || {};

  const regex = /\/\/\s*#ifdef\s+([A-Z0-9_| ]+)[\r\n]+([\s\S]*?)\/\/\s*#endif/g;

  const result = source.replace(regex, (match, expression, content) => {
    const keys = expression.split('||').map(s => s.trim());

    const isMatched = keys.some(key => !!options[key]);

    if (isMatched) {
      return content;
    }
    return '';
  });

  return result;
};

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kibuniverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant