vitesse-webext icon indicating copy to clipboard operation
vitesse-webext copied to clipboard

Keep contentScripts individual

Open jacktang opened this issue 3 years ago • 6 comments

Hi,

I find the vitesse-webext project contains only one index.global.js under contentScripts. If I want to keep contentScript individual, what should I do?

There are some build configs in vite.config.content.ts file, but I not so familiar with vite, could you please give me some example?

jacktang avatar Dec 20 '21 08:12 jacktang

I've tried edit the build config in vite.config.ts

  build: {
    outDir: r('extension/dist'),
    emptyOutDir: false,
    sourcemap: isDev ? 'inline' : false,
    // https://developer.chrome.com/docs/webstore/program_policies/#:~:text=Code%20Readability%20Requirements
    terserOptions: {
      mangle: false,
    },
    rollupOptions: {
      input: {
        background: r('src/background/index.html'),
        options: r('src/options/index.html'),
        popup: r('src/popup/index.html'),
        'contentScripts/parser': r('src/contentScripts/parser/*.ts'),
      },
    },
  },

but no luck, it didn't work at all :(

jacktang avatar Dec 20 '21 11:12 jacktang

content-scripts were defined at vite.config.content.ts for now.

tmkx avatar Dec 20 '21 12:12 tmkx

@tmkx yep, I also tried vite.config.content.ts

    rollupOptions: {
      output: {
        entryFileNames: 'index.global.js',
        extend: true,
      },
      input: {
         'parser': r('src/contentScripts/parser/*.ts'),
      },
    },

But it didn't copy the ts files under parser dir.

jacktang avatar Dec 20 '21 13:12 jacktang

Let clear the question again. I want to keep vue component in current index.ts and keep other content scripts in individual files because they will be inserted into tab page in different life cycle and with different functions.

jacktang avatar Dec 20 '21 14:12 jacktang

it does not support multi entrypoints(or glob) yet. There are some ways to do that:

  1. bundle all components into contentScripts/index.ts, and use them at your needs
  2. copy vite.config.content.ts, and change build.lib.entry, manifest.ts to add a new content-script file

tmkx avatar Dec 20 '21 16:12 tmkx

@tmkx it would be really great to have a working example of that, as I'm a complete vite.config noob

louisremi avatar May 23 '23 15:05 louisremi