【发布时间】:2018-07-19 14:51:01
【问题描述】:
问题在于在编译代码中使用 eval 的 Webpack。因此,Chrome 扩展程序和 Firefox 插件不起作用,因为它需要 CSP 属性中的“unsafe-eval”指令,这是不允许的。我将 Vue.js 用于前端,webpack 和 vue-loader 用于构建过程
Package.json 文件
{
"webpack": "^3.10.0",
"babel-core": "^6.18.2",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-2": "^6.24.1",
"file-loader": "^0.9.0",
"style-loader": "^0.18.2",
"vue-loader": "^10.0.2"
}
这是 webpack 的 build.js 文件中包含的内容。 Function 构造函数和 eval 的用法。
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}
// Another method of build
function setImmediate(callback) {
// Callback can either be a function or a string
if (typeof callback !== "function") {
callback = new Function("" + callback);
}
这是web-ext lint 检查插件问题的结果
Code Message File Line Column
DANGEROUS_EVAL The Function build.js 433 11
constructor is
eval.
DANGEROUS_EVAL eval can be build.js 433 43
harmful.
DANGEROUS_EVAL The Function build.js 8814 20
constructor is
eval.
有什么方法我可以在没有 Webpack 的情况下使用 build 进行构建,因为从 Vue 方面支持使用 Vue 的运行时代码,但 Webpack 没有按照 CSP 策略构建的平面。请帮忙,因为我不需要特别是构建中的这一行
【问题讨论】:
标签: google-chrome-extension webpack vue.js firefox-addon