Skip to content

Commit

Permalink
feat(): add customLinkHref
Browse files Browse the repository at this point in the history
  • Loading branch information
GitOfZGT committed Mar 11, 2022
1 parent b91bf24 commit 3c306ac
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @zougt/theme-css-extract-webpack-plugin

这个 webpack 插件与[@zougt/some-loader-utils](https://github.com/GitOfZGT/some-loader-utils)结合轻松实现在线动态主题,使用文档直接查看[@zougt/some-loader-utils](https://github.com/GitOfZGT/some-loader-utils)

## Options

| Name | Type | Default | Description |
Expand All @@ -13,6 +14,7 @@
| **[`defaultScopeName`](#defaultScopeName)** | `{String}` | multipleScopeVars[0].scopeName | 默认使用主题名称 |
| **[`themeLinkTagId`](#themeLinkTagId)** | `{String}` | `theme-link-tag` | 在 html 中使用主题 css 文件的 link 标签的 id |
| **[`themeLinkTagAppend`](#themeLinkTagAppend)** | `{Boolean}` | `false` | 是否在其他 css 之后插入主题 css 文件的 link 标签 |
| **[`customLinkHref`](#customLinkHref)** | `{Function}` | `null` | 预设主题模式,抽取 css 后,自定义默认添加到 html 的 link 的 href |

### `multipleScopeVars`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zougt/theme-css-extract-webpack-plugin",
"version": "1.3.2",
"version": "1.4.0",
"description": "extracts theme CSS into separate files",
"license": "MIT",
"repository": "GitOfZGT/theme-css-extract-webpack-plugin",
Expand Down
4 changes: 1 addition & 3 deletions src/apply/arbitraryModeApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export function arbitraryModeApply(compiler) {
) {
this.cacheThemeStyleContent = styleContent;
const packRoot = require
.resolve(pack.name, {
paths: [process.cwd()],
})
.resolve(pack.name)
.replace(/[\\/]cjs\.js$/, '')
.replace(/\\/g, '/');
// no return
Expand Down
10 changes: 7 additions & 3 deletions src/apply/presetModeApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ function getThemeExtractLinkTag({ publicPath, userOptions }) {
(typeof userOptions.customThemeCssFileName === 'function'
? userOptions.customThemeCssFileName(userOptions.defaultScopeName)
: '') || userOptions.defaultScopeName;
let href = `/${publicPath || ''}/${
userOptions.outputDir || ''
}/${filename}.css`.replace(/\/+(?=\/)/g, '');
if (typeof userOptions.customLinkHref === 'function') {
href = userOptions.customLinkHref(href);
}
return {
tagName: 'link',
voidTag: true,
attributes: {
href: userOptions.customLinkHref(`/${publicPath || ''}/${
userOptions.outputDir || ''
}/${filename}.css`.replace(/\/+(?=\/)/g, '')),
href,
rel: 'stylesheet',
id: userOptions.themeLinkTagId,
},
Expand Down
4 changes: 1 addition & 3 deletions src/hot-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import pack from '../../package.json';
function HotUpdateLoader(content) {
const callback = this.async();
const packRoot = require
.resolve(pack.name, {
paths: [this.context || process.cwd()],
})
.resolve(pack.name)
.replace(/[\\/]cjs\.js$/, '')
.replace(/\\/g, '/');
const param = getPluginParams();
Expand Down

0 comments on commit 3c306ac

Please sign in to comment.