@zohodesk/react-cli 1.0.1-exp.1 → 1.0.2-exp.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +13 -0
- package/docs/SelectorWeight.md +3 -0
- package/docs/VariableConversion.md +6 -1
- package/lib/configs/webpack.dev.config.js +6 -0
- package/lib/configs/webpack.docs.config.js +4 -0
- package/lib/configs/webpack.impact.config.js +4 -0
- package/lib/configs/webpack.prod.config.js +6 -0
- package/lib/loaderUtils/getCSSLoaders.js +79 -50
- package/lib/loaderUtils/tests/windowsModification.test.js +10 -0
- package/lib/loaderUtils/windowsModification.js +6 -1
- package/lib/loaders/composeLoader.js +175 -0
- package/lib/pluginUtils/getDevPlugins.js +13 -2
- package/lib/pluginUtils/getProdPlugins.js +1 -1
- package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
- package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
- package/lib/plugins/{UglifyCSSPlugin.js → MinifyPlugin.js} +3 -3
- package/lib/plugins/SelectorPlugin.js +60 -72
- package/lib/plugins/VariableConversionCollector.js +38 -29
- package/lib/plugins/index.js +15 -7
- package/lib/plugins/utils/classHandling.js +2 -10
- package/lib/plugins/utils/fileHandling.js +70 -100
- package/lib/plugins/utils/tests/fileHandling.test.js +30 -0
- package/lib/postcss-plugins/EmptyPlugin.js +8 -0
- package/lib/postcss-plugins/ExcludePlugin.js +1 -1
- package/lib/postcss-plugins/SelectorReplace.js +80 -0
- package/lib/postcss-plugins/ValueReplacer.js +2 -13
- package/lib/postcss-plugins/__test__/selectorReplace.test.js +28 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +0 -1
- package/lib/postcss-plugins/variableModificationPlugin/index.js +14 -32
- package/lib/postcss-plugins/variableModifier.js +1 -1
- package/lib/schemas/index.js +34 -3
- package/lib/servers/server.js +2 -2
- package/lib/utils/cssClassNameGenerate.js +35 -7
- package/package.json +3 -2
- package/lib/plugins/composeCommonPlugin.js +0 -30
- package/lib/plugins/cssoPlugin.js +0 -37
- package/lib/plugins/utils/checkPattern.js +0 -57
package/README.md
CHANGED
@@ -44,6 +44,19 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.0.2
|
48
|
+
|
49
|
+
**Feature Update**
|
50
|
+
- Selector replace plugin made as a custom postcss-plugin with update to code that was unpublished in package.
|
51
|
+
|
52
|
+
# 1.0.1
|
53
|
+
|
54
|
+
**Issue Fix**
|
55
|
+
- variable conversion for px and var(--) values in same declaration was not supported, now it is supported.
|
56
|
+
- package-lock.json removed from `.npmignore`
|
57
|
+
|
58
|
+
**Feature Update**
|
59
|
+
- exclude added to Selector Plugin
|
47
60
|
# 1.0.0
|
48
61
|
## Major Release
|
49
62
|
**Changes:**
|
package/docs/SelectorWeight.md
CHANGED
@@ -4,3 +4,6 @@
|
|
4
4
|
* all classes in all files will be added with the `defaultSelector` provided in package.json to increase selector weight
|
5
5
|
* in case a specific chunk file is supposed to have a different selector, it can be mentioned in the `customFileSelectorWeight.json`. This will add the new selector to that particular chunk file.
|
6
6
|
* `excludeStrings` is an array used to exclude selectors that should not be converted. Default selectors such as body, html are excluded through this way.
|
7
|
+
|
8
|
+
# v1.0.1 update:
|
9
|
+
* exclude support added, file paths to be added in `react-cli > app > exclude > selectorWeight` to be excluded from conversion.
|
@@ -4,8 +4,13 @@
|
|
4
4
|
|
5
5
|
Conversion for Variables from Variables to px in Supportapp completed (`variableIgnore.js` && `pxParserPostcss.js` to be referred to), and px to custom variables through the new `variableModificationPlugin`. Error Log generation can also be converted on enabling
|
6
6
|
|
7
|
+
|
8
|
+
**Issue Fix**
|
9
|
+
# Issue fix done in `1.0.1`
|
10
|
+
- variable conversion for px and var(--) values in same declaration was not supported, now it is supported.
|
11
|
+
|
7
12
|
**Features:**
|
8
|
-
# Features below are added
|
13
|
+
# Features below are added from `0.0.1-beta.173`
|
9
14
|
1. variables are converted from px to custom variables ( options are consumed from `cssVariableReplacementOptions.json` present in source folder )
|
10
15
|
2. To enable the error log generation `errorLog` is to be made `true` in `cssVariableReplacementOptions.json` ( it will take a little longer than usual build time )
|
11
16
|
3. To enable the console display of errors that are generated, `errorInConsole` is to be made `true` in `cssVariableReplacementOptions.json`
|
@@ -25,6 +25,8 @@ const {
|
|
25
25
|
outputFolder,
|
26
26
|
plugins,
|
27
27
|
exclude,
|
28
|
+
patterns,
|
29
|
+
patternsRootDir,
|
28
30
|
mediaQueryHoverActiveString,
|
29
31
|
cssVariableReplacementConfig,
|
30
32
|
selectorWeightConfig,
|
@@ -102,6 +104,8 @@ module.exports = {
|
|
102
104
|
use: (0, _loaderUtils.getCSSLoaders)({
|
103
105
|
plugins,
|
104
106
|
exclude,
|
107
|
+
patterns,
|
108
|
+
patternsRootDir,
|
105
109
|
mediaQueryHoverActiveString,
|
106
110
|
cssVariableReplacementConfig,
|
107
111
|
selectorWeightConfig,
|
@@ -114,6 +118,8 @@ module.exports = {
|
|
114
118
|
use: (0, _loaderUtils.getCSSLoaders)({
|
115
119
|
plugins,
|
116
120
|
exclude,
|
121
|
+
patterns,
|
122
|
+
patternsRootDir,
|
117
123
|
mediaQueryHoverActiveString,
|
118
124
|
cssVariableReplacementConfig,
|
119
125
|
selectorWeightConfig,
|
@@ -22,6 +22,8 @@ const {
|
|
22
22
|
cssUniqueness,
|
23
23
|
plugins,
|
24
24
|
exclude,
|
25
|
+
patterns,
|
26
|
+
patternsRootDir,
|
25
27
|
mediaQueryHoverActiveString,
|
26
28
|
cssVariableReplacementConfig,
|
27
29
|
selectorWeightConfig,
|
@@ -77,6 +79,8 @@ module.exports = isSSTest => ({
|
|
77
79
|
use: (0, _loaderUtils.getCSSLoaders)({
|
78
80
|
plugins,
|
79
81
|
exclude,
|
82
|
+
patterns,
|
83
|
+
patternsRootDir,
|
80
84
|
mediaQueryHoverActiveString,
|
81
85
|
cssVariableReplacementConfig,
|
82
86
|
selectorWeightConfig,
|
@@ -21,6 +21,8 @@ const {
|
|
21
21
|
cssUniqueness,
|
22
22
|
plugins,
|
23
23
|
exclude,
|
24
|
+
patterns,
|
25
|
+
patternsRootDir,
|
24
26
|
mediaQueryHoverActiveString,
|
25
27
|
cssVariableReplacementConfig,
|
26
28
|
selectorWeightConfig,
|
@@ -77,6 +79,8 @@ module.exports = {
|
|
77
79
|
use: (0, _loaderUtils.getCSSLoaders)({
|
78
80
|
plugins,
|
79
81
|
exclude,
|
82
|
+
patterns,
|
83
|
+
patternsRootDir,
|
80
84
|
mediaQueryHoverActiveString,
|
81
85
|
cssVariableReplacementConfig,
|
82
86
|
selectorWeightConfig,
|
@@ -29,6 +29,8 @@ const {
|
|
29
29
|
server,
|
30
30
|
plugins,
|
31
31
|
exclude,
|
32
|
+
patterns,
|
33
|
+
patternsRootDir,
|
32
34
|
mediaQueryHoverActiveString,
|
33
35
|
cssVariableReplacementConfig,
|
34
36
|
selectorWeightConfig,
|
@@ -153,6 +155,8 @@ module.exports = {
|
|
153
155
|
use: (0, _loaderUtils.getCSSLoaders)({
|
154
156
|
plugins,
|
155
157
|
exclude,
|
158
|
+
patterns,
|
159
|
+
patternsRootDir,
|
156
160
|
cssVariableReplacementConfig,
|
157
161
|
selectorWeightConfig,
|
158
162
|
mediaQueryHoverActiveString,
|
@@ -165,6 +169,8 @@ module.exports = {
|
|
165
169
|
use: (0, _loaderUtils.getCSSLoaders)({
|
166
170
|
plugins,
|
167
171
|
exclude,
|
172
|
+
patterns,
|
173
|
+
patternsRootDir,
|
168
174
|
mediaQueryHoverActiveString,
|
169
175
|
cssVariableReplacementConfig,
|
170
176
|
selectorWeightConfig,
|
@@ -11,7 +11,7 @@ var _cssClassNameGenerate = _interopRequireDefault(require("../utils/cssClassNam
|
|
11
11
|
|
12
12
|
var _utils = require("../utils");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _fileHandling = require("../plugins/utils/fileHandling");
|
15
15
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
@@ -19,21 +19,11 @@ const fs = require('fs');
|
|
19
19
|
|
20
20
|
const options = (0, _utils.getOptions)();
|
21
21
|
|
22
|
-
function excludeEmptyCheckPlugin({
|
23
|
-
enable,
|
24
|
-
ignore,
|
25
|
-
plugins
|
26
|
-
}) {
|
27
|
-
return enable ? ignore.length === 0 ? plugins : [require('../postcss-plugins/ExcludePlugin')({
|
28
|
-
ignore,
|
29
|
-
plugins
|
30
|
-
})] : [];
|
31
|
-
}
|
32
|
-
|
33
22
|
const getCSSLoaders = optionsObj => {
|
34
23
|
const {
|
35
24
|
plugins,
|
36
|
-
|
25
|
+
patterns,
|
26
|
+
patternsRootDir,
|
37
27
|
mediaQueryHoverActiveString,
|
38
28
|
cssVariableReplacementConfig,
|
39
29
|
classNameBlob,
|
@@ -41,11 +31,7 @@ const getCSSLoaders = optionsObj => {
|
|
41
31
|
selectorReplace,
|
42
32
|
cssHashSelectors,
|
43
33
|
classNamePrefix
|
44
|
-
} = optionsObj;
|
45
|
-
// console.log(plugins)
|
46
|
-
// console.log('exclude:')
|
47
|
-
// console.log(exclude)
|
48
|
-
|
34
|
+
} = optionsObj;
|
49
35
|
const {
|
50
36
|
devCssFileBountry
|
51
37
|
} = options.app;
|
@@ -55,10 +41,6 @@ const getCSSLoaders = optionsObj => {
|
|
55
41
|
const {
|
56
42
|
cssSelectorZipPath
|
57
43
|
} = options.impactService;
|
58
|
-
const rtlExcludeLocal = (0, _windowsModification.windowsModification)(exclude.rtl);
|
59
|
-
const hoverActiveExcludeLocal = (0, _windowsModification.windowsModification)(exclude.hoverActive);
|
60
|
-
const combinerMediaQueryExcludeLocal = (0, _windowsModification.windowsModification)(exclude.combinerMediaQuery);
|
61
|
-
const cssVariableReplacementExcludeLocal = (0, _windowsModification.windowsModification)(exclude.cssVariableReplacement);
|
62
44
|
const cssLoaderOptions = {
|
63
45
|
// importLoaders: hasRTL||hoverActive ? 1 : 0,
|
64
46
|
importLoaders: 1,
|
@@ -69,35 +51,19 @@ const getCSSLoaders = optionsObj => {
|
|
69
51
|
if (classNameBlob) {
|
70
52
|
cssLoaderOptions.modules.localIdentName = classNameBlob;
|
71
53
|
} else {
|
72
|
-
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
|
54
|
+
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix, patterns, patternsRootDir);
|
73
55
|
} // console.log('selector weight config : ', selectorWeightConfig);
|
74
56
|
|
75
57
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
addPrefixToSelector: function addPrefixToSelector(selector, prefix) {
|
81
|
-
if (prefix === '[dir]') {
|
82
|
-
return selector;
|
83
|
-
}
|
84
|
-
|
85
|
-
return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
|
58
|
+
let postcssPlugins = [plugins.valueReplacer && require('../postcss-plugins/ValueReplacer')(valueReplacer), plugins.selectorReplace && require('../postcss-plugins/SelectorReplace')(selectorReplace), plugins.hasRTL && require('@zohodesk/postcss-rtl')({
|
59
|
+
addPrefixToSelector: function addPrefixToSelector(selector, prefix) {
|
60
|
+
if (prefix === '[dir]') {
|
61
|
+
return selector;
|
86
62
|
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
plugins: [require('postcss-combine-media-query')]
|
92
|
-
}), ...excludeEmptyCheckPlugin({
|
93
|
-
enable: plugins.hoverActive,
|
94
|
-
ignore: hoverActiveExcludeLocal,
|
95
|
-
plugins: [require('../postcss-plugins/hoverActivePlugin')(mediaQueryHoverActiveString)]
|
96
|
-
}), ...excludeEmptyCheckPlugin({
|
97
|
-
enable: plugins.cssVariableReplacement,
|
98
|
-
ignore: cssVariableReplacementExcludeLocal,
|
99
|
-
plugins: [fs.existsSync(cssVariableReplacementConfig) && require('../postcss-plugins/variableModificationPlugin/index').plugin(cssVariableReplacementConfig)]
|
100
|
-
})].filter(Boolean);
|
63
|
+
|
64
|
+
return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
|
65
|
+
}
|
66
|
+
}), plugins.combinerMediaQuery && require('postcss-combine-media-query')(), plugins.hoverActive && require('../postcss-plugins/hoverActivePlugin')(mediaQueryHoverActiveString), plugins.cssVariableReplacement && fs.existsSync(cssVariableReplacementConfig) && require('../postcss-plugins/variableModificationPlugin/index').plugin(cssVariableReplacementConfig)].filter(Boolean);
|
101
67
|
return [cssSelectorZipPath && {
|
102
68
|
loader: require.resolve('../loaders/selectorMappingLoader')
|
103
69
|
}, {
|
@@ -117,11 +83,74 @@ const getCSSLoaders = optionsObj => {
|
|
117
83
|
loader: 'postcss-loader',
|
118
84
|
options: {
|
119
85
|
ident: 'postcss',
|
120
|
-
plugins: function () {
|
121
|
-
|
86
|
+
plugins: function (params) {
|
87
|
+
// console.log('check here : ', params.resourcePath);
|
88
|
+
// getCSSLoaders for all postcss filtering
|
89
|
+
|
90
|
+
/*
|
91
|
+
input :
|
92
|
+
params.resourcePath : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
93
|
+
patterns : [
|
94
|
+
// include all files
|
95
|
+
"valueReplacer": [
|
96
|
+
"*"
|
97
|
+
],
|
98
|
+
// include all files
|
99
|
+
"selectorReplace": [
|
100
|
+
"*"
|
101
|
+
],
|
102
|
+
// include src folder, include deskapp folder, exclude node modules
|
103
|
+
"hoverActive": [
|
104
|
+
"src",
|
105
|
+
"deskapp",
|
106
|
+
"!node_modules"
|
107
|
+
],
|
108
|
+
// include src folder, include deskapp folder, exclude node modules
|
109
|
+
"combinerMediaQuery": [
|
110
|
+
"src",
|
111
|
+
"deskapp",
|
112
|
+
"!node_modules"
|
113
|
+
],
|
114
|
+
// include src folder, include deskapp folder, exclude node modules
|
115
|
+
"hasRTL": [
|
116
|
+
"src",
|
117
|
+
"deskapp",
|
118
|
+
"!node_modules"
|
119
|
+
],
|
120
|
+
// include src folder, include deskapp folder, exclude node modules
|
121
|
+
"cssVariableReplacement": [
|
122
|
+
"src",
|
123
|
+
"deskapp",
|
124
|
+
"!node_modules"
|
125
|
+
],
|
126
|
+
// include src folder, include deskapp folder, exclude node modules
|
127
|
+
"selectorWeight": [
|
128
|
+
"src",
|
129
|
+
"deskapp",
|
130
|
+
"!node_modules"
|
131
|
+
],
|
132
|
+
// include all files
|
133
|
+
"cssUniqueness": [
|
134
|
+
"*"
|
135
|
+
]
|
136
|
+
],
|
137
|
+
|
138
|
+
[ postcssPlugins that are implemented ]
|
139
|
+
rootDir : patternsRootDir : 'supportapp'
|
140
|
+
*/
|
141
|
+
postcssPlugins = (0, _fileHandling.isFileNameMatchingPattern)({
|
142
|
+
filename: params.resourcePath,
|
143
|
+
filterObject: patterns,
|
144
|
+
plugins: postcssPlugins,
|
145
|
+
rootDir: patternsRootDir
|
146
|
+
}); // postcssPlugins that are allowed
|
147
|
+
|
148
|
+
return postcssPlugins.length > 0 ? postcssPlugins : [require('../postcss-plugins/EmptyPlugin')()];
|
122
149
|
}
|
123
150
|
}
|
124
|
-
} : null
|
151
|
+
} : null, {
|
152
|
+
loader: require.resolve('../loaders/composeLoader')
|
153
|
+
}].filter(Boolean);
|
125
154
|
};
|
126
155
|
|
127
156
|
var _default = getCSSLoaders;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
windowsModificationFile
|
5
|
+
} = require('../windowsModification');
|
6
|
+
|
7
|
+
const tests = ['D:\\MyWork\\React Build\\desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'D:/MyWork/React Build/desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'src\\components\\Accessibility\\Accessibility.module.css', 'src/components/Accessibility/Accessibility.module.css', 'Accessibility.module.css', ''];
|
8
|
+
tests.forEach(test => {
|
9
|
+
console.log(windowsModificationFile(test));
|
10
|
+
});
|
@@ -4,8 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.windowsModification = windowsModification;
|
7
|
+
exports.windowsModificationFile = windowsModificationFile;
|
7
8
|
const isWin = process.platform === 'win32';
|
8
9
|
|
9
10
|
function windowsModification(array) {
|
10
11
|
return isWin ? array && Array.isArray(array) && array.map(r => r.replace(/\//g, '\\')) : array;
|
11
|
-
}
|
12
|
+
}
|
13
|
+
|
14
|
+
function windowsModificationFile(filename) {
|
15
|
+
return isWin ? filename.replace(/\//g, '\\') : filename;
|
16
|
+
} // module.exports = { windowsModification, windowsModificationFile };
|
@@ -0,0 +1,175 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
4
|
+
|
5
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
6
|
+
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
|
9
|
+
const supportedProps = ['margin-top', 'margin-bottom', 'margin-left', 'margin-right', // 'margin',
|
10
|
+
'padding-top', 'padding-bottom', 'padding-left', 'padding-right', // 'padding',
|
11
|
+
'top', 'bottom', 'left', 'right', 'height', 'width', 'min-height', 'min-width', 'max-height', 'max-width'];
|
12
|
+
const renameProps = {
|
13
|
+
'margin-top': {
|
14
|
+
pos: 'mt',
|
15
|
+
neg: 'mt_'
|
16
|
+
},
|
17
|
+
'margin-bottom': {
|
18
|
+
pos: 'mb',
|
19
|
+
neg: 'mb_'
|
20
|
+
},
|
21
|
+
'margin-left': {
|
22
|
+
pos: 'ml',
|
23
|
+
neg: 'ml_'
|
24
|
+
},
|
25
|
+
'margin-right': {
|
26
|
+
pos: 'mr',
|
27
|
+
neg: 'mr_'
|
28
|
+
},
|
29
|
+
margin: {
|
30
|
+
pos: 'm',
|
31
|
+
neg: 'm_'
|
32
|
+
},
|
33
|
+
'padding-top': {
|
34
|
+
pos: 'pt',
|
35
|
+
neg: 'pt_'
|
36
|
+
},
|
37
|
+
'padding-bottom': {
|
38
|
+
pos: 'pb',
|
39
|
+
neg: 'pb_'
|
40
|
+
},
|
41
|
+
'padding-left': {
|
42
|
+
pos: 'pl',
|
43
|
+
neg: 'pl_'
|
44
|
+
},
|
45
|
+
'padding-right': {
|
46
|
+
pos: 'pr',
|
47
|
+
neg: 'pr_'
|
48
|
+
},
|
49
|
+
padding: {
|
50
|
+
pos: 'p',
|
51
|
+
neg: 'p_'
|
52
|
+
},
|
53
|
+
top: {
|
54
|
+
pos: 'post',
|
55
|
+
neg: 'post_'
|
56
|
+
},
|
57
|
+
bottom: {
|
58
|
+
pos: 'posb',
|
59
|
+
neg: 'posb_'
|
60
|
+
},
|
61
|
+
left: {
|
62
|
+
pos: 'posl',
|
63
|
+
neg: 'posl_'
|
64
|
+
},
|
65
|
+
right: {
|
66
|
+
pos: 'posr',
|
67
|
+
neg: 'posr_'
|
68
|
+
},
|
69
|
+
height: {
|
70
|
+
pos: 'h',
|
71
|
+
neg: 'h_'
|
72
|
+
},
|
73
|
+
width: {
|
74
|
+
pos: 'w',
|
75
|
+
neg: 'w_'
|
76
|
+
},
|
77
|
+
'min-height': {
|
78
|
+
pos: 'minh',
|
79
|
+
neg: 'minh_'
|
80
|
+
},
|
81
|
+
'min-width': {
|
82
|
+
pos: 'minw',
|
83
|
+
neg: 'minw_'
|
84
|
+
},
|
85
|
+
'max-height': {
|
86
|
+
pos: 'maxh',
|
87
|
+
neg: 'maxh_'
|
88
|
+
},
|
89
|
+
'max-width': {
|
90
|
+
pos: 'maxw',
|
91
|
+
neg: 'maxw_'
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
function objToClassName(prop, data) {
|
96
|
+
return renameProps[prop] ? data < 0 ? renameProps[prop].neg ? `${renameProps[prop].neg}${data * -1}` : `undef${data * -1}` : renameProps[prop].pos ? `${renameProps[prop].pos}${data}` : `undef${data}` : `undef${data}`;
|
97
|
+
}
|
98
|
+
|
99
|
+
const commonFilePath = {
|
100
|
+
'margin-left': 'src/common/css/margin.css',
|
101
|
+
'margin-right': 'src/common/css/margin.css',
|
102
|
+
'margin-top': 'src/common/css/margin.css',
|
103
|
+
'margin-bottom': 'src/common/css/margin.css',
|
104
|
+
'padding-left': 'src/common/css/padding.css',
|
105
|
+
'padding-right': 'src/common/css/padding.css',
|
106
|
+
'padding-top': 'src/common/css/padding.css',
|
107
|
+
'padding-bottom': 'src/common/css/padding.css',
|
108
|
+
top: 'src/common/css/position.css',
|
109
|
+
bottom: 'src/common/css/position.css',
|
110
|
+
left: 'src/common/css/position.css',
|
111
|
+
right: 'src/common/css/position.css',
|
112
|
+
height: 'src/common/css/height.css',
|
113
|
+
width: 'src/common/css/width.css',
|
114
|
+
'min-height': 'src/common/css/height.css',
|
115
|
+
'min-width': 'src/common/css/width.css',
|
116
|
+
'max-height': 'src/common/css/height.css',
|
117
|
+
'max-width': 'src/common/css/width.css'
|
118
|
+
};
|
119
|
+
const preNames = {
|
120
|
+
height: 'zd-height-',
|
121
|
+
'max-height': 'zd-height-',
|
122
|
+
'min-height': 'zd-height-',
|
123
|
+
width: 'zd-width-',
|
124
|
+
'max-width': 'zd-width-',
|
125
|
+
'min-width': 'zd-width-',
|
126
|
+
top: 'zd-position-',
|
127
|
+
bottom: 'zd-position-',
|
128
|
+
left: 'zd-position-',
|
129
|
+
right: 'zd-position-',
|
130
|
+
'padding-top': 'zd-padding-',
|
131
|
+
'padding-bottom': 'zd-padding-',
|
132
|
+
'padding-left': 'zd-padding-',
|
133
|
+
'padding-right': 'zd-padding-',
|
134
|
+
'margin-top': 'zd-margin-',
|
135
|
+
'margin-bottom': 'zd-margin-',
|
136
|
+
'margin-left': 'zd-margin-',
|
137
|
+
'margin-right': 'zd-margin-'
|
138
|
+
};
|
139
|
+
|
140
|
+
function allowParent(rule) {
|
141
|
+
return rule.parent.type === 'root' || rule.parent.type === 'atrule' && rule.parent.name === 'media';
|
142
|
+
}
|
143
|
+
|
144
|
+
module.exports = function (source) {
|
145
|
+
const {
|
146
|
+
rootContext,
|
147
|
+
resourcePath,
|
148
|
+
query
|
149
|
+
} = this;
|
150
|
+
|
151
|
+
let root = _postcss.default.parse(source);
|
152
|
+
|
153
|
+
root.walkRules(rule => {
|
154
|
+
rule.walkDecls(decl => {
|
155
|
+
if (!allowParent(rule)) {
|
156
|
+
return;
|
157
|
+
}
|
158
|
+
|
159
|
+
if (supportedProps.includes(decl.prop) && /px$/gi.test(decl.value) && !/^--/gi.test(decl.prop) && commonFilePath[decl.prop] && !decl.value.includes('calc') && !/[,\s+]+|(\w+)\.|:|(\d+)%/gi.test(rule.selector)) {
|
160
|
+
let composeString = `from "${_path.default.relative(_path.default.parse(resourcePath).dir, // resourcePath
|
161
|
+
commonFilePath[decl.prop]).replace(/\\/gi, '/')}"`; // n++ < 10 && console.log(composeString);
|
162
|
+
|
163
|
+
if (!composeString.includes('src')) {
|
164
|
+
const cls = objToClassName(decl.prop, parseInt(decl.value));
|
165
|
+
composeString = `${cls} ${composeString}`;
|
166
|
+
decl.value = composeString;
|
167
|
+
decl.prop = 'composes'; // n < 10 && console.log(rule.selector, decl.prop, decl.value);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
});
|
171
|
+
});
|
172
|
+
const output = root.toString(); // console.log(output);
|
173
|
+
|
174
|
+
return output;
|
175
|
+
};
|
@@ -48,6 +48,8 @@ const getDevPlugins = (options, publicPath) => {
|
|
48
48
|
hasShadowDOM,
|
49
49
|
cssVariableReplacementConfig,
|
50
50
|
plugins: pluginObject,
|
51
|
+
patterns,
|
52
|
+
patternsRootDir,
|
51
53
|
exclude,
|
52
54
|
selectorWeightConfig,
|
53
55
|
server: {
|
@@ -194,17 +196,26 @@ const getDevPlugins = (options, publicPath) => {
|
|
194
196
|
|
195
197
|
if (pluginObject.cssVariableReplacement) {
|
196
198
|
pluginsArr.push(new _VariableConversionCollector.default({
|
197
|
-
cssVariableReplacementConfig
|
199
|
+
cssVariableReplacementConfig,
|
200
|
+
patterns,
|
201
|
+
patternsRootDir
|
198
202
|
}));
|
199
203
|
}
|
200
204
|
|
201
205
|
if (pluginObject.selectorWeight) {
|
202
206
|
pluginsArr.push(new _SelectorPlugin.default({
|
203
207
|
selectorWeightConfig,
|
204
|
-
exclude: exclude.selectorWeight
|
208
|
+
exclude: exclude.selectorWeight,
|
209
|
+
patterns,
|
210
|
+
patternsRootDir
|
205
211
|
}));
|
206
212
|
}
|
207
213
|
|
214
|
+
if (pluginObject.minifier) {
|
215
|
+
// console.log('minifier active');
|
216
|
+
pluginsArr.push(new _plugins.MinifierPlugin());
|
217
|
+
}
|
218
|
+
|
208
219
|
return pluginsArr.filter(Boolean);
|
209
220
|
};
|
210
221
|
|
@@ -102,7 +102,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
102
102
|
// ignoreOrder: true,
|
103
103
|
filename: cssLTRFileNameTempalte,
|
104
104
|
chunkFilename: cssLTRFileNameTempalte
|
105
|
-
}), new _plugins.ResourceHintsPlugin(), new _plugins.
|
105
|
+
}), new _plugins.ResourceHintsPlugin(), new _plugins.MinifyPlugin()];
|
106
106
|
|
107
107
|
if (enableRTLSplit) {
|
108
108
|
pluginsArr.push(new _RtlCssPlugin.RtlCssPlugin({
|
@@ -11,9 +11,9 @@ var _uglifycss = _interopRequireDefault(require("uglifycss"));
|
|
11
11
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
|
14
|
-
class
|
14
|
+
class MinifierPlugin {
|
15
15
|
apply(compiler) {
|
16
|
-
compiler.hooks.emit.tap('
|
16
|
+
compiler.hooks.emit.tap('MinifierPlugin', compilation => {
|
17
17
|
Object.keys(compilation.assets).forEach(filename => {
|
18
18
|
if (/\.css$/.test(filename)) {
|
19
19
|
try {
|
@@ -36,4 +36,4 @@ class UglifyCSSPlugin {
|
|
36
36
|
|
37
37
|
}
|
38
38
|
|
39
|
-
exports.default =
|
39
|
+
exports.default = MinifierPlugin;
|