@zohodesk/react-cli 1.1.7 → 1.1.8-exp.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/.eslintignore +7 -7
  2. package/.eslintrc.js +180 -180
  3. package/.prettierrc +6 -6
  4. package/Changelog.md +1019 -1019
  5. package/README.md +1293 -1251
  6. package/bin/cli.js +497 -497
  7. package/docs/ComposeMinification.md +13 -13
  8. package/docs/CustomChunks.md +29 -26
  9. package/docs/DevServerPort.md +39 -39
  10. package/docs/DevStart.md +18 -18
  11. package/docs/HoverActive.md +12 -12
  12. package/docs/InstallNode.md +28 -28
  13. package/docs/MarkdownParser.md +17 -17
  14. package/docs/ReactLive.md +13 -13
  15. package/docs/SelectorWeight.md +8 -8
  16. package/docs/TODOS.md +10 -10
  17. package/docs/ValueReplacer.md +60 -60
  18. package/docs/VariableConversion.md +729 -729
  19. package/docs/patternFiltering.md +56 -56
  20. package/docs/warnings_while_install.txt +35 -35
  21. package/files/eslintrc.js +62 -62
  22. package/files/prettierrc.js +3 -3
  23. package/lib/common/splitChunks.js +65 -45
  24. package/lib/common/testPattern.js +9 -9
  25. package/lib/configs/webpack.css.umd.config.js +4 -4
  26. package/lib/configs/webpack.dev.config.js +24 -3
  27. package/lib/configs/webpack.docs.config.js +22 -3
  28. package/lib/configs/webpack.impact.config.js +4 -2
  29. package/lib/configs/webpack.prod.config.js +6 -3
  30. package/lib/deprecationLogger.js +41 -0
  31. package/lib/loaderUtils/configsAssetsLoaders.js +33 -33
  32. package/lib/loaderUtils/getCSSLoaders.js +77 -56
  33. package/lib/loaders/workerLoader.js +9 -9
  34. package/lib/pluginUtils/getDevPlugins.js +8 -7
  35. package/lib/pluginUtils/getProdPlugins.js +6 -6
  36. package/lib/plugins/CustomAttributePlugin.md +35 -35
  37. package/lib/plugins/EFCPlugin.md +6 -6
  38. package/lib/plugins/I18NInjectIntoIndexPlugin.js +4 -4
  39. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +38 -38
  40. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +30 -30
  41. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +8 -8
  42. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -95
  43. package/lib/plugins/I18nSplitPlugin/README.md +25 -25
  44. package/lib/plugins/I18nSplitPlugin/index.js +57 -57
  45. package/lib/plugins/ResourceHintsPlugin.js +30 -20
  46. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +6 -6
  47. package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -30
  48. package/lib/plugins/SelectorPlugin.js +29 -29
  49. package/lib/plugins/ServiceWorkerPlugin.js +9 -9
  50. package/lib/plugins/TPHashMappingPlugin.js +4 -4
  51. package/lib/plugins/VariableConversionCollector.js +59 -59
  52. package/lib/plugins/utils/fileHandling.js +35 -42
  53. package/lib/plugins/variableConvertorUtils.js +9 -9
  54. package/lib/postcss-plugins/RTLSplitPlugin.js +10 -10
  55. package/lib/postcss-plugins/__test__/test1Input.css +38 -38
  56. package/lib/postcss-plugins/__test__/test1Output.css +38 -38
  57. package/lib/postcss-plugins/hoverActivePlugin.js +3 -3
  58. package/lib/schemas/index.js +19 -36
  59. package/lib/sh/pre-commit.sh +34 -34
  60. package/lib/sh/reportPublish.sh +45 -45
  61. package/lib/utils/buildstats.html +148 -148
  62. package/lib/utils/cssClassNameGenerate.js +13 -13
  63. package/lib/utils/deprecationSupport.js +144 -0
  64. package/lib/utils/getOptions.js +18 -78
  65. package/lib/utils/resultSchema.json +73 -73
  66. package/npm-shrinkwrap.json +33393 -33393
  67. package/npm8.md +9 -9
  68. package/package.json +123 -123
  69. package/postpublish.js +8 -8
  70. package/result.json +1 -0
  71. package/templates/app/.eslintrc.js +140 -140
  72. package/templates/app/README.md +12 -12
  73. package/templates/app/app/index.html +24 -24
  74. package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
  75. package/templates/app/app/properties/i18nkeys.json +3 -3
  76. package/templates/app/docs/all.html +69 -69
  77. package/templates/app/mockapi/index.js +18 -18
  78. package/templates/app/package.json +37 -37
  79. package/templates/app/src/actions/SampleActions/index.js +37 -37
  80. package/templates/app/src/actions/index.js +65 -65
  81. package/templates/app/src/appUrls.js +19 -19
  82. package/templates/app/src/components/Alert/Alert.js +134 -134
  83. package/templates/app/src/components/Alert/Alert.module.css +79 -79
  84. package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
  85. package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
  86. package/templates/app/src/components/Sample/Sample.module.css +11 -11
  87. package/templates/app/src/components/Sample/SampleList.js +61 -61
  88. package/templates/app/src/components/Slider/Slider.css +41 -41
  89. package/templates/app/src/components/Slider/Slider.js +55 -55
  90. package/templates/app/src/containers/AlertContainer/index.js +15 -15
  91. package/templates/app/src/containers/AppContainer/index.js +96 -96
  92. package/templates/app/src/containers/AppContainer/index.module.css +27 -27
  93. package/templates/app/src/containers/CustomMatch/index.js +65 -65
  94. package/templates/app/src/containers/DevTools/index.js +10 -10
  95. package/templates/app/src/containers/Header/index.js +67 -67
  96. package/templates/app/src/containers/Header/index.module.css +43 -43
  97. package/templates/app/src/containers/Redirect/index.js +63 -63
  98. package/templates/app/src/containers/Redirector/index.js +47 -47
  99. package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
  100. package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
  101. package/templates/app/src/historyChange.js +5 -5
  102. package/templates/app/src/index.html +10 -10
  103. package/templates/app/src/index.js +24 -24
  104. package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
  105. package/templates/app/src/reducers/alertData.js +11 -11
  106. package/templates/app/src/reducers/index.js +6 -6
  107. package/templates/app/src/reducers/samples.js +19 -19
  108. package/templates/app/src/store/configureStore.dev.js +51 -51
  109. package/templates/app/src/store/configureStore.js +5 -5
  110. package/templates/app/src/store/configureStore.prod.js +26 -26
  111. package/templates/app/src/util/Common.js +5 -5
  112. package/templates/app/src/util/RequestAPI.js +132 -132
  113. package/templates/docs/all.html +250 -250
  114. package/templates/docs/component.html +179 -179
  115. package/templates/docs/components.html +222 -222
  116. package/templates/docs/css/b.min.css +6 -6
  117. package/templates/docs/css/component.css +42 -42
  118. package/templates/docs/css/componentTest.css +6 -6
  119. package/templates/docs/css/hopscotch.css +585 -585
  120. package/templates/docs/css/markdown.css +202 -202
  121. package/templates/docs/css/style.css +1022 -1022
  122. package/templates/docs/impactReportTemplate.html +154 -154
  123. package/templates/docs/index.html +1502 -1502
  124. package/templates/docs/js/active-line.js +72 -72
  125. package/templates/docs/js/b.min.js +7 -7
  126. package/templates/docs/js/codemirror.js +9680 -9680
  127. package/templates/docs/js/designTokens.js +334 -334
  128. package/templates/docs/js/j.min.js +4 -4
  129. package/templates/docs/js/javascript.js +874 -874
  130. package/templates/docs/js/matchbrackets.js +145 -145
  131. package/unittest/index.html +37 -0
