E
E
Elvis2019-10-16 10:21:11
JavaScript
Elvis, 2019-10-16 10:21:11

How to make js import another js in chrome extention?

Hey!
Is it possible to somehow import the code of another js into js?
For example, there is a js file that contains basic scripts that are called in many other functions. When it's all in a single file, then everything is fine, but when this file becomes too large, then you already think about dividing the plugin's functionality into, so to speak, "modules". Each module is responsible for its own functionality. However, the same functions are called in each module.
Actually, I want to highlight all such functions in some kind of base.js and import them into other js files.
How can I do this if you consider that I have an extention, and not just code on the site.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2019-10-16
@Dr_Elvis

  1. Collect the code with some kind of bundler
    Choose.

S
Sergey c0re, 2019-10-16
@erge

Have you read this?
https://developer.chrome.com/extensions/content_sc...
Declaratively injected scripts are registered in the manifest under the "content_scripts" field. They can include JavaScript files, CSS files or both. All auto-run content scripts must specify match patterns.

{
"name": "My extension",
...
"content_scripts": [
{
"matches": [" http://*.nytimes.com/* "],
"css": ["myStyles.css"] ,
"js": ["contentScript.js"]
}
],
...
}

js array of strings Optional. The list of JavaScript files to be injected into matching pages. These are injected in the order they appear in this array.
same with background section
https://developer.chrome.com/extensions/background...
{
"name": "Awesome Test Extension",
...
"background": {
"scripts": [
"backgroundContextMenus.js ",
"backgroundOmniBox.js",
"backgroundOauth.js"
],
"persistent": false
},
...
}
PS:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question