![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
branding-webpack-plugin
Advanced tools
Use CSS custom properties to theme your app with fallbacks for browsers that don't support it (tested on IE11).
Branding plugin allows you to import CSS variables that get applied to the page.
The CSS variables are defined in a .branding
file.
When imported, they get applied to the page, therefore any usage of the CSS variable gets the theme's colour.
You also get access to the colour values in JavaScript.
Branding plugin creates a nice fallback for IE 11 by creating an overrides stylesheet that gets loaded only when the browser doesn't support CSS variables.
The end result is that you can easily import a theme's colours without worrying about browser support.
📃 Blog post: You can read more about how it works here
You'll need webpack 4.
npm i --save-dev branding-webpack-plugin
A non-supported webpack 3 version also exists. You can install it by running
npm i --save-dev branding-webpack3-plugin
In your webpack config, create a new instance of BrandingPlugin and add its CSS loader to your CSS pipeline, and its loader for *.branding files.
const BrandingPlugin = require('webpack-branding-plugin');
const brandingPlugin = new BrandingPlugin();
module.exports = {
module: {
rules: [
{test: /\.branding$/, use: [brandingPlugin.createLoader()]},
{test: /\.css$/, use: [{loader: 'style-loader'}, {loader: 'css-loader'}, brandingPlugin.createCSSLoader()]}
]
},
plugins: [brandingPlugin]
};
Say you have your app's CSS in app.css
and some branding/theming colours in theme.branding
.
app.css
body {
color: black;
background: var(--my-theme-color);
}
theme.branding
:root {
--my-theme-color: red;
}
Then, you can import theme.branding
in your entry JS file:
index.js
import './app.css'; // uses CSS and style loader
// uses branding plugin and loader to apply the CSS variables to the page,
// with fallbacks for browsers that don't support it!
import brandingVars from './theme.branding';
console.log(brandingVars); // Output: {'--my-theme-color': 'red'}
This also works with dynamic imports import('./theme.branding')
, which means you can dynamically import a theme
at runtime e.g. import(`./theme-${confirm('Enter theme name')}.branding`)
.
You can read the blog post to learn more about a real use case.
Take a look at the examples
folder for a working example of how it works.
Contributions welcome via issues and pull requests! Read our contribution guide here.
There is a basic test to ensure the plugin works with and without CSS variable support.
To run the tests, run:
npm test
You can also run the test server in the background using npm run serve-test
and run jest directly in another terminal using npm run jest
.
FAQs
Cross platform theming with CSS variables
We found that branding-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.