@@ -13,8 +13,8 @@ var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKey
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- /**
17
- * this plugin was creating the chunk specific i18n chunk's.
16
+ /**
17
+ * this plugin was creating the chunk specific i18n chunk's.
18
18
  */
19
19
  // this plugin's kick starter is apply method
20
20
  const pluginName = 'I18nFilesEmitter';
@@ -141,40 +141,40 @@ class I18nFilesEmitter {
141
141
  }
142
142
 
143
143
  apply(compiler) {
144
- /*
145
- compiler.hooks.thisCompilation.tap(pluginName, compilation => {
146
- compilation.mainTemplate.hooks.renderManifest.tap(
147
- pluginName,
148
- (result, { chunk }) => {
149
- this.renderChunk(result, compilation, chunk);
150
- }
151
- );
152
- compilation.chunkTemplate.hooks.renderManifest.tap(
153
- pluginName,
154
- (result, { chunk }) => {
155
- this.renderChunk(result, compilation, chunk);
156
- }
157
- );
158
- });
144
+ /*
145
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
146
+ compilation.mainTemplate.hooks.renderManifest.tap(
147
+ pluginName,
148
+ (result, { chunk }) => {
149
+ this.renderChunk(result, compilation, chunk);
150
+ }
151
+ );
152
+ compilation.chunkTemplate.hooks.renderManifest.tap(
153
+ pluginName,
154
+ (result, { chunk }) => {
155
+ this.renderChunk(result, compilation, chunk);
156
+ }
157
+ );
158
+ });
159
159
  */
160
160
  // this below hook was tapped for create asssets(file) for chunk specific i18nChunk Files
161
161
  compiler.hooks.emit.tap(pluginName, compilation => {
162
162
  this.emitI18nAssert(compilation);
163
163
  });
164
164
  }
