-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transformer-webextension: Cannot add Vue generated .css file to web_accessible_resources #7835
Comments
For anyone else reading this issue having a similar problem, here is the hacky temporary solution I came up with: I made this patch: diff --git a/node_modules/@parcel/transformer-webextension/lib/WebExtensionTransformer.js b/node_modules/@parcel/transformer-webextension/lib/WebExtensionTransformer.js
index 53cf1e0..1b015ad 100644
--- a/node_modules/@parcel/transformer-webextension/lib/WebExtensionTransformer.js
+++ b/node_modules/@parcel/transformer-webextension/lib/WebExtensionTransformer.js
@@ -195,6 +195,10 @@ async function collectDependencies(asset, program, ptrs, hot) {
let war = [];
for (let i = 0; i < program.web_accessible_resources.length; ++i) {
+ if (program.web_accessible_resources[i].startsWith('<generated>')) {
+ war.push(program.web_accessible_resources[i].substring(11));
+ continue;
+ }
// TODO: this doesn't support Parcel resolution
const globFiles = (await (0, _utils().glob)(_path().default.join(_path().default.dirname(filePath), program.web_accessible_resources[i]), fs, {})).map(fp => asset.addURLDependency(_path().default.relative(_path().default.dirname(filePath), fp), {
needsStableName: true, and I prefix the path of my resource with |
I think that since this is a file that Parcel generated from an entry point ( This is "easy" if the entry point is just the manifest: // Parcel should apply:
{
"content_scripts": [
{,
+ "css": ["content.css"],
"js": ["content.js"],
"matches": ["*://*/*"]
}
]
} but less easy if the injection is made via The non-completely-correct-but-easiest alternative would be to:
… however it doesn't seem to be natively supported, we'd need the equivalent of Webpack’s "style-loader": |
Possible solutions for usersUntested
|
This will now be fixed by #7050. In fact you shouldn't even need to reference the CSS in |
Good to hear that fixes it for scripts loaded via manifest.json but, as mentioned, anything injected via chrome.tabs.executeScript('content.js');
+ chrome.tabs.insertCSS('content.css'); that's unrelated to |
A bit off topic, but since it's a generated file, it should be possible but will probably not be easy. Importing |
Great! Small precision regarding my own solution: I inject the CSS file into the page from the content script by manually adding a |
Extensions should inject CSS via the manifest or via the insertCSS() function. Adding a link tag is not ideal because it requires the file to appear in |
🐛 Bug report
I'm trying to inject a Vue app into a web page from a web extension content script, but I can't load the Vue generated CSS file from its Asset URL into the page because Parcel doesn't let me put the generated file's name into the
web_accessible_resources
property of the manifest.🎛 Configuration (.babelrc, package.json, cli command)
.babelrc
🤔 Expected Behavior
Parcel should keep the
content.css
entry inweb_accessible_resources
.😯 Current Behavior
content.css
is removed fromweb_accessible_resources
in the manifest during the build.💁 Possible Solution
I don't really understand what the transformer does but I guess this TODO might have something to do with the fact the generated file is not found:
parcel/packages/transformers/webextension/src/WebExtensionTransformer.js
Line 176 in e294eaf
🔦 Context
I'm building a web extension that injects stuff into web pages using its content script.
One of the thing I want to inject is a Vue app, I managed to make the Vue app mount to the injected DOM element but one thing is missing: the components style.
I tracked down that a
content.css
file is generated by Vue but since I'm using a content script, Parcel understandably doesn't know how to inject it anywhere (normally it would inject it as a<link rel="stylesheet">
element in the generated HTML file).My solution was to try injecting the CSS file into the page myself using its Asset URL however when I try to add
content.css
to theweb_accessible_resources
in the manifest, it gets removed by Parcel.I also tried to add a placeholder
content.css
file in my source files but then Parcel complains about the non-unique bundle name.💻 Code Sample
manifest.json
content.js
App.vue
🌍 Your Environment
The text was updated successfully, but these errors were encountered: