1
2 Comments

Do you use NPM modules in your extension? How?

Do you just use a background.js file and a contentscripts file to build your extension? if not then how do you do it?

  1. 2

    yup I import a few packages including React.js .

    What you want is a "bundler", it's a tool that frontend devs use to get their code ready to ship in a browser. The bundler compiles and bundles all your scripts into a single generated "dist" JS file. Then you put that dist JS into your extension bundle, and that file is your extension's content script or background script.

    ESBuild is a good choice for this (there's other choices like Webpack, Parcel, etc). Here's my ESBuild script:

    require('esbuild').build({
        entryPoints: [
            'src/extension/contentMain.ts',
            'src/extension/backgroundMain.ts',
            'src/extension/popupMain.tsx',
        ],
        sourcemap: 'external',
        bundle: true,
        platform: 'browser',
        outdir: 'chrome-extension/dist',
    
    })
    .catch(err => {
        console.log(err.stack || err);
    });
    
Trending on Indie Hackers
I talked to 8 SaaS founders, these are the most common SaaS tools they use 20 comments What are your cold outreach conversion rates? Top 3 Metrics And Benchmarks To Track 19 comments How I Sourced 60% of Customers From Linkedin, Organically 13 comments Hero Section Copywriting Framework that Converts 3x 12 comments Promptzone - first-of-its-kind social media platform dedicated to all things AI. 8 comments How to create a rating system with Tailwind CSS and Alpinejs 7 comments