简体   繁体   中英

how to include other javascript files in content js file of chrome extension?

I have made a chrome extension ! it gives css and xpath on click at any point on the web page. I have include my js files for calculating xpath and css in content scripts of chrome extension. Is there any way by which i can include only on js file in content script and import all other js files inside that one js file ?

I tried the require and export which i got when i searched but its not working.

var xPath = {};
xPath.get_xpath=function(ele)
{
}
export xpath = xpath;

and i tried to import it using require like this :

var calculate = require("xpath");

but its showing error export not defined.

You should use the following:

var xPath = {};
xPath.get_xpath = function(ele) {
}
module.exports = xPath;

Note that Chrome doesn't support JS modules, so you need to use browserify builder.

As an example, check my open source extension: Clipboardy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM