chrome-extension-cli icon indicating copy to clipboard operation
chrome-extension-cli copied to clipboard

Use for more ambitious Chrome Extensions...

Open mercutiomontague opened this issue 1 year ago • 1 comments

Is it possible to use this for Chrome Extensions that use more than a single content script? What if I wanted to add an npm package?

mercutiomontague avatar Apr 11 '23 21:04 mercutiomontague

I had the same use case and I've just discovered this project. So as far as I understand you can do it.

The idea is all the content scripts you mention in your webpack.config.js gets merged into one file under the default name contentScript.js. You can also see that by looking at the build directory.

If you have multiple content scripts and you want to merge them together, all you need to do is 👇

// webpack.config.js

const config = (env, argv) =>
  merge(common, {
    entry: {
      contentScript: [PATHS.src + '/contentScript1.js', PATHS.src + '/contentScript2.js'], // <--- See the list
      background: PATHS.src + '/background.js',
    },
    devtool: argv.mode === 'production' ? false : 'source-map',
  });

Once you build with this config, you'll be able to see in your build directory that your contentScript1 & contentScript2 were merged into contentScript.js. Notice that we didn't even touch content_scripts key in the manifest.json.

andreyuhai avatar Apr 17 '23 23:04 andreyuhai