# webpack-theme-set

> 配合[webpack-css-themes-plugin](http://git.sdp.nd/gem-mine/webpack-css-themes-plugin)使用，用于加载其生成的主题

Latest version **0.7.1** (published 2024-01-09) · 0 weekly downloads

## Install

```sh
npm install webpack-theme-set
pnpm add webpack-theme-set
yarn add webpack-theme-set
bun add webpack-theme-set
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.1 |
| Published | 2024-01-09 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | githoniel |

## Links

- npm: https://www.npmjs.com/package/webpack-theme-set
- npm.io page: https://npm.io/package/webpack-theme-set

## Recent versions

- 0.7.1 (latest) — 2024-01-09
- 0.7.0 — 2023-12-19
- 0.6.0 — 2021-02-09
- 0.5.0 — 2021-02-08
- 0.4.0 — 2020-11-05
- 0.3.3 — 2020-10-21
- 0.3.2 — 2020-10-21
- 0.3.1 — 2020-07-02
- 0.3.0 — 2020-07-02
- 0.2.0 — 2020-06-12
- 0.1.0 — 2020-06-10
- 0.0.2 — 2020-06-05
- 0.0.1 — 2020-06-05

## README

# set-webpack-theme

配合[webpack-css-themes-plugin](http://git.sdp.nd/gem-mine/webpack-css-themes-plugin)使用，用于加载其生成的主题

## Demo

```js
import themeSetter from 'webpack-theme-set'
// 按照 window._pageThemeConfig -> urlQuery -> cookie的次序设置主题信息
themeSetter.autoSetTheme()
// 切换主题
themeSetter.setTheme('default', {
  count: 3,
  prefix: 'app-'
})

```

注意：设置主题后，iframe等必须刷新页面，请主动执行

## 主题文件

主题文件名规则如下
1. themeFileCount = 1 时候，单主题文件，为`${prefix}${themeName}.css`
2. themeFileCount > 1 时候, 多主体文件，为`${prefix}${themeName}-${index}.css`

## API

### constructor

初始化类的时候，按照`window._pageThemeConfig` -> `urlQuery` -> `cookie`的优先级获取主题信息，一旦从某个来源中获取到主题信息便会返回并设置当前主题

如果都没有获取则不会设置主题

### SetTheme

setTheme(themeName: string, { count, prefix, }?: {
    count?: number;
    prefix?: string;
}): void

- themeName: 主题名称
- count: 主题文件数量，由于IE9兼容，可能拆分成N份，默认为1
- prefix: 主题文件前缀，默认为`app-`

---
_Source: https://npm.io/package/webpack-theme-set · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
