@douyinfe/semi-rspack-plugin 2.59.0-alpha.0 → 2.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/componentDependentTree.d.ts +69 -0
- package/lib/componentDependentTree.js +71 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +3 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -1
- package/lib/loaders/semi-extract-css-content-loader.d.ts +12 -0
- package/lib/loaders/semi-extract-css-content-loader.js +28 -0
- package/lib/loaders/semi-theme-loader.d.ts +1 -0
- package/lib/loaders/semi-theme-loader.js +8 -2
- package/lib/loaders/semi-web-component-loader.d.ts +2 -0
- package/lib/loaders/semi-web-component-loader.js +122 -0
- package/lib/rule.d.ts +9 -0
- package/lib/rule.js +34 -3
- package/lib/types.d.ts +2 -0
- package/package.json +6 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare const dependentTree: {
|
|
2
|
+
Anchor: string[];
|
|
3
|
+
AutoComplete: string[];
|
|
4
|
+
Avatar: any;
|
|
5
|
+
AvatarGroup: any;
|
|
6
|
+
BackTop: string[];
|
|
7
|
+
Badge: any;
|
|
8
|
+
Banner: string[];
|
|
9
|
+
Breadcrumb: string[];
|
|
10
|
+
Button: string[];
|
|
11
|
+
Calendar: string[];
|
|
12
|
+
Card: string[];
|
|
13
|
+
Carousel: string[];
|
|
14
|
+
Cascader: string[];
|
|
15
|
+
Checkbox: string[];
|
|
16
|
+
CheckboxGroup: string[];
|
|
17
|
+
Collapse: string[];
|
|
18
|
+
Collapsible: any;
|
|
19
|
+
DatePicker: string[];
|
|
20
|
+
Descriptions: any;
|
|
21
|
+
Divider: any;
|
|
22
|
+
Dropdown: string[];
|
|
23
|
+
Empty: string[];
|
|
24
|
+
Form: string[];
|
|
25
|
+
Row: any;
|
|
26
|
+
Col: any;
|
|
27
|
+
Highlight: any;
|
|
28
|
+
IconButton: string[];
|
|
29
|
+
Image: string[];
|
|
30
|
+
Input: string[];
|
|
31
|
+
InputGroup: string[];
|
|
32
|
+
TextArea: string[];
|
|
33
|
+
InputNumber: string[];
|
|
34
|
+
Layout: any;
|
|
35
|
+
Modal: string[];
|
|
36
|
+
Navigation: string[];
|
|
37
|
+
Notification: string[];
|
|
38
|
+
OverflowList: any;
|
|
39
|
+
Pagination: string[];
|
|
40
|
+
Popconfirm: string[];
|
|
41
|
+
Popover: string[];
|
|
42
|
+
Portal: any;
|
|
43
|
+
Progress: any;
|
|
44
|
+
Radio: string[];
|
|
45
|
+
Rating: string[];
|
|
46
|
+
ScrollList: any;
|
|
47
|
+
Select: string[];
|
|
48
|
+
SideSheet: string[];
|
|
49
|
+
Skeleton: any;
|
|
50
|
+
Slider: string[];
|
|
51
|
+
Space: any;
|
|
52
|
+
Spin: any;
|
|
53
|
+
Steps: string[];
|
|
54
|
+
Switch: string[];
|
|
55
|
+
Table: string[];
|
|
56
|
+
Tabs: string[];
|
|
57
|
+
Tag: string[];
|
|
58
|
+
TagGroup: string[];
|
|
59
|
+
TagInput: string[];
|
|
60
|
+
Timeline: any;
|
|
61
|
+
Toast: string[];
|
|
62
|
+
Tooltip: string[];
|
|
63
|
+
Transfer: string[];
|
|
64
|
+
Tree: string[];
|
|
65
|
+
TreeSelect: string[];
|
|
66
|
+
Typography: string[];
|
|
67
|
+
Upload: string[];
|
|
68
|
+
};
|
|
69
|
+
export default dependentTree;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dependentTree = {
|
|
4
|
+
"Anchor": ["Typography"],
|
|
5
|
+
"AutoComplete": ["Spin", "Popover", "Input", "Icon"],
|
|
6
|
+
"Avatar": [],
|
|
7
|
+
"AvatarGroup": [],
|
|
8
|
+
"BackTop": ["Icon"],
|
|
9
|
+
"Badge": [],
|
|
10
|
+
"Banner": ["IconButton", "Typography", "Icon"],
|
|
11
|
+
"Breadcrumb": ["Popover", "Typography", "Icon"],
|
|
12
|
+
"Button": ["Icon"],
|
|
13
|
+
"Calendar": ["Popover", "Button", "Icon"],
|
|
14
|
+
"Card": ["Space", "Skeleton", "Typography"],
|
|
15
|
+
"Carousel": ["Icon"],
|
|
16
|
+
"Cascader": ["Input", "Popover", "Tag", "TagInput", "Spin", "Checkbox", "Icon"],
|
|
17
|
+
"Checkbox": ["Icon"],
|
|
18
|
+
"CheckboxGroup": ["Icon"],
|
|
19
|
+
"Collapse": ["Collapsible", "Icon"],
|
|
20
|
+
"Collapsible": [],
|
|
21
|
+
"DatePicker": ["Button", "Input", "IconButton", "Icon", "Typography", "ScrollList", "Icon"],
|
|
22
|
+
"Descriptions": [],
|
|
23
|
+
"Divider": [],
|
|
24
|
+
"Dropdown": ["Tooltip", "Icon"],
|
|
25
|
+
"Empty": ["Typography"],
|
|
26
|
+
"Form": ["Row", "Col", "Icon"],
|
|
27
|
+
"Row": [],
|
|
28
|
+
"Col": [],
|
|
29
|
+
"Highlight": [],
|
|
30
|
+
"IconButton": ["Button", "Spin", "Icon"],
|
|
31
|
+
"Image": ["Skeleton", "Divider", "Tooltip", "Slider", "Spin", "Portal", "Icon"],
|
|
32
|
+
"Input": ["Icon"],
|
|
33
|
+
"InputGroup": ["Form"],
|
|
34
|
+
"TextArea": ["Icon"],
|
|
35
|
+
"InputNumber": ["Input", "Icon"],
|
|
36
|
+
"Layout": [],
|
|
37
|
+
"Modal": ["Button", "Portal", "Typography", "Icon"],
|
|
38
|
+
"Navigation": ["Button", "Tooltip", "Dropdown", "Collapsible", "Icon"],
|
|
39
|
+
"Notification": ["Button", "Icon"],
|
|
40
|
+
"OverflowList": [],
|
|
41
|
+
"Pagination": ["Select", "InputNumber", "Popover", "Icon"],
|
|
42
|
+
"Popconfirm": ["Popover", "Button", "Icon"],
|
|
43
|
+
"Popover": ["Tooltip"],
|
|
44
|
+
"Portal": [],
|
|
45
|
+
"Progress": [],
|
|
46
|
+
"Radio": ["Icon"],
|
|
47
|
+
"Rating": ["Icon", "Tooltip"],
|
|
48
|
+
"ScrollList": [],
|
|
49
|
+
"Select": ["Tag", "OverflowList", "Space", "Typography", "Spin", "Popover", "Icon"],
|
|
50
|
+
"SideSheet": ["[Portal", "Button", "Icon"],
|
|
51
|
+
"Skeleton": [],
|
|
52
|
+
"Slider": ["Tooltip"],
|
|
53
|
+
"Space": [],
|
|
54
|
+
"Spin": [],
|
|
55
|
+
"Steps": ["Row", "Col", "Icon"],
|
|
56
|
+
"Switch": ["Spin"],
|
|
57
|
+
"Table": ["Radio", "Checkbox", "Dropdown", "Spin", "Pagination", "Icon"],
|
|
58
|
+
"Tabs": ["OverflowList", "Dropdown", "Button", "Icon"],
|
|
59
|
+
"Tag": ["Icon", "Popover", "Avatar"],
|
|
60
|
+
"TagGroup": ["Icon", "Popover", "Avatar"],
|
|
61
|
+
"TagInput": ["Tag", "Input", "Popover", "Icon"],
|
|
62
|
+
"Timeline": [],
|
|
63
|
+
"Toast": ["Button", "Icon"],
|
|
64
|
+
"Tooltip": ["Portal"],
|
|
65
|
+
"Transfer": ["Input", "Checkbox", "Tree", "Button", "Spin", "Icon"],
|
|
66
|
+
"Tree": ["Input", "Checkbox", "Spin", "Collapsible", "Icon"],
|
|
67
|
+
"TreeSelect": ["Tag", "TagInput", "Checkbox", "Popover", "Input", "Icon"],
|
|
68
|
+
"Typography": ["Popover", "Tooltip", "Icon"],
|
|
69
|
+
"Upload": ["Button", "Progress", "Tooltip", "Spin", "Icon"]
|
|
70
|
+
};
|
|
71
|
+
exports.default = dependentTree;
|
package/lib/constants.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export declare const SOURCE_SUFFIX_LOADER: string;
|
|
|
2
2
|
export declare const THEME_LOADER: string;
|
|
3
3
|
export declare const OMIT_CSS_LOADER: string;
|
|
4
4
|
export declare const PREFIX_LOADER: string;
|
|
5
|
+
export declare const EXTRACT_CSS_LOADER: string;
|
|
6
|
+
export declare const WEB_COMPONENT_LOADER: string;
|
package/lib/constants.js
CHANGED
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PREFIX_LOADER = exports.OMIT_CSS_LOADER = exports.THEME_LOADER = exports.SOURCE_SUFFIX_LOADER = void 0;
|
|
6
|
+
exports.WEB_COMPONENT_LOADER = exports.EXTRACT_CSS_LOADER = exports.PREFIX_LOADER = exports.OMIT_CSS_LOADER = exports.THEME_LOADER = exports.SOURCE_SUFFIX_LOADER = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
exports.SOURCE_SUFFIX_LOADER = path_1.default.resolve(__dirname, './loaders/semi-source-suffix-loader');
|
|
9
9
|
exports.THEME_LOADER = path_1.default.resolve(__dirname, './loaders/semi-theme-loader');
|
|
10
10
|
exports.OMIT_CSS_LOADER = path_1.default.resolve(__dirname, './loaders/semi-omit-css-loader');
|
|
11
11
|
exports.PREFIX_LOADER = path_1.default.resolve(__dirname, './loaders/semi-prefix-loader');
|
|
12
|
+
exports.EXTRACT_CSS_LOADER = path_1.default.resolve(__dirname, './loaders/semi-extract-css-content-loader');
|
|
13
|
+
exports.WEB_COMPONENT_LOADER = path_1.default.resolve(__dirname, './loaders/semi-web-component-loader');
|
package/lib/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export { default as semiThemeLoader } from './loaders/semi-theme-loader';
|
|
|
5
5
|
export { default as semiPrefixLoader } from './loaders/semi-prefix-loader';
|
|
6
6
|
export { default as semiSourceSuffixLoader } from './loaders/semi-source-suffix-loader';
|
|
7
7
|
export { default as semiOmitCssLoader } from './loaders/semi-omit-css-loader';
|
|
8
|
+
export { default as semiExtractCssContentLoader } from './loaders/semi-extract-css-content-loader';
|
|
9
|
+
export { default as semiWebComponentLoader } from './loaders/semi-web-component-loader';
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.semiOmitCssLoader = exports.semiSourceSuffixLoader = exports.semiPrefixLoader = exports.semiThemeLoader = void 0;
|
|
20
|
+
exports.semiWebComponentLoader = exports.semiExtractCssContentLoader = exports.semiOmitCssLoader = exports.semiSourceSuffixLoader = exports.semiPrefixLoader = exports.semiThemeLoader = void 0;
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
22
|
__exportStar(require("./plugin"), exports);
|
|
23
23
|
__exportStar(require("./rule"), exports);
|
|
@@ -29,3 +29,7 @@ var semi_source_suffix_loader_1 = require("./loaders/semi-source-suffix-loader")
|
|
|
29
29
|
Object.defineProperty(exports, "semiSourceSuffixLoader", { enumerable: true, get: function () { return __importDefault(semi_source_suffix_loader_1).default; } });
|
|
30
30
|
var semi_omit_css_loader_1 = require("./loaders/semi-omit-css-loader");
|
|
31
31
|
Object.defineProperty(exports, "semiOmitCssLoader", { enumerable: true, get: function () { return __importDefault(semi_omit_css_loader_1).default; } });
|
|
32
|
+
var semi_extract_css_content_loader_1 = require("./loaders/semi-extract-css-content-loader");
|
|
33
|
+
Object.defineProperty(exports, "semiExtractCssContentLoader", { enumerable: true, get: function () { return __importDefault(semi_extract_css_content_loader_1).default; } });
|
|
34
|
+
var semi_web_component_loader_1 = require("./loaders/semi-web-component-loader");
|
|
35
|
+
Object.defineProperty(exports, "semiWebComponentLoader", { enumerable: true, get: function () { return __importDefault(semi_web_component_loader_1).default; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {*} source
|
|
5
|
+
* @returns string
|
|
6
|
+
* @description
|
|
7
|
+
* 此 loader 用于从 css-loader 处理后的 js 代码中获取纯 css 样式字符串
|
|
8
|
+
* source 是经过 css-loader 处理后的 js 代码。要获取其中的 css 样式字符串,需经过如下操作:
|
|
9
|
+
* 1. 通过识别module.id, "做为开头,", ""]);作为结尾拿到中间的 css 代码
|
|
10
|
+
* 2. 将 文本中的 \n 替换为空字符串
|
|
11
|
+
*/
|
|
12
|
+
export default function semiExtractCssContentLoader(this: LoaderContext<void>, source: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {*} source
|
|
6
|
+
* @returns string
|
|
7
|
+
* @description
|
|
8
|
+
* 此 loader 用于从 css-loader 处理后的 js 代码中获取纯 css 样式字符串
|
|
9
|
+
* source 是经过 css-loader 处理后的 js 代码。要获取其中的 css 样式字符串,需经过如下操作:
|
|
10
|
+
* 1. 通过识别module.id, "做为开头,", ""]);作为结尾拿到中间的 css 代码
|
|
11
|
+
* 2. 将 文本中的 \n 替换为空字符串
|
|
12
|
+
*/
|
|
13
|
+
function semiExtractCssContentLoader(source) {
|
|
14
|
+
const beginContent = 'module.id, "';
|
|
15
|
+
const endContent = '", ""]);';
|
|
16
|
+
let begInIndex = source.indexOf(beginContent);
|
|
17
|
+
let endIndex = source.length;
|
|
18
|
+
let result = source;
|
|
19
|
+
if (begInIndex !== -1) {
|
|
20
|
+
endIndex = source.lastIndexOf(endContent);
|
|
21
|
+
if (endIndex !== -1) {
|
|
22
|
+
result = source.slice(begInIndex + beginContent.length, endIndex);
|
|
23
|
+
result = result.replace(/\\n/g, "");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
exports.default = semiExtractCssContentLoader;
|
|
@@ -8,6 +8,7 @@ const componentName_1 = __importDefault(require("../componentName"));
|
|
|
8
8
|
function SemiThemeLoader(source) {
|
|
9
9
|
const query = this.getOptions();
|
|
10
10
|
const theme = query.name || '@douyinfe/semi-theme-default';
|
|
11
|
+
const cssLayer = query.cssLayer ?? false;
|
|
11
12
|
// always inject
|
|
12
13
|
const scssVarStr = `@import "~${theme}/scss/index.scss";\n`;
|
|
13
14
|
// inject once
|
|
@@ -50,6 +51,7 @@ function SemiThemeLoader(source) {
|
|
|
50
51
|
// inject prefix
|
|
51
52
|
const prefixCls = query.prefixCls || 'semi';
|
|
52
53
|
const prefixClsStr = `$prefix: '${prefixCls}';\n`;
|
|
54
|
+
let finalCSS = "";
|
|
53
55
|
if (shouldInject) {
|
|
54
56
|
const customStr = (() => {
|
|
55
57
|
let customStr = '';
|
|
@@ -73,10 +75,14 @@ function SemiThemeLoader(source) {
|
|
|
73
75
|
}
|
|
74
76
|
return `body:not(:not(body)){${customStr}};`;
|
|
75
77
|
})();
|
|
76
|
-
|
|
78
|
+
finalCSS = `${animationStr}${cssVarStr}${scssVarStr}${prefixClsStr}${fileStr}${customStr}`;
|
|
77
79
|
}
|
|
78
80
|
else {
|
|
79
|
-
|
|
81
|
+
finalCSS = `${scssVarStr}${prefixClsStr}${fileStr}`;
|
|
80
82
|
}
|
|
83
|
+
if (cssLayer) {
|
|
84
|
+
finalCSS = `@layer semi{${finalCSS}}`;
|
|
85
|
+
}
|
|
86
|
+
return finalCSS;
|
|
81
87
|
}
|
|
82
88
|
exports.default = SemiThemeLoader;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const componentDependentTree_1 = __importDefault(require("../componentDependentTree"));
|
|
8
|
+
function getAllComponents(components) {
|
|
9
|
+
const originComponents = new Set(components);
|
|
10
|
+
const resultComponents = new Set();
|
|
11
|
+
// 对特殊组件做特殊处理,因为这些组件的样式文件名和组件名不一致,需要手动映射
|
|
12
|
+
const specialCaseBefore = {
|
|
13
|
+
'AvatarGroup': 'Avatar',
|
|
14
|
+
'CheckboxGroup': 'Checkbox',
|
|
15
|
+
'TagGroup': 'Tag'
|
|
16
|
+
};
|
|
17
|
+
/*
|
|
18
|
+
对特殊组件做特殊处理,因为这些组件的样式文件名和组件名不一致,需要手动映射
|
|
19
|
+
同时由于以下原因:
|
|
20
|
+
1. 组件所依赖组件和被映射的组件不同,因此应该在获取到依赖组件之后,再做映射
|
|
21
|
+
e.g InputGroup 依赖 Form 组件,其样式存储在 input.scss 中,
|
|
22
|
+
而 Input 不依赖 Form 组件,因此对于 InputGroup,需要拿到依赖组件,再做映射
|
|
23
|
+
2. 由于组件是其他组件的依赖组件,因此需要在获取到依赖组件之后,再做映射
|
|
24
|
+
e.g 比如 Row 是 Form 组件的依赖,因此需要在获取到依赖组件之后,再做映射
|
|
25
|
+
*/
|
|
26
|
+
const specialCaseAfter = {
|
|
27
|
+
"InputGroup": "Input",
|
|
28
|
+
'Row': 'Grid',
|
|
29
|
+
'Col': 'Grid',
|
|
30
|
+
};
|
|
31
|
+
Object.keys(specialCaseBefore).map(keyComponent => {
|
|
32
|
+
if (originComponents.has(keyComponent)) {
|
|
33
|
+
originComponents.delete(keyComponent);
|
|
34
|
+
originComponents.add(specialCaseBefore[keyComponent]);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
function getDependentComponents(components) {
|
|
38
|
+
components.forEach((component) => {
|
|
39
|
+
if (!resultComponents.has(component)) {
|
|
40
|
+
const dependents = componentDependentTree_1.default[component];
|
|
41
|
+
dependents?.forEach((element) => {
|
|
42
|
+
getDependentComponents([element]);
|
|
43
|
+
});
|
|
44
|
+
resultComponents.add(component);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getDependentComponents(Array.from(originComponents));
|
|
49
|
+
Object.keys(specialCaseAfter).map(keyComponent => {
|
|
50
|
+
if (resultComponents.has(keyComponent)) {
|
|
51
|
+
resultComponents.delete(keyComponent);
|
|
52
|
+
resultComponents.add(specialCaseAfter[keyComponent]);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return Array.from(resultComponents);
|
|
56
|
+
}
|
|
57
|
+
function getScssImportPaths(components) {
|
|
58
|
+
const pathsObj = {
|
|
59
|
+
IconPath: '@douyinfe/semi-icons/lib/es/styles/icons.scss',
|
|
60
|
+
basePath: '@douyinfe/semi-ui/lib/es/_base/base.scss',
|
|
61
|
+
foundationPath: '@douyinfe/semi-foundation/lib/es/'
|
|
62
|
+
};
|
|
63
|
+
const specialCase = {
|
|
64
|
+
'Icon': pathsObj.IconPath,
|
|
65
|
+
'Base': pathsObj.basePath,
|
|
66
|
+
'Portal': `${pathsObj.foundationPath}_portal/portal.scss`,
|
|
67
|
+
"TextArea": `${pathsObj.foundationPath}input/textarea.scss`,
|
|
68
|
+
"IconButton": `${pathsObj.foundationPath}button/iconButton.scss`,
|
|
69
|
+
};
|
|
70
|
+
const cssPaths = ["Base", ...components].map(componentName => {
|
|
71
|
+
const lowFirstLetter = componentName.slice(0, 1).toLowerCase() + componentName.slice(1);
|
|
72
|
+
let pathName = '';
|
|
73
|
+
if (specialCase[componentName]) {
|
|
74
|
+
pathName = specialCase[componentName];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
pathName = `${pathsObj.foundationPath}${lowFirstLetter}/${lowFirstLetter}.scss`;
|
|
78
|
+
}
|
|
79
|
+
return pathName;
|
|
80
|
+
});
|
|
81
|
+
const importFuncName = `
|
|
82
|
+
async function importSemiComponentStyle(componentsStr, root, cb){
|
|
83
|
+
const modules = await Promise.all([
|
|
84
|
+
${cssPaths.map(path => `import("${path}")`).join(',')}
|
|
85
|
+
]);
|
|
86
|
+
const styleStr = modules.map(module => {
|
|
87
|
+
const cssContent = module.default;
|
|
88
|
+
return cssContent;
|
|
89
|
+
});
|
|
90
|
+
styleStr.reverse().forEach(css => {
|
|
91
|
+
const style = document.createElement('style');
|
|
92
|
+
style.innerHTML = css;
|
|
93
|
+
root.prepend(style);
|
|
94
|
+
});
|
|
95
|
+
if(typeof cb === 'function') {
|
|
96
|
+
cb();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
return importFuncName;
|
|
101
|
+
}
|
|
102
|
+
function semiWebComponentLoader(source) {
|
|
103
|
+
/*SEMI_INSERT_STYLE_BEGIN[需要插入样式的组件]SEMI_INSERT_STYLE_END*/
|
|
104
|
+
const beginContent = 'SEMI_INSERT_STYLE_BEGIN';
|
|
105
|
+
const beginIndex = source.indexOf(beginContent);
|
|
106
|
+
if (beginIndex !== -1) {
|
|
107
|
+
const endIndex = source.indexOf('SEMI_INSERT_STYLE_END');
|
|
108
|
+
if (endIndex === -1) {
|
|
109
|
+
throw new Error('SEMI_INSERT_STYLE_END not found');
|
|
110
|
+
}
|
|
111
|
+
const componentsStr = source.slice(beginIndex + beginContent.length, endIndex);
|
|
112
|
+
const componentsArr = JSON.parse(componentsStr);
|
|
113
|
+
const allComponents = getAllComponents(componentsArr);
|
|
114
|
+
// console.log('allComponents', allComponents);
|
|
115
|
+
const importFuncName = getScssImportPaths(allComponents);
|
|
116
|
+
const result = source + importFuncName;
|
|
117
|
+
// console.log('result', result);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
return source;
|
|
121
|
+
}
|
|
122
|
+
exports.default = semiWebComponentLoader;
|
package/lib/rule.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function createThemeLoaderRule(opts?: SemiWebpackPluginOptions):
|
|
|
14
14
|
prefixCls: string;
|
|
15
15
|
variables: string;
|
|
16
16
|
include: string;
|
|
17
|
+
cssLayer: boolean;
|
|
17
18
|
name?: string;
|
|
18
19
|
};
|
|
19
20
|
}[];
|
|
@@ -35,4 +36,12 @@ export declare function createPrefixLoaderRule(opts?: SemiWebpackPluginOptions):
|
|
|
35
36
|
};
|
|
36
37
|
}[];
|
|
37
38
|
};
|
|
39
|
+
export declare function createWebComponentLoaderRule(opts?: SemiWebpackPluginOptions): {
|
|
40
|
+
test: RegExp;
|
|
41
|
+
type: string;
|
|
42
|
+
exclude: RegExp;
|
|
43
|
+
use: {
|
|
44
|
+
loader: string;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
38
47
|
export declare function applySemiRules(opts?: SemiWebpackPluginOptions): RuleSetRule[];
|
package/lib/rule.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applySemiRules = exports.createPrefixLoaderRule = exports.createOmitCssLoaderRule = exports.createThemeLoaderRule = exports.createSourceSuffixLoaderRule = void 0;
|
|
3
|
+
exports.applySemiRules = exports.createWebComponentLoaderRule = exports.createPrefixLoaderRule = exports.createOmitCssLoaderRule = exports.createThemeLoaderRule = exports.createSourceSuffixLoaderRule = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function createSourceSuffixLoaderRule(_opts) {
|
|
@@ -23,11 +23,28 @@ function createThemeLoaderRule(opts) {
|
|
|
23
23
|
prefixCls: opts.prefixCls,
|
|
24
24
|
variables: (0, utils_1.stringifyVariableRecord)(opts.variables),
|
|
25
25
|
include: opts.include,
|
|
26
|
+
cssLayer: opts.cssLayer
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
const loaderInfo = {
|
|
28
29
|
test: /@douyinfe\/semi-(ui|icons|foundation)\/lib\/.+\.scss$/,
|
|
29
30
|
use: [{ loader: constants_1.THEME_LOADER, options }],
|
|
30
31
|
};
|
|
32
|
+
if (opts.webComponentPath) {
|
|
33
|
+
const commonLoader = [
|
|
34
|
+
{ loader: "raw-loader" },
|
|
35
|
+
{ loader: constants_1.EXTRACT_CSS_LOADER },
|
|
36
|
+
{
|
|
37
|
+
loader: 'css-loader',
|
|
38
|
+
options: { sourceMap: false }
|
|
39
|
+
},
|
|
40
|
+
{ loader: 'sass-loader' }
|
|
41
|
+
];
|
|
42
|
+
loaderInfo.use = [
|
|
43
|
+
...commonLoader,
|
|
44
|
+
...loaderInfo.use
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
return loaderInfo;
|
|
31
48
|
}
|
|
32
49
|
exports.createThemeLoaderRule = createThemeLoaderRule;
|
|
33
50
|
function createOmitCssLoaderRule(_opts) {
|
|
@@ -47,17 +64,31 @@ function createPrefixLoaderRule(opts) {
|
|
|
47
64
|
};
|
|
48
65
|
}
|
|
49
66
|
exports.createPrefixLoaderRule = createPrefixLoaderRule;
|
|
67
|
+
function createWebComponentLoaderRule(opts) {
|
|
68
|
+
return {
|
|
69
|
+
test: opts.webComponentPath instanceof RegExp ? opts.webComponentPath : /src\/([^/]+\/)*[^/]+\.(ts|tsx|js|jsx)$/,
|
|
70
|
+
type: 'javascript/auto',
|
|
71
|
+
exclude: /node_modules/,
|
|
72
|
+
use: [{ loader: constants_1.WEB_COMPONENT_LOADER }],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.createWebComponentLoaderRule = createWebComponentLoaderRule;
|
|
50
76
|
function applySemiRules(opts) {
|
|
51
77
|
const rules = [];
|
|
52
78
|
if (opts.omitCss) {
|
|
53
79
|
rules.push(createOmitCssLoaderRule(opts));
|
|
54
|
-
|
|
80
|
+
if (!opts.webComponentPath) {
|
|
81
|
+
return rules;
|
|
82
|
+
}
|
|
55
83
|
}
|
|
56
84
|
rules.push(createSourceSuffixLoaderRule(opts));
|
|
57
85
|
rules.push(createThemeLoaderRule(opts));
|
|
58
86
|
if (opts.prefixCls) {
|
|
59
87
|
rules.push(createPrefixLoaderRule(opts));
|
|
60
88
|
}
|
|
89
|
+
if (opts.webComponentPath) {
|
|
90
|
+
rules.push(createWebComponentLoaderRule(opts));
|
|
91
|
+
}
|
|
61
92
|
return rules;
|
|
62
93
|
}
|
|
63
94
|
exports.applySemiRules = applySemiRules;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export interface SemiWebpackPluginOptions {
|
|
2
2
|
theme?: SemiThemeOptions | SemiThemeOptions['name'];
|
|
3
|
+
cssLayer?: boolean;
|
|
3
4
|
prefixCls?: string;
|
|
4
5
|
variables?: Record<string, string | number>;
|
|
5
6
|
include?: string;
|
|
6
7
|
omitCss?: boolean;
|
|
8
|
+
webComponentPath?: boolean | RegExp;
|
|
7
9
|
}
|
|
8
10
|
export interface SemiThemeOptions {
|
|
9
11
|
name?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-rspack-plugin",
|
|
3
|
-
"version": "2.59.0
|
|
3
|
+
"version": "2.59.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/core": "^7.15.4",
|
|
22
|
-
"
|
|
22
|
+
"css-loader": "4.3.0",
|
|
23
|
+
"enhanced-resolve": "^5.8.3",
|
|
24
|
+
"raw-loader": "^4.0.2",
|
|
25
|
+
"sass-loader": "^10.1.1"
|
|
23
26
|
},
|
|
24
27
|
"peerDependencies": {
|
|
25
28
|
"webpack": "^5"
|
|
@@ -30,5 +33,5 @@
|
|
|
30
33
|
"typescript": "^4",
|
|
31
34
|
"webpack": "^5.77.0"
|
|
32
35
|
},
|
|
33
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "b9a08d8581277fdc6ae9c33cdfc78b39938e5de1"
|
|
34
37
|
}
|