VUE3 CSP 问题在"new Function"



我使用vue 3.1.5和vue cli 4.5.0的特殊应用程序,如chrome扩展,得到以下错误

"拒绝将字符串作为JavaScript计算,因为'unsafe-eval'在以下内容安全策略指令中不允许作为脚本的来源:"script-src chrome://resources 'self'"

在runtime-core.esm-bundler.js

function compileToFunction(source, options = {}) {
...
// compile
const { code } = baseCompile(source, options);
// evaluate function
const msg = new Function(return ${code})();
...
}

是否有办法构建与CSP兼容的ve3应用程序?

我已经尝试了这些选项

  • config.resolve.alias。集(vue美元,vue/dist/vue.esm.js);
  • configureWebpack: {devtool: inline-source-map}
  • configureWebpack: {devtool: false}

是否有其他选项或我错过了什么?

问候,帕维尔

是的,Vue使用new Function进行模板的运行时编译。
如果您不希望在CSP中允许'unsafe-eval',则必须将模板预编译为呈现函数。

最新更新