@zohodesk/react-cli 0.0.1-exp.164.1 → 0.0.1-exp.166.2
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/DOTO.md +13 -0
- package/README.md +32 -12
- package/bin/cli.js +22 -1
- package/docs/CustomChunks.md +26 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/warnings_while_install.txt +35 -0
- package/lib/common/splitChunks.js +48 -37
- package/lib/common/testPattern.js +0 -2
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +6 -1
- package/lib/configs/webpack.docs.config.js +30 -26
- package/lib/configs/webpack.prod.config.js +1 -1
- package/lib/loaderUtils/getCSSLoaders.js +17 -13
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- package/lib/schemas/index.js +12 -0
- package/lib/servers/devBulid.js +98 -0
- package/lib/servers/getCliPath.js +24 -0
- package/lib/servers/nowatchserver.js +9 -84
- package/lib/servers/server.js +9 -2
- package/lib/utils/rtl.js +19 -2
- package/lib/utils/useExitCleanup.js +55 -0
- package/package.json +1 -1
- package/lib/common/criteriaHandler.js +0 -91
- package/lib/common/splitChunks1.js +0 -95
- package/lib/common/splitChunksNew.js +0 -129
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
// module.exports = postcss.plugin('postcss-value-replacer', opts => {
|
8
|
+
// const { plugins } = opts;
|
9
|
+
// return (root, result) => {
|
10
|
+
// const inputFile = root.source.input.file;
|
11
|
+
// let isIgnoredFile= opts.ignore.some(file => inputFile.indexOf(file)!==-1);
|
12
|
+
// if (!isIgnoredFile) {
|
13
|
+
// const handler = response =>
|
14
|
+
// response.messages.forEach(msg => result.messages.push(msg));
|
15
|
+
// return postcss(plugins)
|
16
|
+
// .process(root, { from: undefined })
|
17
|
+
// .then(handler);
|
18
|
+
// }
|
19
|
+
// };
|
20
|
+
// });
|
21
|
+
// export default
|
22
|
+
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
23
|
+
root => {
|
24
|
+
root.walkDecls(decl => {
|
25
|
+
valueReplacer.forEach(obj => {
|
26
|
+
if (obj.props.indexOf(decl.prop) !== -1) {
|
27
|
+
let ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
28
|
+
ks.forEach(k => {
|
29
|
+
decl.value = decl.value.replace(k, obj.values[k]);
|
30
|
+
}); //decl.value = obj.values[decl.value];
|
31
|
+
}
|
32
|
+
}); //console.log({root, roots:root+""}, root+"")
|
33
|
+
// Transform CSS AST here
|
34
|
+
}); // root.walkDecls(decl => {
|
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
|
+
// });
|
46
|
+
});
|
package/lib/schemas/index.js
CHANGED
@@ -44,6 +44,17 @@ var _default = {
|
|
44
44
|
},
|
45
45
|
css: {
|
46
46
|
enableRTLSplit: false,
|
47
|
+
valueReplacer: null,
|
48
|
+
//valueReplacer: [
|
49
|
+
// {
|
50
|
+
// props: ['font', 'font-family'],
|
51
|
+
// values: {
|
52
|
+
// 'zdfonts-rCallBar': 'zdfonts-rCallBar01',
|
53
|
+
// 'zdfonts-rCall': 'zdfonts-rCallBar02'
|
54
|
+
// }
|
55
|
+
// // ,suffix: '0'
|
56
|
+
// }
|
57
|
+
// ],
|
47
58
|
templateLabel: '{{--dir}}',
|
48
59
|
disableMiniFiySelector: false,
|
49
60
|
dirVarName: 'document.dir'
|
@@ -246,6 +257,7 @@ var _default = {
|
|
246
257
|
cli: 'css_unique'
|
247
258
|
},
|
248
259
|
folder: 'src',
|
260
|
+
disableES5Transpile: false,
|
249
261
|
hasRTL: false,
|
250
262
|
rtlExclude: [],
|
251
263
|
cssHashSelectors: {
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getPaths = getPaths;
|
7
|
+
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
|
+
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
11
|
+
|
12
|
+
var _child_process = require("child_process");
|
13
|
+
|
14
|
+
var _utils = require("../utils");
|
15
|
+
|
16
|
+
var _getCliPath = require("./getCliPath");
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
const options = (0, _utils.getOptions)(); // const args = process.argv.slice(3);
|
21
|
+
|
22
|
+
const {
|
23
|
+
app: {
|
24
|
+
outputFolder
|
25
|
+
}
|
26
|
+
} = options;
|
27
|
+
const {
|
28
|
+
cssSelectorZipPath
|
29
|
+
} = options.impactService;
|
30
|
+
const zipname = cssSelectorZipPath ? _path.default.parse(cssSelectorZipPath).name : null;
|
31
|
+
|
32
|
+
const outputFolderLocation = _path.default.join(process.cwd(), outputFolder);
|
33
|
+
|
34
|
+
function execSyncDefalut(command) {
|
35
|
+
console.log(' command running ==>', command);
|
36
|
+
return (0, _child_process.execSync)(command, {
|
37
|
+
stdio: 'inherit'
|
38
|
+
});
|
39
|
+
}
|
40
|
+
|
41
|
+
const isQuiet = 'q';
|
42
|
+
const webpack = (0, _getCliPath.getCliPath)('webpack'); // console.log('webpack === > ', webpack, fs.existsSync(webpack));
|
43
|
+
|
44
|
+
if (_fs.default.existsSync(outputFolderLocation)) {
|
45
|
+
execSyncDefalut(`rm -rf ${outputFolder}`);
|
46
|
+
console.log(`previous ${outputFolder} removed`);
|
47
|
+
}
|
48
|
+
|
49
|
+
if (_fs.default.existsSync(_path.default.join(process.cwd(), 'build.zip'))) {
|
50
|
+
execSyncDefalut('rm build.zip');
|
51
|
+
console.log('previous build.zip removed');
|
52
|
+
} // execSyncDefalut(`${webpack } --version`);
|
53
|
+
// execSyncDefalut(`${webpack} --config ${require.resolve('../configs/webpack.dev.config.js')}`);
|
54
|
+
|
55
|
+
|
56
|
+
console.log('webpack compilation starts...');
|
57
|
+
const startTime = Date.now(); // const result = spawnSync(
|
58
|
+
// webpack,
|
59
|
+
// ['--config', require.resolve('../configs/webpack.dev.config.js')].concat(
|
60
|
+
// args
|
61
|
+
// ),
|
62
|
+
// { stdio: 'inherit' }
|
63
|
+
// );
|
64
|
+
|
65
|
+
const result = execSyncDefalut(`${webpack} --config ${require.resolve('../configs/webpack.dev.config.js')}`);
|
66
|
+
result && console.log(result);
|
67
|
+
|
68
|
+
if (result && result.stderr) {
|
69
|
+
throw result.stderr;
|
70
|
+
}
|
71
|
+
|
72
|
+
console.log(`compailation done in ${Date.now() - startTime}ms`);
|
73
|
+
|
74
|
+
if (zipname) {
|
75
|
+
execSyncDefalut(`zip -r${isQuiet} build.zip ${outputFolder}/*`);
|
76
|
+
console.log('build.zip file created');
|
77
|
+
const result = execSyncDefalut(`zip -r${isQuiet} ${cssSelectorZipPath} ${zipname}/*`);
|
78
|
+
execSyncDefalut(`rm -rf ${zipname}`);
|
79
|
+
|
80
|
+
if (result && result.stderr) {
|
81
|
+
console.log('zip file not created', cssSelectorZipPath);
|
82
|
+
console.error(result.stderr);
|
83
|
+
} else {
|
84
|
+
console.log('zip file created', cssSelectorZipPath);
|
85
|
+
}
|
86
|
+
} // npm run start --app:domain=tsi --impact:cssbountry="{$@&&@$}" --disable-watch --dev-cache --cssselector_zip=css-source-map.zip
|
87
|
+
// npm run start --app_domain=tsi --impact_cssbountry="{$@&&@$}" --disable-watch --dev-cache --cssselector_zip=css-source-map.zip
|
88
|
+
|
89
|
+
|
90
|
+
console.log(`compailation done in ${Date.now() - startTime}ms`);
|
91
|
+
|
92
|
+
function getPaths() {
|
93
|
+
return {
|
94
|
+
zipname,
|
95
|
+
cssSelectorZipPath,
|
96
|
+
outputFolderLocation
|
97
|
+
};
|
98
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getCliPath = getCliPath;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _os = require("os");
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
let appPath = process.cwd();
|
15
|
+
const isNodeModuleUnderAppFolder = __dirname.indexOf(appPath) !== -1;
|
16
|
+
let isWindows = (0, _os.platform)().toLowerCase() === 'win32';
|
17
|
+
|
18
|
+
const _getCliPath = !isNodeModuleUnderAppFolder ? libName => _path.default.join(__dirname, '..', '..', 'node_modules', '.bin', libName) : libName => libName;
|
19
|
+
|
20
|
+
const suffixExt = isWindows ? '.cmd' : '';
|
21
|
+
|
22
|
+
function getCliPath(libName) {
|
23
|
+
return _getCliPath(libName) + suffixExt;
|
24
|
+
}
|
@@ -1,25 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _fs = _interopRequireDefault(require("fs"));
|
4
|
-
|
5
3
|
var _path = _interopRequireDefault(require("path"));
|
6
4
|
|
7
5
|
var _https = _interopRequireDefault(require("https"));
|
8
6
|
|
9
|
-
var _os = require("os");
|
10
|
-
|
11
7
|
var _express = _interopRequireDefault(require("express"));
|
12
8
|
|
13
9
|
var _ws = _interopRequireDefault(require("ws"));
|
14
10
|
|
15
|
-
var _child_process = require("child_process");
|
16
|
-
|
17
11
|
var _httpProxyMiddleware = require("http-proxy-middleware");
|
18
12
|
|
19
13
|
var _utils = require("../utils");
|
20
14
|
|
21
15
|
var _httpsOptions = require("./httpsOptions");
|
22
16
|
|
17
|
+
var _devBulid = require("./devBulid");
|
18
|
+
|
23
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24
20
|
|
25
21
|
// import webpack from 'webpack';
|
@@ -28,95 +24,25 @@ let options = (0, _utils.getOptions)(); // let args = process.argv.slice(3);
|
|
28
24
|
let {
|
29
25
|
app: {
|
30
26
|
context,
|
31
|
-
server
|
32
|
-
outputFolder
|
27
|
+
server
|
33
28
|
}
|
34
29
|
} = options;
|
35
30
|
let {
|
36
31
|
host,
|
37
32
|
port,
|
38
33
|
domain,
|
39
|
-
mode,
|
40
34
|
disableContextURL,
|
41
35
|
hasMock,
|
42
36
|
mockPort
|
43
37
|
} = server;
|
44
|
-
let isCompatableHttp2 = Number(process.version.
|
38
|
+
let isCompatableHttp2 = Number(process.version.slice(1).split('.')[0]) >= 8;
|
45
39
|
let contextURL = disableContextURL ? '' : `/${context}`;
|
46
40
|
let serverUrl = (0, _utils.getServerURL)(server, 'htt' + 'ps');
|
47
41
|
const {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
let outputFolderLocation = _path.default.join(process.cwd(), outputFolder);
|
53
|
-
|
54
|
-
function execSyncDefalut(command) {
|
55
|
-
console.log(' command running ==>', command);
|
56
|
-
return (0, _child_process.execSync)(command, {
|
57
|
-
stdio: 'inherit'
|
58
|
-
});
|
59
|
-
}
|
60
|
-
|
61
|
-
let appPath = process.cwd();
|
62
|
-
const isNodeModuleUnderAppFolder = __dirname.indexOf(appPath) !== -1;
|
63
|
-
const isQuiet = 'q';
|
64
|
-
let isWindows = (0, _os.platform)().toLowerCase() === 'win32';
|
65
|
-
|
66
|
-
const _getCliPath = !isNodeModuleUnderAppFolder ? libName => _path.default.join(__dirname, '..', '..', 'node_modules', '.bin', libName) : libName => libName;
|
67
|
-
|
68
|
-
const suffixExt = isWindows ? '.cmd' : '';
|
69
|
-
|
70
|
-
function getCliPath(libName) {
|
71
|
-
return _getCliPath(libName) + suffixExt;
|
72
|
-
}
|
73
|
-
|
74
|
-
let webpack = getCliPath('webpack'); // console.log('webpack === > ', webpack, fs.existsSync(webpack));
|
75
|
-
|
76
|
-
if (_fs.default.existsSync(outputFolderLocation)) {
|
77
|
-
execSyncDefalut(`rm -rf ${outputFolder}`);
|
78
|
-
console.log(`previous ${outputFolder} removed`);
|
79
|
-
}
|
80
|
-
|
81
|
-
if (_fs.default.existsSync(_path.default.join(process.cwd(), 'build.zip'))) {
|
82
|
-
execSyncDefalut('rm build.zip');
|
83
|
-
console.log('previous build.zip removed');
|
84
|
-
} // execSyncDefalut(`${webpack } --version`);
|
85
|
-
// execSyncDefalut(`${webpack} --config ${require.resolve('../configs/webpack.dev.config.js')}`);
|
86
|
-
|
87
|
-
|
88
|
-
console.log('webpack compilation starts...');
|
89
|
-
let startTime = Date.now(); // let result = spawnSync(
|
90
|
-
// webpack,
|
91
|
-
// ['--config', require.resolve('../configs/webpack.dev.config.js')].concat(
|
92
|
-
// args
|
93
|
-
// ),
|
94
|
-
// { stdio: 'inherit' }
|
95
|
-
// );
|
96
|
-
|
97
|
-
let result = execSyncDefalut(`${webpack} --config ${require.resolve('../configs/webpack.dev.config.js')}`);
|
98
|
-
result && console.log(result);
|
99
|
-
|
100
|
-
if (result && result.stderr) {
|
101
|
-
throw result.stderr;
|
102
|
-
}
|
103
|
-
|
104
|
-
console.log(`compailation done in ${Date.now() - startTime}ms`);
|
105
|
-
|
106
|
-
if (zipname) {
|
107
|
-
execSyncDefalut(`zip -r${isQuiet} build.zip ${outputFolder}/*`);
|
108
|
-
console.log('build.zip file created');
|
109
|
-
let result = execSyncDefalut(`zip -r${isQuiet} ${cssSelectorZipPath} ${zipname}/*`);
|
110
|
-
execSyncDefalut(`rm -rf ${zipname}`);
|
111
|
-
|
112
|
-
if (result && result.stderr) {
|
113
|
-
console.log('zip file not created', cssSelectorZipPath);
|
114
|
-
console.error(result.stderr);
|
115
|
-
} else {
|
116
|
-
console.log('zip file created', cssSelectorZipPath);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
42
|
+
zipname,
|
43
|
+
cssSelectorZipPath,
|
44
|
+
outputFolderLocation
|
45
|
+
} = (0, _devBulid.getPaths)();
|
120
46
|
const app = (0, _express.default)();
|
121
47
|
|
122
48
|
if (hasMock) {
|
@@ -271,5 +197,4 @@ app.listen(httpPort, err => {
|
|
271
197
|
domain,
|
272
198
|
port: httpPort
|
273
199
|
}, 'ht' + 'tp')}${contextURL}/`);
|
274
|
-
});
|
275
|
-
console.log(`compailation done in ${Date.now() - startTime}ms`);
|
200
|
+
});
|
package/lib/servers/server.js
CHANGED
@@ -99,9 +99,16 @@ app.use((0, _HMRMiddleware.default)(compiler, {
|
|
99
99
|
path: '/sockjs-node/info'
|
100
100
|
}));
|
101
101
|
app.use((req, res, next) => {
|
102
|
-
|
102
|
+
//console.log('origin', req.get('origin'));
|
103
|
+
res.setHeader('Access-Control-Allow-Origin', req.get('origin') || '*'); // res.setHeader('Access-Control-Allow-Origin', req.get('origin'));
|
104
|
+
|
105
|
+
res.setHeader('Access-Control-Allow-Private-Network', true);
|
106
|
+
res.setHeader('Access-Control-Allow-Credentials', true);
|
103
107
|
next();
|
104
108
|
}).use(`${contextURL}/fonts`, _express.default.static(`${context}/fonts`));
|
109
|
+
app.options('/*', (req, res) => {
|
110
|
+
res.send('Ok');
|
111
|
+
});
|
105
112
|
app.use('/wms/*', (req, res) => {
|
106
113
|
res.sendFile(_path.default.join(__dirname, '..', '..', 'templates', 'wms', 'index.html'));
|
107
114
|
});
|
@@ -197,6 +204,6 @@ app.listen(httpPort, err => {
|
|
197
204
|
(0, _utils.log)(`Listening at ${(0, _utils.getServerURL)({
|
198
205
|
host,
|
199
206
|
domain,
|
200
|
-
port:
|
207
|
+
port: port
|
201
208
|
}, 'ht' + 'tp')}${contextURL}/`);
|
202
209
|
});
|
package/lib/utils/rtl.js
CHANGED
@@ -18,7 +18,10 @@ let src = _path.default.join(cwd, process.argv[2]);
|
|
18
18
|
|
19
19
|
let dist = _path.default.join(cwd, process.argv[3]);
|
20
20
|
|
21
|
-
|
21
|
+
let canWacth = '-w' === process.argv[4];
|
22
|
+
|
23
|
+
// import { useExitCleanup } from './useExitCleanup';
|
24
|
+
function watchHandler(fromPath, toPath) {
|
22
25
|
let css = _fs.default.readFileSync(fromPath);
|
23
26
|
|
24
27
|
(0, _postcss.default)([(0, _postcssRtl.default)({
|
@@ -39,4 +42,18 @@ let dist = _path.default.join(cwd, process.argv[3]);
|
|
39
42
|
_fs.default.writeFile(`${toPath}.map`, result.map, () => true);
|
40
43
|
}
|
41
44
|
});
|
42
|
-
}
|
45
|
+
}
|
46
|
+
|
47
|
+
(0, _folderIterator.default)(src, dist, ['.css'], false, (fromPath, toPath) => {
|
48
|
+
if (canWacth && fromPath) {
|
49
|
+
_fs.default.watchFile(fromPath, () => {
|
50
|
+
watchHandler(fromPath, toPath);
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
watchHandler(fromPath, toPath);
|
55
|
+
}); // if (canWacth) {
|
56
|
+
// useExitCleanup(() => {
|
57
|
+
// fs.unwatchFile(src, watchHandler);
|
58
|
+
// });
|
59
|
+
// }
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useExitCleanup = useExitCleanup;
|
7
|
+
//so the program will not close instantly
|
8
|
+
let listeners = [];
|
9
|
+
let hasCalled = false;
|
10
|
+
|
11
|
+
function useExitCleanup(listener) {
|
12
|
+
if (!hasCalled) {
|
13
|
+
process.stdin.resume();
|
14
|
+
hasCalled = true;
|
15
|
+
}
|
16
|
+
|
17
|
+
listeners.push(listeners);
|
18
|
+
return () => {
|
19
|
+
listeners = listeners.filter(l => l !== listener);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
function exitHandler(options, exitCode) {
|
24
|
+
if (options.cleanup) {
|
25
|
+
console.log('clean');
|
26
|
+
}
|
27
|
+
|
28
|
+
if (exitCode || exitCode === 0) {
|
29
|
+
console.log(exitCode);
|
30
|
+
}
|
31
|
+
|
32
|
+
if (options.exit) {
|
33
|
+
process.exit();
|
34
|
+
}
|
35
|
+
} //do something when app is closing
|
36
|
+
|
37
|
+
|
38
|
+
process.on('exit', exitHandler.bind(null, {
|
39
|
+
cleanup: true
|
40
|
+
})); //catches ctrl+c event
|
41
|
+
|
42
|
+
process.on('SIGINT', exitHandler.bind(null, {
|
43
|
+
exit: true
|
44
|
+
})); // catches "kill pid" (for example: nodemon restart)
|
45
|
+
|
46
|
+
process.on('SIGUSR1', exitHandler.bind(null, {
|
47
|
+
exit: true
|
48
|
+
}));
|
49
|
+
process.on('SIGUSR2', exitHandler.bind(null, {
|
50
|
+
exit: true
|
51
|
+
})); //catches uncaught exceptions
|
52
|
+
|
53
|
+
process.on('uncaughtException', exitHandler.bind(null, {
|
54
|
+
exit: true
|
55
|
+
}));
|
package/package.json
CHANGED
@@ -1,91 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.criteriaHandler = criteriaHandler;
|
7
|
-
|
8
|
-
/*
|
9
|
-
root = {
|
10
|
-
a: 1
|
11
|
-
b: 0
|
12
|
-
op = "&"
|
13
|
-
}
|
14
|
-
|
15
|
-
rule = (1 & 2) | 0
|
16
|
-
root = {
|
17
|
-
a: {
|
18
|
-
a: 1
|
19
|
-
b: 2
|
20
|
-
op = "&"
|
21
|
-
}
|
22
|
-
b: 0
|
23
|
-
op = "|"
|
24
|
-
}
|
25
|
-
|
26
|
-
rule = (3 | !(1 & 2)) | 0
|
27
|
-
*/
|
28
|
-
function parseNumber(rule, _i) {
|
29
|
-
let i = _i;
|
30
|
-
let ans = 0;
|
31
|
-
|
32
|
-
while (/[0-9]/.test(rule[i])) {
|
33
|
-
ans = ans * 10 + Number(rule[i]);
|
34
|
-
i++;
|
35
|
-
}
|
36
|
-
|
37
|
-
return [i, ans];
|
38
|
-
}
|
39
|
-
|
40
|
-
function criteriaParser(rule, _i = 0) {
|
41
|
-
let openBarceCount = 0; // let root = {};
|
42
|
-
|
43
|
-
let cur = {};
|
44
|
-
let c;
|
45
|
-
|
46
|
-
for (let i = _i; i < rule.length; i++) {
|
47
|
-
c = rule[i];
|
48
|
-
|
49
|
-
if (/[0-9]/.test(c)) {
|
50
|
-
let [_i, num] = parseNumber(rule, i);
|
51
|
-
i = _i - 1;
|
52
|
-
|
53
|
-
if (cur.a === undefined) {
|
54
|
-
cur.a = num; // } else if (cur.b === undefined) {
|
55
|
-
} else {
|
56
|
-
cur.b = num; // if (cur.op && cur.a);
|
57
|
-
// } else {
|
58
|
-
}
|
59
|
-
} else if (/[|&]/.test(c)) {
|
60
|
-
if (cur.op) {
|
61
|
-
// if (cur.b === undefined && cur.op !== '!') {
|
62
|
-
// throw `Error unexpected charector ${c} in index ${i}`;
|
63
|
-
// }
|
64
|
-
cur = {
|
65
|
-
a: cur,
|
66
|
-
op: c
|
67
|
-
};
|
68
|
-
} else {
|
69
|
-
cur.op = c;
|
70
|
-
}
|
71
|
-
} // if (c === '(' || c === ')') {
|
72
|
-
// if (openBarceCount) {
|
73
|
-
// openBarceCount++;
|
74
|
-
// } else if (c === ')') {
|
75
|
-
// openBarceCount--;
|
76
|
-
// cur = { a, b, op };
|
77
|
-
// }
|
78
|
-
// } else if (/[0-9]/.test(c)) {
|
79
|
-
// } else {
|
80
|
-
// }
|
81
|
-
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
function criteriaHandler(criterias, rule) {
|
86
|
-
if (/[(!)0-9&|]/.test(rule) === false) {
|
87
|
-
console.log('rule has unexpexted charectors');
|
88
|
-
}
|
89
|
-
|
90
|
-
let root = criteriaParser(rule);
|
91
|
-
}
|
@@ -1,95 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
9
|
-
|
10
|
-
var _os = _interopRequireDefault(require("os"));
|
11
|
-
|
12
|
-
var _utils = require("../utils");
|
13
|
-
|
14
|
-
var _testPattern = require("./testPattern");
|
15
|
-
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
|
18
|
-
let isWindows = _os.default.platform().toLowerCase() === 'win32';
|
19
|
-
let ps = _path.default.sep;
|
20
|
-
let options = (0, _utils.getOptions)();
|
21
|
-
let {
|
22
|
-
app: {
|
23
|
-
vendorExclude,
|
24
|
-
customChunks,
|
25
|
-
vendorInclude
|
26
|
-
}
|
27
|
-
} = options;
|
28
|
-
|
29
|
-
let isVendor = function isVendor(module) {
|
30
|
-
let {
|
31
|
-
userRequest
|
32
|
-
} = module;
|
33
|
-
let excludeList = ['script-loader', 'raw-loader', 'react', 'react-dom'];
|
34
|
-
excludeList = [...excludeList, ...vendorExclude];
|
35
|
-
return userRequest && (vendorInclude.some(item => userRequest.indexOf(item) !== -1) || userRequest.indexOf('node_modules') >= 0 && userRequest.endsWith('.css') === false && userRequest.endsWith('publicPathConfig.js') === false && excludeList.every(item => userRequest.indexOf(`node_modules${ps}${item}${ps}`) === -1));
|
36
|
-
};
|
37
|
-
|
38
|
-
let isReact = module => {
|
39
|
-
let {
|
40
|
-
userRequest
|
41
|
-
} = module;
|
42
|
-
let reactBundle = ['react', 'react-dom'];
|
43
|
-
return userRequest && reactBundle.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
|
44
|
-
};
|
45
|
-
|
46
|
-
let defaultChunks = {
|
47
|
-
'react.vendor': {
|
48
|
-
name: 'react.vendor',
|
49
|
-
chunks: 'all',
|
50
|
-
minChunks: 1,
|
51
|
-
test: isReact,
|
52
|
-
priority: -10
|
53
|
-
},
|
54
|
-
vendor: {
|
55
|
-
name: 'vendor',
|
56
|
-
chunks: 'initial',
|
57
|
-
minChunks: 1,
|
58
|
-
test: isVendor,
|
59
|
-
priority: -10
|
60
|
-
}
|
61
|
-
};
|
62
|
-
let customChunksConfig = {};
|
63
|
-
customChunks.map(({
|
64
|
-
name,
|
65
|
-
pattern,
|
66
|
-
size = 2,
|
67
|
-
rules,
|
68
|
-
chunks = 'all',
|
69
|
-
includeDepenency
|
70
|
-
}, index) => customChunksConfig[name] = {
|
71
|
-
name,
|
72
|
-
test: rules ? m => {
|
73
|
-
let {
|
74
|
-
userRequest
|
75
|
-
} = m;
|
76
|
-
let pkgs = rules;
|
77
|
-
|
78
|
-
if (!Array.isArray(rules)) {
|
79
|
-
pkgs = [rules];
|
80
|
-
}
|
81
|
-
|
82
|
-
return pkgs.some(p => (0, _testPattern.isRelated)(userRequest, p)) || includeDepenency && (0, _testPattern.isDependency)(m, pkgs);
|
83
|
-
} : new RegExp(isWindows ? pattern.replace(/\//g, '\\') : pattern),
|
84
|
-
chunks,
|
85
|
-
enforce: true,
|
86
|
-
minChunks: size,
|
87
|
-
priority: -10 * (index + 2)
|
88
|
-
});
|
89
|
-
var _default = {
|
90
|
-
cacheGroups: Object.assign({
|
91
|
-
default: false,
|
92
|
-
vendors: false
|
93
|
-
}, defaultChunks, customChunksConfig)
|
94
|
-
};
|
95
|
-
exports.default = _default;
|