-
Notifications
You must be signed in to change notification settings - Fork 50
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
Specifying styles to content scripts #1
Comments
I did not think about such a case, as a temporary solution I can offer: {
"content_scripts": [
{
"matches": ["..."],
"js": ["src/pages/content/index.js"],
"css": ["assets/content.css"]
}
]
}
build: {
rollupOptions: {
input: {
background: resolve(pagesDir, "background", "index.ts"),
content: resolve(pagesDir, "content", "index.ts"),
popup: resolve(pagesDir, "popup", "index.html"),
},
output: {
entryFileNames: (chunk) => `src/pages/${chunk.name}/index.js`,
chunkFileNames: `assets/[name].js`,
// https://github.com/vitejs/vite/issues/378#issuecomment-768816653
assetFileNames: `assets/[name].[ext]`
},
},
}, import styles in import type { IStorage } from "src/types";
import "./styles.css";
chrome.storage.sync.get({ count: 0 } as IStorage, ({ count }: IStorage) => {
console.log("content", count);
}); Output:
I will think of a more beautiful solution, thanks for describing the problem :) |
What if I wanted to use an SCSS file instead? |
https://vitejs.dev/guide/features.html#css-pre-processors npm add -D sass and that's it, you can use |
Unfortunately, Vite copies the SCSS rather than running it through Sass to get the CSS file |
import type { IStorage } from "src/types";
import "./styles.scss";
chrome.storage.sync.get({ count: 0 } as IStorage, ({ count }: IStorage) => {
console.log("content", count);
});
$color: red;
body {
background-color: $color !important;
} npm run build
Output body{background-color:red!important} |
Added examples in
|
fix: Increase @crxjs/vite-plugin to beta 18 for side_panel support.
I couldn't figure out how to specify CSS files in the manifest under
"content_scripts"
I tried:
vite.config.ts
What I actually get:
The text was updated successfully, but these errors were encountered: