@zohodesk/react-cli 1.1.22-exp.1 → 1.1.22-exp.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.22-exp.1",
3
+ "version": "1.1.22-exp.3",
4
4
  "description": "A CLI tool for build modern web application and libraries",
5
5
  "scripts": {
6
6
  "init": "node ./lib/utils/init.js",
@@ -110,7 +110,8 @@
110
110
  "webpack-dev-middleware": "3.7.2",
111
111
  "ws": "7.3.1",
112
112
  "xhr2": "0.2.0",
113
- "xmlhttprequest": "1.8.0"
113
+ "xmlhttprequest": "1.8.0",
114
+ "babel-plugin-module-resolver": "5.0.2"
114
115
  },
115
116
  "babel": {
116
117
  "presets": [
@@ -1,108 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const pluginName = 'CustomScriptLoadingStrategyPlugin';
13
-
14
- class CustomScriptLoadingStrategyPlugin {
15
- constructor({
16
- scriptLoadingStategey
17
- } = {}) {
18
- this.scriptLoadingStrategy = scriptLoadingStategey;
19
- }
20
-
21
- getFileNameFromTagSrc(src) {
22
- const fileNameArr = src.split('/');
23
- return fileNameArr[fileNameArr.length - 1];
24
- }
25
-
26
- addAttributestToTag(tag, attributes) {
27
- tag.attributes = Object.assign({}, tag.attributes, attributes);
28
- }
29
-
30
- matchFileName(tag, fileName) {
31
- return fileName.test(this.getFileNameFromTagSrc(tag.attributes.src));
32
- }
33
-
34
- blockingStrategy(tag) {
35
- delete tag.attributes.defer;
36
- delete tag.attributes.async;
37
- }
38
-
39
- deferStrategy(tag) {
40
- delete tag.attributes.async;
41
- }
42
-
43
- asyncStrategy(tag) {
44
- delete tag.attributes.defer;
45
- }
46
-
47
- moduleStrategy(tag) {
48
- this.deferStrategy(tag);
49
- }
50
-
51
- matchStrategy(scriptLoadingStrategy, tag) {
52
- if (scriptLoadingStrategy === 'blocking') {
53
- this.blockingStrategy(tag);
54
- }
55
-
56
- if (scriptLoadingStrategy === 'defer') {
57
- this.deferStrategy(tag);
58
- }
59
-
60
- if (scriptLoadingStrategy === 'async') {
61
- this.asyncStrategy(tag);
62
- }
63
-
64
- if (scriptLoadingStrategy === 'module') {
65
- this.moduleStrategy(tag);
66
- }
67
- }
68
-
69
- matchAndApplyCustomLoadingStrategyToScripts(tags) {
70
- Object.keys(this.scriptLoadingStrategy).forEach(scriptLoadingStrategy => {
71
- const filesToMatch = this.scriptLoadingStrategy[scriptLoadingStrategy];
72
- tags.forEach(tag => {
73
- if (tag.attributes.src) {
74
- const isFileMatch = filesToMatch.some(fileName => this.matchFileName(tag, fileName));
75
-
76
- if (isFileMatch) {
77
- this.matchStrategy(scriptLoadingStrategy, tag);
78
- this.addAttributestToTag(tag, {
79
- [scriptLoadingStrategy]: true
80
- });
81
- }
82
- } // filesToMatch.forEach(fileName => {
83
- // if (!this.matchFileName(tag, fileName)) {
84
- // return;
85
- // }
86
- // this.matchStrategy(scriptLoadingStrategy, tag);
87
- // this.addAttributestToTag(tag, fileName, {
88
- // [scriptLoadingStrategy]: true
89
- // });
90
- // });
91
-
92
- });
93
- });
94
- }
95
-
96
- apply(compiler) {
97
- compiler.hooks.compilation.tap(pluginName, compilation => {
98
- _htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, callback) => {
99
- const tags = [...data.bodyTags, ...data.headTags];
100
- this.matchAndApplyCustomLoadingStrategyToScripts(tags);
101
- callback(null, data);
102
- });
103
- });
104
- }
105
-
106
- }
107
-
108
- exports.default = CustomScriptLoadingStrategyPlugin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTypeOf = getTypeOf;
7
-
8
- function getTypeOf(value) {
9
- return Object.prototype.toString.call(value).split(/\s/)[1].replace(/\]/, '').toLowerCase();
10
- }