@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
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
function validator(opts) {
|
8
|
+
if (!opts || typeof opts !== 'object') {
|
9
|
+
throw new Error('Always requires argment');
|
10
|
+
}
|
11
|
+
|
12
|
+
const {
|
13
|
+
before,
|
14
|
+
after
|
15
|
+
} = opts;
|
16
|
+
|
17
|
+
if (!before || !after) {
|
18
|
+
throw new Error('Be sure to have "before" and "after" object names');
|
19
|
+
}
|
20
|
+
|
21
|
+
if (!Array.isArray(before) || !Array.isArray(after)) {
|
22
|
+
throw new Error('Objects "before" and "after" must be of type Array');
|
23
|
+
}
|
24
|
+
|
25
|
+
if (before.length !== after.length) {
|
26
|
+
throw new Error('Length of before and after options must be the same');
|
27
|
+
}
|
28
|
+
|
29
|
+
if (before.length === 0) {
|
30
|
+
throw new Error('Array length is 1 or more');
|
31
|
+
}
|
32
|
+
|
33
|
+
before.forEach((beforeOpt, idx) => {
|
34
|
+
const afterOpt = after[idx];
|
35
|
+
|
36
|
+
switch (true) {
|
37
|
+
case typeof beforeOpt === 'string':
|
38
|
+
{
|
39
|
+
if (!typeof afterOpt === 'string') {
|
40
|
+
throw new Error(`The after option ${afterOpt} must be a string. If you want to apply the replace callback function, then use a RegExp for the before option`);
|
41
|
+
}
|
42
|
+
|
43
|
+
break;
|
44
|
+
}
|
45
|
+
|
46
|
+
case beforeOpt instanceof RegExp:
|
47
|
+
{
|
48
|
+
if (!typeof afterOpt === 'string' && !typeof afterOpt === 'function') {
|
49
|
+
throw new Error(`The after option ${afterOpt} must be either a string, or a function`);
|
50
|
+
}
|
51
|
+
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
|
55
|
+
default:
|
56
|
+
throw new Error(`The before option ${beforeOpt} must be either a string, or a RegExp`);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
module.exports = _postcss.default.plugin('postcss-selector-replace-new', opts => {
|
62
|
+
validator(opts);
|
63
|
+
const {
|
64
|
+
before,
|
65
|
+
after
|
66
|
+
} = opts;
|
67
|
+
return root => {
|
68
|
+
root.walkRules(rule => {
|
69
|
+
before.forEach((beforeOpt, idx) => {
|
70
|
+
const afterOpt = after[idx];
|
71
|
+
|
72
|
+
if (typeof beforeOpt === 'string') {
|
73
|
+
rule.selector = rule.selector.split(beforeOpt).join(afterOpt);
|
74
|
+
} else {
|
75
|
+
rule.selector = rule.selector.replace(beforeOpt, afterOpt);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
});
|
79
|
+
};
|
80
|
+
});
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
18
18
|
// }
|
19
19
|
// };
|
20
20
|
// });
|
21
|
-
// export default
|
21
|
+
// export default
|
22
22
|
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
23
23
|
root => {
|
24
24
|
root.walkDecls(decl => {
|
@@ -31,16 +31,5 @@ root => {
|
|
31
31
|
}
|
32
32
|
}); //console.log({root, roots:root+""}, root+"")
|
33
33
|
// Transform CSS AST here
|
34
|
-
});
|
35
|
-
// valueReplacer.forEach(obj => {
|
36
|
-
// if (
|
37
|
-
// obj.props.indexOf(decl.prop) !== -1 &&
|
38
|
-
// obj.values[decl.value] !== undefined
|
39
|
-
// ) {
|
40
|
-
// decl.value = obj.values[decl.value];
|
41
|
-
// }
|
42
|
-
// });
|
43
|
-
// //console.log({root, roots:root+""}, root+"")
|
44
|
-
// // Transform CSS AST here
|
45
|
-
// });
|
34
|
+
});
|
46
35
|
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
let settings1 = {
|
4
|
+
selectorReplace: {
|
5
|
+
before: [':root', 'data-mode', 'data-theme'],
|
6
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'data-desk-mode', 'data-desk-theme']
|
7
|
+
}
|
8
|
+
};
|
9
|
+
let settings2 = {
|
10
|
+
selectorReplace: {
|
11
|
+
before: [':root', 'data-'],
|
12
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'test-']
|
13
|
+
}
|
14
|
+
}; //error case
|
15
|
+
|
16
|
+
let settings3 = {
|
17
|
+
selectorReplace: {
|
18
|
+
before: [':root', 'data-'],
|
19
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__']
|
20
|
+
}
|
21
|
+
}; //error case
|
22
|
+
|
23
|
+
let settings4 = {
|
24
|
+
selectorReplace: {
|
25
|
+
before: [':root'],
|
26
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'test-']
|
27
|
+
}
|
28
|
+
}; // here conversion happens for data from one index to another
|
@@ -10,8 +10,6 @@ const {
|
|
10
10
|
ErrorHandler
|
11
11
|
} = require('./ErrorHandler');
|
12
12
|
|
13
|
-
const errors = [];
|
14
|
-
const errorTable = [];
|
15
13
|
const errHandler = new ErrorHandler();
|
16
14
|
const convertableProps = {
|
17
15
|
'font-size': true,
|
@@ -121,7 +119,7 @@ const singleConvertor = (value, changeVal, details, range) => {
|
|
121
119
|
// console.log(value, 'not within range')
|
122
120
|
|
123
121
|
|
124
|
-
|
122
|
+
const errObj = {
|
125
123
|
decl,
|
126
124
|
type: 'RANGE_ERROR',
|
127
125
|
filename,
|
@@ -129,25 +127,7 @@ const singleConvertor = (value, changeVal, details, range) => {
|
|
129
127
|
path: path
|
130
128
|
};
|
131
129
|
errHandler.errorTable.push(errObj);
|
132
|
-
errHandler.errorFunction(errObj);
|
133
|
-
// {
|
134
|
-
// decl,
|
135
|
-
// type: 'RANGE_ERROR',
|
136
|
-
// filename,
|
137
|
-
// message: `value (${value}) (${typeof value}) not within range (${
|
138
|
-
// range.start
|
139
|
-
// },${range.end})\r`,
|
140
|
-
// path: path
|
141
|
-
// },
|
142
|
-
// 'RANGE_ERROR'
|
143
|
-
// );
|
144
|
-
// }
|
145
|
-
// addError(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n message : value (${value}) not within range (${range.start},${range.end})\r`)
|
146
|
-
// return value;
|
147
|
-
// } else {
|
148
|
-
// console.log('++++++++++++++++++++++rect val!', value);
|
149
|
-
// }
|
150
|
-
|
130
|
+
errHandler.errorFunction(errObj);
|
151
131
|
return;
|
152
132
|
};
|
153
133
|
|
@@ -195,7 +175,7 @@ module.exports = {
|
|
195
175
|
// }
|
196
176
|
|
197
177
|
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase().includes(commentStr)) {
|
198
|
-
|
178
|
+
const errObj = {
|
199
179
|
decl,
|
200
180
|
type: 'DECLARATION_IGNORED',
|
201
181
|
filename,
|
@@ -258,7 +238,7 @@ module.exports = {
|
|
258
238
|
} else {
|
259
239
|
if (!decl.value.includes('calc')) {
|
260
240
|
// addError(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n unit : ${unitErrorVal} ,\n message : ${unitErrorVal} (Unit) Not Allowed \r`);
|
261
|
-
|
241
|
+
const errObj = {
|
262
242
|
decl,
|
263
243
|
filename,
|
264
244
|
unitErrorVal: unitErrorVal,
|
@@ -288,27 +268,29 @@ module.exports = {
|
|
288
268
|
}
|
289
269
|
}
|
290
270
|
} else {
|
291
|
-
if (decl.value && decl.value.includes('px') && decl.value.includes('var(--')
|
292
|
-
|
293
|
-
|
271
|
+
if (settingsObject[decl.prop] && decl.value && decl.value.includes('px') && decl.value.includes('var(--')) {
|
272
|
+
const valArr = decl.value.split(' ');
|
273
|
+
const settings = settingsObject[decl.prop];
|
294
274
|
const {
|
295
275
|
range
|
296
276
|
} = settings;
|
297
|
-
valArr.
|
277
|
+
const convertedVals = valArr.map(val => {
|
298
278
|
if (val.includes('px')) {
|
299
|
-
|
279
|
+
const convertedVal = singleConvertor(val, settings.replacements.px, {
|
300
280
|
decl,
|
301
281
|
filename,
|
302
282
|
path: fromPath
|
303
283
|
}, range);
|
304
|
-
|
284
|
+
return convertedVal ? convertedVal : val;
|
305
285
|
}
|
286
|
+
|
287
|
+
return val;
|
306
288
|
});
|
307
|
-
decl.value =
|
289
|
+
decl.value = convertedVals.join(' ');
|
308
290
|
}
|
309
291
|
|
310
292
|
if (decl.prop && decl.value && !decl.prop.includes('--') && valRegex.test(decl.value) && (settingsObject[decl.prop] || convertableProps[decl.prop]) && decl.value.includes('var') && !decl.value.includes('calc')) {
|
311
|
-
|
293
|
+
const errObj = {
|
312
294
|
decl,
|
313
295
|
type: 'VARIABLE_PRESENT',
|
314
296
|
filename,
|
@@ -101,7 +101,7 @@ module.exports = postcss.plugin('postcss-variable-report', () => rootOriginal =>
|
|
101
101
|
rule.walkDecls((decl, position) => {
|
102
102
|
// case font-size
|
103
103
|
if (!hasIgnoreComment(rule.nodes[position - 1])) {
|
104
|
-
console.log(settings)
|
104
|
+
// console.log(settings)
|
105
105
|
let unit = decl.value.replace(/[0-9]/g, '');
|
106
106
|
let settings = numberObject[decl.prop];
|
107
107
|
let path = rootOriginal.source.input.from;
|
package/lib/schemas/index.js
CHANGED
@@ -222,12 +222,28 @@ var _default = {
|
|
222
222
|
cli: 'enable_smaphook'
|
223
223
|
},
|
224
224
|
plugins: {
|
225
|
+
valueReplacer: false,
|
226
|
+
selectorReplace: false,
|
225
227
|
hasRTL: false,
|
226
228
|
hoverActive: false,
|
227
229
|
combinerMediaQuery: false,
|
228
230
|
cssVariableReplacement: false,
|
229
|
-
selectorWeight: false
|
231
|
+
selectorWeight: false,
|
232
|
+
minifier: false,
|
233
|
+
composeMinification: false
|
230
234
|
},
|
235
|
+
patterns: {
|
236
|
+
valueReplacer: [],
|
237
|
+
selectorReplace: [],
|
238
|
+
hoverActive: [],
|
239
|
+
combinerMediaQuery: [],
|
240
|
+
hasRTL: [],
|
241
|
+
cssVariableReplacement: [],
|
242
|
+
selectorWeight: [],
|
243
|
+
cssUniqueness: [],
|
244
|
+
composeMinification: []
|
245
|
+
},
|
246
|
+
patternsRootDir: '',
|
231
247
|
exclude: {
|
232
248
|
rtl: [],
|
233
249
|
hoverActive: [],
|
@@ -235,6 +251,10 @@ var _default = {
|
|
235
251
|
cssVariableReplacement: [],
|
236
252
|
selectorWeight: []
|
237
253
|
},
|
254
|
+
include: {
|
255
|
+
cssVariableReplacement: [],
|
256
|
+
selectorWeight: []
|
257
|
+
},
|
238
258
|
cssVariableReplacementConfig: '',
|
239
259
|
selectorWeightConfig: {
|
240
260
|
defaultSelector: '',
|
@@ -319,11 +339,22 @@ var _default = {
|
|
319
339
|
hasRTL: false,
|
320
340
|
rtlExclude: [],
|
321
341
|
plugins: {
|
322
|
-
|
342
|
+
rtl: false,
|
323
343
|
hoverActive: false,
|
324
344
|
combinerMediaQuery: false,
|
325
345
|
cssVariableReplacement: false,
|
326
|
-
selectorWeight: false
|
346
|
+
selectorWeight: false,
|
347
|
+
minifier: false
|
348
|
+
},
|
349
|
+
patternsRootDir: '',
|
350
|
+
patterns: {
|
351
|
+
valueReplacer: [],
|
352
|
+
selectorReplace: [],
|
353
|
+
hoverActive: [],
|
354
|
+
combinerMediaQuery: [],
|
355
|
+
hasRTL: [],
|
356
|
+
cssVariableReplacement: [],
|
357
|
+
selectorWeight: []
|
327
358
|
},
|
328
359
|
exclude: {
|
329
360
|
rtl: [],
|
package/lib/servers/server.js
CHANGED
@@ -204,8 +204,8 @@ if (httpsOptions) {
|
|
204
204
|
port: http2Port
|
205
205
|
}, 'htt' + 'ps')}${contextURL}/`, 'http2 server');
|
206
206
|
});
|
207
|
-
} else {
|
208
|
-
(0, _utils.log)(
|
207
|
+
} else if (httpsOptions) {
|
208
|
+
(0, _utils.log)('Your node version didn\'t adopted http2 support. Kindly update that to 8 LTS or above you can engage the http2');
|
209
209
|
}
|
210
210
|
}
|
211
211
|
|
@@ -9,6 +9,8 @@ var _os = _interopRequireDefault(require("os"));
|
|
9
9
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
11
11
|
|
12
|
+
var _fileHandling = require("../plugins/utils/fileHandling");
|
13
|
+
|
12
14
|
var _getHash = _interopRequireDefault(require("./getHash"));
|
13
15
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -39,17 +41,47 @@ let isSelectorPackage = (resourcePath, packages) => {
|
|
39
41
|
var _default = (unique = true, {
|
40
42
|
filenames,
|
41
43
|
packages
|
42
|
-
}, classNamePrefix) => (context, localIdentName, localName) => {
|
44
|
+
}, classNamePrefix, patterns, rootDir) => (context, localIdentName, localName) => {
|
45
|
+
// console.log(patterns, context.resourcePath);
|
43
46
|
// NOTE: in build macine we use date as folder path.
|
44
47
|
// So every time we create new build there is path will alway different
|
45
48
|
// in order to minmaze that problem we try in relative path;
|
46
49
|
// console.log('context.resourcePath', context.resourcePath, context);
|
47
50
|
// let contextResourcePath = context.resourcePath;
|
51
|
+
let filePaths = context.resourcePath.split(_path.default.sep);
|
52
|
+
let fileName = filePaths[filePaths.length - 1];
|
53
|
+
let [fileNameWithoutExt] = fileName.split('.');
|
54
|
+
let cleanFileName = fileNameWithoutExt.replace(/-/g, '_').toLowerCase();
|
55
|
+
|
48
56
|
let relativePath = _path.default.relative(context.rootContext, context.resourcePath);
|
57
|
+
/*
|
58
|
+
input :
|
59
|
+
context.resourcePath : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
60
|
+
|
61
|
+
patterns.cssVariableReplacement:
|
62
|
+
// include src folder, include deskapp folder, exclude node modules
|
63
|
+
"cssUniqueness": [
|
64
|
+
"src",
|
65
|
+
"deskapp",
|
66
|
+
"!node_modules"
|
67
|
+
]
|
68
|
+
rootDir : patternsRootDir : 'supportapp'
|
69
|
+
output :
|
70
|
+
true or false
|
71
|
+
*/
|
72
|
+
|
49
73
|
|
50
74
|
if (context.resourcePath.endsWith('.plain.css')) {
|
51
75
|
return localName;
|
52
76
|
}
|
77
|
+
|
78
|
+
if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
|
79
|
+
filename: context.resourcePath,
|
80
|
+
filterArr: patterns.cssUniqueness,
|
81
|
+
rootDir
|
82
|
+
})) {
|
83
|
+
return `${classNamePrefix}-${cleanFileName}-${localName}`;
|
84
|
+
}
|
53
85
|
/* old production mode start without breaking so added. may be removed in future*/
|
54
86
|
|
55
87
|
|
@@ -58,14 +90,10 @@ var _default = (unique = true, {
|
|
58
90
|
return `${classNamePrefix}${h}`;
|
59
91
|
}
|
60
92
|
/* old production mode end*/
|
61
|
-
|
62
|
-
|
63
|
-
let filePaths = context.resourcePath.split(_path.default.sep);
|
64
|
-
let fileName = filePaths[filePaths.length - 1];
|
65
|
-
let [fileNameWithoutExt] = fileName.split('.');
|
66
|
-
let cleanFileName = fileNameWithoutExt.replace(/-/g, '_').toLowerCase(); //css file has casesensitive selector issue so can't toLowerCase
|
93
|
+
//css file has casesensitive selector issue so can't toLowerCase
|
67
94
|
//let local = localName.toLowerCase()
|
68
95
|
|
96
|
+
|
69
97
|
if (isSelectorPackage(context.resourcePath, packages) || filenames.indexOf(cleanFileName) !== -1) {
|
70
98
|
let h = (0, _getHash.default)(`${relativePath}-${localName}`, 10);
|
71
99
|
return `${classNamePrefix}${h}`;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2-exp.1",
|
4
4
|
"description": "A CLI tool for build modern web application and libraries",
|
5
5
|
"scripts": {
|
6
6
|
"init": "node ./lib/utils/init.js",
|
@@ -58,6 +58,7 @@
|
|
58
58
|
"compression": "1.7.4",
|
59
59
|
"copy-webpack-plugin": "5.1.2",
|
60
60
|
"css-loader": "4.2.1",
|
61
|
+
"csso": "^5.0.5",
|
61
62
|
"escodegen": "2.0.0",
|
62
63
|
"eslint": "7.6.0",
|
63
64
|
"eslint-html-reporter": "0.7.4",
|
@@ -74,6 +75,7 @@
|
|
74
75
|
"html-webpack-inject-attributes-plugin": "1.0.6",
|
75
76
|
"html-webpack-plugin": "4.3.0",
|
76
77
|
"http-proxy-middleware": "1.0.5",
|
78
|
+
"ignore": "^5.2.4",
|
77
79
|
"jest": "26.4.0",
|
78
80
|
"jsdom": "16.4.0",
|
79
81
|
"loader-utils": "2.0.0",
|
@@ -88,7 +90,6 @@
|
|
88
90
|
"postcss-hash-classname": "0.4.0",
|
89
91
|
"postcss-loader": "3.0.0",
|
90
92
|
"postcss-mobile-hover": "1.0.2",
|
91
|
-
"postcss-selector-replace": "1.0.2",
|
92
93
|
"react-test-renderer": "16.13.1",
|
93
94
|
"redis": "3.0.2",
|
94
95
|
"redux-mock-store": "1.5.4",
|
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
9
|
-
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
-
|
12
|
-
class ComposeCommonPlugin {
|
13
|
-
constructor(options = {}) {
|
14
|
-
this.optimize = options.optimize;
|
15
|
-
}
|
16
|
-
|
17
|
-
apply(compiler) {
|
18
|
-
compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
|
19
|
-
compilation.hooks.optimizeModules.tap('OptimizeMods', modules => {
|
20
|
-
modules.forEach(module => {
|
21
|
-
console.log(module);
|
22
|
-
});
|
23
|
-
});
|
24
|
-
});
|
25
|
-
}
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
var _default = ComposeCommonPlugin;
|
30
|
-
exports.default = _default;
|
@@ -1,37 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
var _webpackSources = require("webpack-sources");
|
9
|
-
|
10
|
-
var _csso = require("csso");
|
11
|
-
|
12
|
-
class cssoPlugin {
|
13
|
-
apply(compiler) {
|
14
|
-
compiler.hooks.emit.tap('cssoPlugin', compilation => {
|
15
|
-
Object.keys(compilation.assets).forEach(filename => {
|
16
|
-
if (/\.css$/.test(filename)) {
|
17
|
-
// console.log(filename, ' processed!');
|
18
|
-
try {
|
19
|
-
let asset = compilation.assets[filename].source();
|
20
|
-
|
21
|
-
if (typeof asset !== 'string') {
|
22
|
-
asset = asset.toString();
|
23
|
-
}
|
24
|
-
|
25
|
-
const result = (0, _csso.minify)(asset).css;
|
26
|
-
compilation.assets[filename] = new _webpackSources.RawSource(result);
|
27
|
-
} catch (e) {
|
28
|
-
compilation.errors.push(e);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
});
|
32
|
-
});
|
33
|
-
}
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
exports.default = cssoPlugin;
|
@@ -1,57 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.checkPattern = checkPattern;
|
7
|
-
exports.negateArray = negateArray;
|
8
|
-
|
9
|
-
function checkPattern(filename, pattern) {
|
10
|
-
let isMatching = false;
|
11
|
-
|
12
|
-
if (pattern === '*') {
|
13
|
-
// console.log('case 3');
|
14
|
-
isMatching = true;
|
15
|
-
} else if (/^!/gi.test(pattern) && filename.includes(pattern)) {
|
16
|
-
// console.log('case 1');
|
17
|
-
isMatching = false;
|
18
|
-
} else if (!/^!/gi.test(pattern) && filename.includes(pattern)) {
|
19
|
-
// console.log('case 2');
|
20
|
-
isMatching = true;
|
21
|
-
}
|
22
|
-
|
23
|
-
return isMatching;
|
24
|
-
}
|
25
|
-
|
26
|
-
function negateArray(arr) {
|
27
|
-
const temp = [...arr];
|
28
|
-
temp.forEach((x, index) => {
|
29
|
-
if (/^!/gi.test(x)) {
|
30
|
-
arr[index] = x.substring(1);
|
31
|
-
} else {
|
32
|
-
arr[index] = `!${x}`;
|
33
|
-
}
|
34
|
-
});
|
35
|
-
return temp;
|
36
|
-
} // const pattern1 = ["*","src/","src/**/avatar","!src/components",];
|
37
|
-
// const examplesInputs1 = [
|
38
|
-
// "D:/Mywork/desk_client_app/src/components/component.css",
|
39
|
-
// "D:/Mywork/desk_client_app/src/components/avatar/avatar.css",
|
40
|
-
// "D:/Mywork/desk_client_app/src/components/teamavatar/avatar.css",
|
41
|
-
// "D:/Mywork/desk_client_app/src/container/teamavatar/avatar.css",
|
42
|
-
// "D:/Mywork/desk_client_app/deskapp/container/teamavatar/avatar.css",
|
43
|
-
// ]
|
44
|
-
// const pattern2 = ["src/","!src/components","src/components/avatar"];
|
45
|
-
// const examplesInputs2 = [
|
46
|
-
// "D:/Mywork/desk_client_app/src/components/component.css",
|
47
|
-
// "D:/Mywork/desk_client_app/src/components/avatar/avatar.css",
|
48
|
-
// "D:/Mywork/desk_client_app/src/components/teamavatar/avatar.css",
|
49
|
-
// "D:/Mywork/desk_client_app/src/container/teamavatar/avatar.css",
|
50
|
-
// "D:/Mywork/desk_client_app/deskapp/container/teamavatar/avatar.css",
|
51
|
-
// ]
|
52
|
-
// console.log(checkPattern('filename', ["*","src/","!src/components","src/components/avatar"]))
|
53
|
-
// console.log(checkPattern(filename, pattern))
|
54
|
-
// console.log(checkPattern(filename, pattern))
|
55
|
-
// console.log(checkPattern(filename, pattern))
|
56
|
-
// console.log(checkPattern(filename, pattern))
|
57
|
-
// console.log(checkPattern(filename, pattern))
|