Skip to content

Commit 3c306ac

Browse files
committed
feat(): add customLinkHref
1 parent b91bf24 commit 3c306ac

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# @zougt/theme-css-extract-webpack-plugin
22

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

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

1719
### `multipleScopeVars`
1820

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zougt/theme-css-extract-webpack-plugin",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"description": "extracts theme CSS into separate files",
55
"license": "MIT",
66
"repository": "GitOfZGT/theme-css-extract-webpack-plugin",

src/apply/arbitraryModeApply.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ export function arbitraryModeApply(compiler) {
106106
) {
107107
this.cacheThemeStyleContent = styleContent;
108108
const packRoot = require
109-
.resolve(pack.name, {
110-
paths: [process.cwd()],
111-
})
109+
.resolve(pack.name)
112110
.replace(/[\\/]cjs\.js$/, '')
113111
.replace(/\\/g, '/');
114112
// no return

src/apply/presetModeApply.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ function getThemeExtractLinkTag({ publicPath, userOptions }) {
1111
(typeof userOptions.customThemeCssFileName === 'function'
1212
? userOptions.customThemeCssFileName(userOptions.defaultScopeName)
1313
: '') || userOptions.defaultScopeName;
14+
let href = `/${publicPath || ''}/${
15+
userOptions.outputDir || ''
16+
}/${filename}.css`.replace(/\/+(?=\/)/g, '');
17+
if (typeof userOptions.customLinkHref === 'function') {
18+
href = userOptions.customLinkHref(href);
19+
}
1420
return {
1521
tagName: 'link',
1622
voidTag: true,
1723
attributes: {
18-
href: userOptions.customLinkHref(`/${publicPath || ''}/${
19-
userOptions.outputDir || ''
20-
}/${filename}.css`.replace(/\/+(?=\/)/g, '')),
24+
href,
2125
rel: 'stylesheet',
2226
id: userOptions.themeLinkTagId,
2327
},

src/hot-loader/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import pack from '../../package.json';
77
function HotUpdateLoader(content) {
88
const callback = this.async();
99
const packRoot = require
10-
.resolve(pack.name, {
11-
paths: [this.context || process.cwd()],
12-
})
10+
.resolve(pack.name)
1311
.replace(/[\\/]cjs\.js$/, '')
1412
.replace(/\\/g, '/');
1513
const param = getPluginParams();

0 commit comments

Comments
 (0)