使用 Webpack 编译后重新加载 Chrome 扩展时出现此错误:
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".
at new Function (<anonymous>)
at evalExpression (compiler.js:33919)
at jitStatements (compiler.js:33937)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._interpretOrJit (compiler.js:34520)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._compileTemplate (compiler.js:34448)
at compiler.js:34347
at Set.forEach (<anonymous>)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._compileComponents (compiler.js:34347)
at compiler.js:34217
at Object.then (compiler.js:474)
我的 CSP 授予unsafe-eval
允许。
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
我怎样才能允许使用eval()
在我的代码中(因为 Webpack 使用它来生成源映射)?
我花了几个小时,但您可能想要做的是更改 webpack 使用的源映射的样式。
默认情况下它使用 eval。
https://webpack.js.org/configuration/devtool/ https://webpack.js.org/configuration/devtool/
我将其添加到我的 webpack.config.js 中:
devtool: 'cheap-module-source-map'
做到这一点的秘诀是找出原因webpack --mode development
有错误并且webpack --mode production
didn't.
另外,我使用的是 React 而不是 Polymer,但我很确定这仍然适用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)