awesome-webextension / webpack-target-webextension

WebExtension Target for Webpack 5. Supports code-splitting and HMR.
MIT License
46 stars 5 forks source link

How to exclude files from this plugin (unsafe context) #19

Closed fregante closed 3 years ago

fregante commented 3 years ago

I have a file that is being injected in the “unsafe context” via script tag in order to access the data/variables in the live website. This file is being executed outside the extension context and is not a content script.

How do you suggest I exclude it from this plugin? If it included import calls they’re now broken. Do you think it’s possible to disable the plugin on specific files, either via webpack config or plugin config?

The only option I’m aware of is to have a whole new webpack config/build specific to this file in order to exclude this plugin.

crimx commented 3 years ago

If it included import calls they’re now broken.

What did you mean? It was supposed to just work.

The only option I’m aware of is to have a whole new webpack config/build specific to this file in order to exclude this plugin.

I'm affraid so if that doesn't work. You can feed an array of configs to webpack so it should be alright.

fregante commented 3 years ago

Thank you for the quick answer!

If it included import calls they’re now broken.

What did you mean? It was supposed to just work.

runtime.getURL is not available on the web:

https://github.com/crimx/webpack-target-webextension/blob/d3445a43d2065288c302aa7aa1489cb106cb16c1/lib/webpack5/AutoPublicPathRuntimeModule.js#L46

so unless __webpack_public_path__ can be completely hardcoded (this workaround wouldn't work either) I don't think this injection would ever work, regardless of this plugin.

I think the only way to support such scripts would be to stop code splitting altogether. I think this is doable via an infinite splitChunks.minSize or via the more explicit LimitChunkCountPlugin

Jack-Works commented 3 years ago

We have this case too. We use a separate webpack config to pack it.