{"id":15140299,"url":"https://github.com/itayganor/multiple-themes-webpack-plugin","last_synced_at":"2025-10-23T15:31:51.500Z","repository":{"id":57305337,"uuid":"289271213","full_name":"itayganor/multiple-themes-webpack-plugin","owner":"itayganor","description":"🌈 Build multiple themes for your frontend project and switch between them on the fly","archived":false,"fork":false,"pushed_at":"2020-08-22T17:45:44.000Z","size":177,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T19:23:14.452Z","etag":null,"topics":["css-modules","less","theme","webpack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itayganor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-21T13:03:28.000Z","updated_at":"2021-06-24T22:57:56.000Z","dependencies_parsed_at":"2022-09-20T20:51:00.044Z","dependency_job_id":null,"html_url":"https://github.com/itayganor/multiple-themes-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itayganor%2Fmultiple-themes-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itayganor%2Fmultiple-themes-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itayganor%2Fmultiple-themes-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itayganor%2Fmultiple-themes-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itayganor","download_url":"https://codeload.github.com/itayganor/multiple-themes-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237852526,"owners_count":19376702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-modules","less","theme","webpack"],"created_at":"2024-09-26T08:02:01.054Z","updated_at":"2025-10-23T15:31:51.110Z","avatar_url":"https://github.com/itayganor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# multiple-themes-webpack-plugin\n\n[![npm version](https://img.shields.io/npm/v/multiple-themes-webpack-plugin)](https://www.npmjs.com/package/multiple-themes-webpack-plugin)\n\nA webpack plugin to generate multiple themes for your app.\n\nWraps [webpack-css-themes-plugin](https://github.com/gem-mine/webpack-css-themes-plugin).\n\n# Installation\n\nInstall from NPM:\n```cmd\nnpm install -D multiple-themes-webpack-plugin\n```\n\nAlso install `html-webpack-plugin` if you don't have it already:\n\n```cmd\nnpm install -D html-webpack-plugin\n```\n\n# Usage\n\n## Setting up the plugin\n\nIn your `webpack.config.js`:\n```ts\nimport MultipleThemesPlugin from 'multiple-themes-webpack-plugin/dist/MultipleThemesPlugin';\n```\n\nAdd it to your plugins list:\n```js\n{\n    plugins: {\n        // ... your other plugins,\n        new MultipleThemesPlugin({\n            themes: {\n                // for each theme, assign a name and a path to its variables\n                dark: path.resolve(__dirname, './src/themes/theme-dark.less'),\n                light: path.resolve(__dirname, './src/themes/theme-light.less'),\n            },\n        }),\n        // Don't forget to include the html-webpack-plugin plugin\n        new HtmlWebpackPlugin({\n            template: path.resolve(__dirname, './index.html'),\n        }),\n    }\n}\n```\n\n## Switching themes at runtime\n\nimport the switch function anywhere in your project:\n```js\nimport {switchTheme} from 'multiple-themes-webpack-plugin';\n```\n\nCall that function with the new theme's name as an argument:\n```\nswitchTheme('dark');\n```\n\n***Developer recommendation:** If you use Typescript, It is recommended to use enums for theme names - for convenience, autocomplete options, and to make sure you won't have typos.*\n\n# Gotcha's\n\n### Default theme\nTo have a default theme preloaded directly in the HTML file (mainly to prevent a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content)),\nAdd this before your closing `\u003c/head\u003e` tag:\n```html\n    \u003c%= htmlWebpackPlugin.options.extraHeadTags %\u003e\n```\n\nAnd in the plugin options:\n```js\nnew MultipleThemesPlugin({\n    themes: {\n        dark: path.resolve(__dirname, './src/themes/theme-dark.less'),\n        light: path.resolve(__dirname, './src/themes/theme-light.less'),\n    },\n    defaultTheme: 'dark',\n}),\n```\n\n### CSS Imports inside `.less` files\n\nIf you try to `@import` a `.css` file inside a `.less` file, You'll get the following error:\n\n```\nError: Didn't get a result from child compiler\n```\n\nTo avoid this, tell the compiler to treat the file as a Less file using the [Import Options](http://lesscss.org/features/#import-atrules-feature-import-options) feature:\n\n```less\n@import (less) './assets/fonts/Lato/Lato.css';\n```\n\n*See [webpack-css-themes-plugin#4](https://github.com/gem-mine/webpack-css-themes-plugin/issues/4) for more information.*\n\n\n### Webpack config entry\nDue to a bug in the base plugin, the `entry` option in `webpack.config.js` must be an object.\nIf it's not an object already in your config, the simplest solution is to wrap your current entry with a single-key object:\n```js\n{\n    // from:\n    entry: ['react-hot-loader/patch', './src/index.tsx'],\n\n    // to:\n    entry: {\n        app: ['react-hot-loader/patch', './src/index.tsx'],\n    },\n}\n```\n\n### Exclude Assets Plugin\nDefault generated CSS Assets are excluded from the `html` file, since this plugin appends its own styles automatically. If you ever wonder why you don't see your compiled themes without supplying a default theme, this is the reason.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitayganor%2Fmultiple-themes-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitayganor%2Fmultiple-themes-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitayganor%2Fmultiple-themes-webpack-plugin/lists"}