165
- /*
166
- renderChunk(result, compilation, chunk) {
167
- const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
168
- // TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
169
- // IDEA: we chose this place for add i18n locale files ????
170
- if (i18nKeys.length > 0) {
171
- Object.keys(this.allI18nObject).forEach(locale => {
172
- result.push(
173
- this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
174
- );
175
- });
176
- }
177
- }
165
+ /*
166
+ renderChunk(result, compilation, chunk) {
167
+ const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
168
+ // TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
169
+ // IDEA: we chose this place for add i18n locale files ????
170
+ if (i18nKeys.length > 0) {
171
+ Object.keys(this.allI18nObject).forEach(locale => {
172
+ result.push(
173
+ this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
174
+ );
175
+ });
176
+ }
177
+ }
178
178
  */
179
179
 
180
180
 
@@ -14,14 +14,14 @@ var _NullFactory = _interopRequireDefault(require("webpack/lib/NullFactory"));
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  const pluginName = 'I18nKeysIdentifer';
17
- /**
18
- * this plugin search the i18 keys and make it as I18nDependency.
19
- * how it works?
20
- * this plugin get jsResourceI18nKeys in constructor.
21
- * we walk throught the js files AST
22
- * if any string literal in that AST is in jsResourceI18nKeys then we consider that string as I18n key
23
- * after the walk of AST we get some I18n keys
24
- * then we make it as I18nDependency.
17
+ /**
18
+ * this plugin search the i18 keys and make it as I18nDependency.
19
+ * how it works?
20
+ * this plugin get jsResourceI18nKeys in constructor.
21
+ * we walk throught the js files AST
22
+ * if any string literal in that AST is in jsResourceI18nKeys then we consider that string as I18n key
23
+ * after the walk of AST we get some I18n keys
24
+ * then we make it as I18nDependency.
25
25
  */
26
26
 
