为了遵循CSP指令并避免'unsafe-eval'的错误,可以在webpack配置文件或babel配置文件中进行如下更改:
module.exports = {
// ...
devServer: {
contentSecurityPolicy: {
directives: {
scriptSrc: ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net", "nonce-randomString"]
}
}
},
// ...
}
module.exports = {
// ...
presets: [
'@babel/preset-env',
'@babel/preset-react',
],
plugins: [
'@babel/plugin-transform-runtime',
['istanbul', {
coverageProvider: 'v8'
}]
],
// ...
}