Chrome扩展程序:尝试在内容脚本中使用require.js

时间:2018-04-18 01:55:55

标签: javascript google-chrome google-chrome-extension

我试图解决的问题:

我在content.js:179 Uncaught ReferenceError: require is not defined号线上遇到var wordnet =require('../node_modules/wordnet');并且为了克服此错误,我尝试使用require.js。但是,我不确定如何在我的内容脚本中包含此脚本。 我已经在manifest.json中包含了require.js:

"content_scripts": [
{
  "matches": [
    "https://www.reddit.com/r/design_critiques/*"
  ],
  "run_at": "document_end",
  "js": [
    "scripts/content.js",
    "scripts/require.js"
  ],
  "css": [
    "stylesheets/content.css"
  ]
}]

1 个答案:

答案 0 :(得分:0)

此问题的解决方案变得微不足道:在require.js之前切换脚本以加载content.js

"content_scripts": [
{
  "matches": [
    "https://www.reddit.com/r/design_critiques/*"
  ],
  "run_at": "document_end",
  "js": [
    "scripts/require.js",
    "scripts/content.js"
  ],
  "css": [
    "stylesheets/content.css"
  ]
}]