27
27
  class I18nKeysIdentifer {
@@ -1,95 +1,95 @@
1
- # I18n Split As Chunks Plugin
2
-
3
- generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
-
5
- ### what is the problem with this?.
6
-
7
- the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
8
- So, We have decide to create a plugin for split i18n per chunk's of js vise.
9
-
10
- ### what is i18n split?
11
-
12
- it is like code split for i18n.
13
- we will collect i18n from js chunk and we will create separate i18n chunk per js chunk,
14
- with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
15
- when js download's we will download i18n with it.
16
-
17
- ### How to we going to i18n split?
18
-
19
- we will read the js chunk and collect I18n keys form it,
20
- then we will create i18n chunk files with these used keys.
21
-
22
- ### how do you collect i18n keys from js files?
23
-
24
- we will traverse the js file's AST (static analysis) and find i18 keys,
25
- we will concider all string which is in jsResource file as i18n keys.
26
- and you can tell dynamic i18n key by js comments,
27
- Like Below:-
28
-
29
- ```js
30
- fetch('tickets?view=view1').then(data => {
31
- // I18n support.ticketsEmpty
32
- // I18n support.viewNotFount
33
- // I18n support.permissionDenied
34
- let text = getI18nValue(data.i18nkey);
35
- });
36
- ```
37
-
38
- ### is there any posiblity for unwanted keys in some chunk?
39
-
40
- Yes, there is two posiblity
41
-
42
- 1. js comment , if you write js comment but it is not needed then it will be add into i18n chunk
43
- `To Resolve` we currently do not have perfect idea for this, But we can check this by chunk size limit.
44
- `idea's will be welcome`
45
- 2. like we said "we will concider all string which is in jsResource file as i18n keys",
46
- So if you use string not for i18n but it was in jsResource then it will be add into i18n chunk.
47
- `To Resolve` this problem we can use some kinda prefix or something.
48
-
49
- ### how do we downlowd and give to app?
50
-
51
- we have over write defualt webpack requireEnsure (every dynamic chunk requests are done by that function) function.
52
- and we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
53
- So we send i18nkeys , when it was download,
54
- you must store all i18n keys, we give asycrnsly by that function download in that patticular.
55
- so you must store and update (like append or assign) everytime that function call.
56
-
57
- ### how to use this feature?
58
-
59
- to use this feature use have give the below oprtions
60
- `package.json`
61
-
62
- ```json
63
- {
64
- /// ...some things
65
- "react-cli": {
66
- // ...some things
67
- "i18n": {
68
- "chunkSplitEnable": true,
69
- "jsResource": "./deskapp/properties/JSResources.properties",
70
- "localeVarName": "window.userInfo.langCode",
71
- "jsonpFunc": "window.loadI18nChunk",
72
- "templateLabel": "{{--user-locale}}", // this is for html template i18n file path locate template
73
- "propertiesFolder": "./deskapp/properties"
74
- }
75
- // ...some things
76
- }
77
- }
78
- ```
79
-
80
- <!-- not need below -->
81
- <!--we have added new feature for css to write logic to how hover related css work in hoverhover and a
82
-
83
- ### is there any problems with static analysis?
84
- Yes,
85
-
86
- ### how do we use dynamic i18n key?
87
-
88
- and we will download i18n file with
89
-
90
- and when js chunk download's then we will download i18n as need.
91
- we all know in our app we loading i18n as one single big file for each locale(language).
92
- we are going to split i18n as per js chunk, and when js chunk download's then we will download i18n as need.
93
-
94
-
95
- -->
1
+ # I18n Split As Chunks Plugin
2
+
3
+ generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
+
5
+ ### what is the problem with this?.
6
+
7
+ the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
8
+ So, We have decide to create a plugin for split i18n per chunk's of js vise.
9
+
10
+ ### what is i18n split?
11
+
12
+ it is like code split for i18n.
13
+ we will collect i18n from js chunk and we will create separate i18n chunk per js chunk,
14
+ with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
15
+ when js download's we will download i18n with it.
16
+
17
+ ### How to we going to i18n split?
18
+
19
+ we will read the js chunk and collect I18n keys form it,
20
+ then we will create i18n chunk files with these used keys.
21
+
22
+ ### how do you collect i18n keys from js files?
23
+
24
+ we will traverse the js file's AST (static analysis) and find i18 keys,
25
+ we will concider all string which is in jsResource file as i18n keys.
26
+ and you can tell dynamic i18n key by js comments,
27
+ Like Below:-
28
+
29
+ ```js
30
+ fetch('tickets?view=view1').then(data => {
31
+ // I18n support.ticketsEmpty
32
+ // I18n support.viewNotFount
33
+ // I18n support.permissionDenied
34
+ let text = getI18nValue(data.i18nkey);
35
+ });
36
+ ```
37
+
38
+ ### is there any posiblity for unwanted keys in some chunk?
39
+
40
+ Yes, there is two posiblity
41
+
42
+ 1. js comment , if you write js comment but it is not needed then it will be add into i18n chunk
43
+ `To Resolve` we currently do not have perfect idea for this, But we can check this by chunk size limit.
44
+ `idea's will be welcome`
45
+ 2. like we said "we will concider all string which is in jsResource file as i18n keys",
46
+ So if you use string not for i18n but it was in jsResource then it will be add into i18n chunk.
47
+ `To Resolve` this problem we can use some kinda prefix or something.
48
+
49
+ ### how do we downlowd and give to app?
50
+
51
+ we have over write defualt webpack requireEnsure (every dynamic chunk requests are done by that function) function.
52
+ and we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
53
+ So we send i18nkeys , when it was download,
54
+ you must store all i18n keys, we give asycrnsly by that function download in that patticular.
55
+ so you must store and update (like append or assign) everytime that function call.
56
+
57
+ ### how to use this feature?
58
+
59
+ to use this feature use have give the below oprtions
60
+ `package.json`
61
+
62
+ ```json
63
+ {
64
+ /// ...some things
65
+ "react-cli": {
66
+ // ...some things
67
+ "i18n": {
68
+ "chunkSplitEnable": true,
69
+ "jsResource": "./deskapp/properties/JSResources.properties",
70
+ "localeVarName": "window.userInfo.langCode",
71
+ "jsonpFunc": "window.loadI18nChunk",
72
+ "templateLabel": "{{--user-locale}}", // this is for html template i18n file path locate template
73
+ "propertiesFolder": "./deskapp/properties"
74
+ }
75
+ // ...some things
76
+ }
77
+ }
78
+ ```
79
+
80
+ <!-- not need below -->
81
+ <!--we have added new feature for css to write logic to how hover related css work in hoverhover and a
82
+
83
+ ### is there any problems with static analysis?
84
+ Yes,
85
+
86
+ ### how do we use dynamic i18n key?
87
+
88
+ and we will download i18n file with
89
+
90
+ and when js chunk download's then we will download i18n as need.
91
+ we all know in our app we loading i18n as one single big file for each locale(language).
92
+ we are going to split i18n as per js chunk, and when js chunk download's then we will download i18n as need.
93
+
94
+
95
+ -->
@@ -1,25 +1,25 @@
1
- # I18n Split As Chunks Plugin
2
-
3
- generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
-
5
- Ok, what is the problem with this?.
6
- the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
7
- So, We have decide to create a plugin for split i18n per chunk's of js vise, Which mean we diside to create for each js chunk has its own i18n chunks, with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
8
-
9
- Ok, How to you do this thing?
10
- we have read the js chunk and collect I18n keys what are used in that chunk and we will create i18n chunk files with only used key.
11
-
12
- Ok, How do you collect that keys?
13
- we now have two expremental statrge to collect I18n keys.
14
-
15
- 1. we read jsResource.properties (or all keys I18n file) then we walk this AST of js and we collect all string which is jsResource.properties.
16
- 2. for dynamic we discide to use comment some thing like
17
- `// I18n support.tickekt.email.notvalid`
18
-
19
- ok, how do you downlowd and give to app?
20
- we have over write defualt webpack require ensure function.
21
- So every dynamic chunk requset are done by that function.
22
- So we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
23
- So we send i18nkeys , when it was download,
24
- you must store all i18n keys, we give asycrnsly by that function download in that patticular.
25
- so you must store and update (like append or assign) everytime that function call.
1
+ # I18n Split As Chunks Plugin
2
+
3
+ generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
+
5
+ Ok, what is the problem with this?.
6
+ the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
7
+ So, We have decide to create a plugin for split i18n per chunk's of js vise, Which mean we diside to create for each js chunk has its own i18n chunks, with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
8
+
9
+ Ok, How to you do this thing?
10
+ we have read the js chunk and collect I18n keys what are used in that chunk and we will create i18n chunk files with only used key.
11
+
12
+ Ok, How do you collect that keys?
13
+ we now have two expremental statrge to collect I18n keys.
14
+
15
+ 1. we read jsResource.properties (or all keys I18n file) then we walk this AST of js and we collect all string which is jsResource.properties.
16
+ 2. for dynamic we discide to use comment some thing like
17
+ `// I18n support.tickekt.email.notvalid`
18
+
19
+ ok, how do you downlowd and give to app?
20
+ we have over write defualt webpack require ensure function.
21
+ So every dynamic chunk requset are done by that function.
22
+ So we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
23
+ So we send i18nkeys , when it was download,
24
+ you must store all i18n keys, we give asycrnsly by that function download in that patticular.
25
+ so you must store and update (like append or assign) everytime that function call.
@@ -21,23 +21,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
 
22
22
  // #region initial
23
23
 
24
- /**
25
- * @TODO:
26
- * [?] add comment line options for properties file and get all keys form property file do right way to genarate them
27
- * [?] need to discuss with collectI18n Keys with js comment need to conform "what is the comment? "
24
+ /**
25
+ * @TODO:
26
+ * [?] add comment line options for properties file and get all keys form property file do right way to genarate them
27
+ * [?] need to discuss with collectI18n Keys with js comment need to conform "what is the comment? "
28
28
  */
29
29
 
30
- /**
31
- * Notes: this plugin has done below works
32
- * 1. collect I18n Keys from js files and make it as Depenencies
33
- * 2. we create file(asset) for chunk specific i18nChunk Files
34
- * 3. create hash for the specific i18nChunk Files
35
- * 4. write logic to requireEnsure method for dowlod I18n chunk download dynamicaly
36
- * 5. create manifest.json file which has the mapping of chunk-locales-i18nChunkFile
37
- * for the external referrece.
38
- * Hints :-
39
- * - file means your machine files
40
- * - asset means that also file but that will create by webpack after build
30
+ /**
31
+ * Notes: this plugin has done below works
32
+ * 1. collect I18n Keys from js files and make it as Depenencies
33
+ * 2. we create file(asset) for chunk specific i18nChunk Files
34
+ * 3. create hash for the specific i18nChunk Files
35
+ * 4. write logic to requireEnsure method for dowlod I18n chunk download dynamicaly
36
+ * 5. create manifest.json file which has the mapping of chunk-locales-i18nChunkFile
37
+ * for the external referrece.
38
+ * Hints :-
39
+ * - file means your machine files
40
+ * - asset means that also file but that will create by webpack after build
41
41
  */
42
42
  // const getI18nLocales = require('./utils/getI18nLocales');
43
43
  // const { ConcatSource, SourceMapSource, OriginalSource } = sources;
@@ -49,16 +49,16 @@ const MODULE_TYPE = 'json/i18n';
49
49
  const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
50
50
 
51
51
  const pluginName = 'i18n-plugin';
52
- /**
53
- * @typedef I18nPluginOptions
54
- * @property {String} filenameTemplate this was template for i18n chunk
55
- * @property {String} jsResource this was path for jsResource i18n file
56
- * @property {String} propertiesFolder this was path for propertiesFolder i18n file
57
- * @property {Boolean} disableDefault this option for disable defulat value for i18n keys, means if the language file does not have some key we don't give jsResource value
58
- * @property {String} i18nManifestFileName this was ouput path for i18n manifest.
59
- * @property {String} jsonpFunc this was function name, we will call that function everytime i18n chunk download.
60
- * @property {String} localeVarName this was variable name, we will call that function everytime i18n chunk download.
61
- *
52
+ /**
53
+ * @typedef I18nPluginOptions
54
+ * @property {String} filenameTemplate this was template for i18n chunk
55
+ * @property {String} jsResource this was path for jsResource i18n file
56
+ * @property {String} propertiesFolder this was path for propertiesFolder i18n file
57
+ * @property {Boolean} disableDefault this option for disable defulat value for i18n keys, means if the language file does not have some key we don't give jsResource value
58
+ * @property {String} i18nManifestFileName this was ouput path for i18n manifest.
59
+ * @property {String} jsonpFunc this was function name, we will call that function everytime i18n chunk download.
60
+ * @property {String} localeVarName this was variable name, we will call that function everytime i18n chunk download.
61
+ *
62
62
  */
63
63
 
64
64
  class I18nPlugin {
@@ -104,13 +104,13 @@ class I18nPlugin {
104
104
  }
105
105
 
106
106
  maintainHashForAllI18nAssets(compilation) {
107
- /**
108
- * we write chunkHash logic inside of our plugin Because we only add Dependency not Module.
109
- * So we need to update chunkHash for our assets
110
- * and we not able tell with just Modules.
111
- * Because, if we add Module for the Depenentcy then that module must has some hash.
112
- * But our I18n Hash is no module specific it was chunk specific,
113
- * that's why we do the stuf in the chunkHash hook.
107
+ /**
108
+ * we write chunkHash logic inside of our plugin Because we only add Dependency not Module.
109
+ * So we need to update chunkHash for our assets
110
+ * and we not able tell with just Modules.
111
+ * Because, if we add Module for the Depenentcy then that module must has some hash.
112
+ * But our I18n Hash is no module specific it was chunk specific,
113
+ * that's why we do the stuf in the chunkHash hook.
114
114
  */
115
115
  compilation.hooks.chunkHash.tap(pluginName, (chunk, chunkHash) => {
116
116
  const {
@@ -154,31 +154,31 @@ class I18nPlugin {
154
154
  }
155
155
 
156
156
  }
157
- /*
158
- // TODO: need to reimplement this logic
159
- // NOTE: this logic for split all content hash per mani chunk
160
- // like add chunk content hash to main locale i18n file
161
-
162
- // let isEntry = chunk.name === this.options.mainChunkName;
163
- // if (chunk.name === 'main' && chunk.hasEntryModule()) {
164
- if (isEntry) {
165
- const hashSource = new ConcatSource();
166
- const dummyChunk = new chunk.constructor();
167
- hashSource.add('// it wil be I18N file hash');
168
- const templateHooks = compilation.chunkTemplate.hooks;
169
- let c = templateHooks.render.call(
170
- templateHooks.module.call(
171
- hashSource,
172
- dummyChunk,
173
- compilation.moduleTemplate.javascript,
174
- compilation.dependencyTemplates
175
- ),
176
- dummyChunk,
177
- compilation.moduleTemplate.javascript,
178
- compilation.dependencyTemplates
179
- );
180
-
181
- }
157
+ /*
158
+ // TODO: need to reimplement this logic
159
+ // NOTE: this logic for split all content hash per mani chunk
160
+ // like add chunk content hash to main locale i18n file
161
+
162
+ // let isEntry = chunk.name === this.options.mainChunkName;
163
+ // if (chunk.name === 'main' && chunk.hasEntryModule()) {
164
+ if (isEntry) {
165
+ const hashSource = new ConcatSource();
166
+ const dummyChunk = new chunk.constructor();
167
+ hashSource.add('// it wil be I18N file hash');
168
+ const templateHooks = compilation.chunkTemplate.hooks;
169
+ let c = templateHooks.render.call(
170
+ templateHooks.module.call(
171
+ hashSource,
172
+ dummyChunk,
173
+ compilation.moduleTemplate.javascript,
174
+ compilation.dependencyTemplates
175
+ ),
176
+ dummyChunk,
177
+ compilation.moduleTemplate.javascript,
178
+ compilation.dependencyTemplates
179
+ );
180
+
181
+ }
182
182
  */
183
183
 
184
184
 
@@ -12,14 +12,21 @@ const {
12
12
  const pluginName = 'prefetch-preload-chunk-plugin';
13
13
 
14
14
  class ResourceHintsPlugin {
15
+ constructor(options) {
16
+ this.options = options;
17
+ }
18
+
15
19
  apply(compiler) {
16
20
  compiler.hooks.thisCompilation.tap(pluginName, ({
17
21
  mainTemplate
18
22
  }) => {
19
23
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
24
+ const {
25
+ allowPrefetchingMultipleChunks
26
+ } = this.options;
20
27
  const idNameMap = chunk.getChunkMaps().name;
21
28
  const nameIdMap = {};
22
- let needsMap = false;
29
+ let needsMap = allowPrefetchingMultipleChunks;
23
30
 
24
31
  for (const key in idNameMap) {
25
32
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
@@ -32,28 +39,31 @@ class ResourceHintsPlugin {
32
39
  }
33
40
  }
34
41
 
35
- return Template.asString([source, '', `${mainTemplate.requireFn}.getChunkId = function getChunkId(chunkId) {`, Template.indent((needsMap ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`] : []).concat(['return chunkId;'])), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, `${mainTemplate.requireFn}.e(chunkId);`]), '};',
36
- /*
37
- (needsMap
38
- ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
39
- : []
40
- ).concat([
41
- 'var promises = [];',
42
- 'if(installedChunks[chunkId] === undefined) {',
43
- Template.indent([
44
- 'installedChunks[chunkId] = null;',
45
- /* mainTemplate.hooks.linkPrefetch.call('', chunk, hash),
42
+ return Template.asString([source, Template.indent([`const nameToChunkIdMap = ${JSON.stringify(needsMap ? nameIdMap : {})};`, 'const chunkNames = Object.keys(nameToChunkIdMap);']), `${mainTemplate.requireFn}.getChunkIds = function getChunkIds(chunkId) {`, Template.indent([allowPrefetchingMultipleChunks ? `const isRegExAsChunkId = chunkId instanceof RegExp;
43
+ return isRegExAsChunkId ? chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]) : [nameToChunkIdMap[chunkId] || chunkId];` : needsMap ? 'return [nameToChunkIdMap[chunkId] || chunkId];' : 'return [chunkId];']), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`let chunkIds = ${mainTemplate.requireFn}.getChunkIds(chunkId)`, `chunkIds.forEach(idOfAChunk => {
44
+ ${mainTemplate.requireFn}.e(idOfAChunk);
45
+ })`]), '};',
46
+ /*
47
+ (needsMap
48
+ ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
49
+ : []
50
+ ).concat([
51
+ 'var promises = [];',
52
+ 'if(installedChunks[chunkId] === undefined) {',
53
+ Template.indent([
54
+ 'installedChunks[chunkId] = null;',
55
+ /* mainTemplate.hooks.linkPrefetch.call('', chunk, hash),
46
56
  'document.head.appendChild(link);', */
47
57
 
48
- /*
49
- mainTemplate.hooks.requireEnsure.call('', chunk, hash)
50
- ]),
51
- '}'
52
- ])
53
- ),
54
- '}',
58
+ /*
59
+ mainTemplate.hooks.requireEnsure.call('', chunk, hash)
60
+ ]),
61
+ '}'
62
+ ])
63
+ ),
64
+ '}',
55
65
  */
56
- `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);` // 'var head = document.getElementsByTagName(\'head\')[0];',
66
+ `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkIds(chunkId)[0]`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);` // 'var head = document.getElementsByTagName(\'head\')[0];',
57
67
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
58
68
  // 'head.appendChild(script);'
59
69
  ]), '}']), '};']);
@@ -24,12 +24,12 @@ const isCss = filename => _path.default.extname(filename) === '.css'; // this p
24
24
 
25
25
  class RtlCssPlugin {
26
26
  constructor(options = {}) {
27
- /**
28
- * @typedef {Object} Options
29
- * @property {String} filename [not used]
30
- * @property {String} dirVarName
31
- * @property {Boolean} sourcemap
32
- * @property {Object} config
27
+ /**
28
+ * @typedef {Object} Options
29
+ * @property {String} filename [not used]
30
+ * @property {String} dirVarName
31
+ * @property {Boolean} sourcemap
32
+ * @property {Object} config
33
33
  */
34
34
  this.options = {
35
35
  filename: options.filename || '[name].rtl.css',
@@ -1,30 +1,30 @@
1
- # RTL Split
2
-
3
- we are doing in build time generating rtl related css code by using @zohodesk/postcss-rt npm.
4
- It was automated, That postcss plugin create rtl reacted css and put them into same file, with css selector [dir=rtl] and ltr realted css with [dir=ltr].
5
- Here is problem mostly no one need rtl and ltr related css at the same time in browser,
6
- we are try to split them by [dir] and load which type of css is needed.
7
- For this purpose we created RTL Split Plugin
8
-
9
-
10
- # To Try it out rtl-ltr split
11
- ### how to use this feature?
12
-
13
- to use this feature use have give the below oprtions
14
- `package.json`
15
- ```json
16
- {
17
- /// ...some things
18
- "react-cli": {
19
- // ...some things
20
- "css": {
21
- "enableRTLSplit": true,
22
- "templateLabel": "{{--dir}}",// this is for html template css file path dir template
23
- "disableMiniFiySelector": false,
24
- "dirVarName": "document.dir" // this will be used for download css based on dir
25
- },
26
- // ...some things
27
- }
28
- }
29
- ```
30
-
1
+ # RTL Split
2
+
3
+ we are doing in build time generating rtl related css code by using @zohodesk/postcss-rt npm.
4
+ It was automated, That postcss plugin create rtl reacted css and put them into same file, with css selector [dir=rtl] and ltr realted css with [dir=ltr].
5
+ Here is problem mostly no one need rtl and ltr related css at the same time in browser,
6
+ we are try to split them by [dir] and load which type of css is needed.
7
+ For this purpose we created RTL Split Plugin
8
+
9
+
10
+ # To Try it out rtl-ltr split
11
+ ### how to use this feature?
12
+
13
+ to use this feature use have give the below oprtions
14
+ `package.json`
15
+ ```json
16
+ {
17
+ /// ...some things
18
+ "react-cli": {
19
+ // ...some things
20
+ "css": {
21
+ "enableRTLSplit": true,
22
+ "templateLabel": "{{--dir}}",// this is for html template css file path dir template
23
+ "disableMiniFiySelector": false,
24
+ "dirVarName": "document.dir" // this will be used for download css based on dir
25
+ },
26
+ // ...some things
27
+ }
28
+ }
29
+ ```
30
+