DEV Community

Discussion on: Advanced Config for CRXJS Vite Plugin

Collapse
 
moshontongit profile image
Muslimin Ontong •

how to implement/create a background script?

Thread Thread
 
lichenglu profile image
Chenglu Li •

From my understanding, you will just need to specify your background script in your manifest file. Something like

{
  ...[this is your custom manifest, not the generated one in dist]
  "background": {
      "service_worker": "src/background/index.ts",
      "type": "module"
    }
}
Enter fullscreen mode Exit fullscreen mode

Then in the dist folder, if you check service-worker-loader.js, you will see your background script imported there. I have only tested it in the dev command, not sure if extra set up is needed for production build.

Thread Thread
 
jacksteamdev profile image
Jack Steam •

This is exactly correct! No extra setup needed for production.

Thread Thread
 
moinulmoin profile image
Moinul Moin •

this will work perfectly?