Webpack require expression external

前端 未结 1 492
生来不讨喜
生来不讨喜 2021-01-24 15:38

I have an expression require which should get resolved in runtime but I can’t get my head around the webpack config for this simple example:

import something fro         


        
相关标签:
1条回答
  • 2021-01-24 16:12

    For anyone wondering: you can solve it with this plugin:

    function() {
      this.parser.plugin('call require', function(expr) {
        if (expr.arguments.length !== 1) {
          return;
        }
    
        const param = this.evaluateExpression(expr.arguments[0]);
        if (!param.isString() && !param.isConditional()) {
          return true;
        }
      });
    }
    

    Anything that cannot be resolved by webpack will be left as is.

    0 讨论(0)
提交回复
热议问题