@zohodesk/client_build_tool 0.0.1 → 0.0.3

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/ConfigurationDocumentation.md +239 -73
  3. package/README.md +38 -4
  4. package/README_backup.md +2 -0
  5. package/TODO.md +1 -1
  6. package/coverage/addFilesNamesToManifestJson.js.html +148 -0
  7. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/addFilesNamesToManifestJson.js.html +148 -0
  8. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/createInitialEntries.js.html +136 -0
  9. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/createManifestJson.js.html +181 -0
  10. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/findInitialFileNames.js.html +133 -0
  11. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/index.html +146 -0
  12. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/index.js.html +199 -0
  13. package/coverage/bundler/webpack/custom_plugins/AddManifestJson/removeHashFromFileName.js.html +127 -0
  14. package/coverage/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js.html +346 -0
  15. package/coverage/bundler/webpack/custom_plugins/VariableConversionCollector/index.html +116 -0
  16. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/constants.js.html +94 -0
  17. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js.html +259 -0
  18. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/index.html +236 -0
  19. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/index.js.html +442 -0
  20. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/insertBefore.js.html +154 -0
  21. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js.html +142 -0
  22. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js.html +127 -0
  23. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js.html +139 -0
  24. package/coverage/{updateArrayWithDefault.js.html → bundler/webpack/custom_postcss_plugins/HoverActivePlugin/specialCases.js.html} +55 -67
  25. package/coverage/bundler/webpack/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js.html +193 -0
  26. package/coverage/bundler/webpack/custom_postcss_plugins/SelectorReplace.js.html +292 -0
  27. package/coverage/bundler/webpack/custom_postcss_plugins/ValueReplacer.js.html +223 -0
  28. package/coverage/bundler/webpack/custom_postcss_plugins/VariableModificationPlugin/index.html +116 -0
  29. package/coverage/bundler/webpack/custom_postcss_plugins/VariableModificationPlugin/index.js.html +1126 -0
  30. package/coverage/bundler/webpack/custom_postcss_plugins/index.html +131 -0
  31. package/coverage/bundler/webpack/loaderConfigs/getSpecificPostCssPlugin.js.html +247 -0
  32. package/coverage/bundler/webpack/loaderConfigs/index.html +116 -0
  33. package/coverage/coverage-final.json +3 -1
  34. package/coverage/coverage-summary.json +4 -2
  35. package/coverage/createInitialEntries.js.html +136 -0
  36. package/coverage/dummy.js.html +238 -0
  37. package/coverage/index.html +51 -21
  38. package/coverage/index.js.html +169 -0
  39. package/coverage/isObject.js.html +94 -0
  40. package/coverage/isValid.js.html +106 -0
  41. package/coverage/removeHashFromFileName.js.html +127 -0
  42. package/docs/BabelCustomizations.md +55 -0
  43. package/lib/commands/build/preProcessor.js +12 -0
  44. package/lib/commands/buildEs/preProcessor.js +17 -0
  45. package/lib/commands/buildLib/preProcessor.js +17 -0
  46. package/lib/commands/pre_process/commandExecutor.js +18 -0
  47. package/lib/commands/pre_process/config.js +12 -0
  48. package/lib/commands/start/preProcessor.js +3 -1
  49. package/lib/schemas/defaultConfigValues.js +66 -30
  50. package/lib/schemas/defaultConfigValuesOnly.js +20 -1
  51. package/lib/shared/babel/addDefaultPlugins.js +15 -0
  52. package/lib/shared/babel/babelWebConfig.js +2 -2
  53. package/lib/shared/babel/getBabelPlugin.js +37 -0
  54. package/lib/shared/bundler/webpack/common/nameTemplates.js +31 -8
  55. package/lib/shared/bundler/webpack/configCustomLoaders.js +1 -1
  56. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +22 -2
  57. package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +4 -2
  58. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +4 -2
  59. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +4 -2
  60. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +1 -1
  61. package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +80 -0
  62. package/lib/shared/bundler/webpack/getCSSLoaders.js +2 -0
  63. package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +1 -53
  64. package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +7 -0
  65. package/lib/shared/bundler/webpack/outputConfig.js +11 -2
  66. package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +20 -0
  67. package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +25 -10
  68. package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +2 -2
  69. package/lib/shared/bundler/webpack/plugins.js +3 -1
  70. package/lib/shared/bundler/webpack/statsConfig.js +11 -2
  71. package/lib/shared/bundler/webpack/webpackConfig.js +2 -2
  72. package/lib/shared/commands-utils/spawnSyncIO.js +5 -5
  73. package/lib/shared/pre_process/runPreProcess.js +58 -0
  74. package/lib/shared/server/mockApiHandler.js +1 -1
  75. package/npm-shrinkwrap.json +552 -2209
  76. package/package.json +8 -3
  77. package/result.json +1 -1
  78. package/unittest/index.html +33 -35
  79. package/lib/commands/build/errorHander.js +0 -10
  80. package/lib/commands/start/deprecationHandler.js +0 -10
  81. package/lib/commands/start/errorHander.js +0 -10
  82. package/lib/commands/start/postProcessor.js +0 -10
  83. package/lib/commands/version/errorHander.js +0 -10
  84. package/lib/shared/babel/defaultBabelPlugins.js +0 -26
  85. /package/lib/shared/bundler/webpack/{getSourceMapType.js → devtoolConfig.js} +0 -0
@@ -13,8 +13,9 @@ var _default = {
13
13
  value: 'app',
14
14
  cli: 'context'
15
15
  },
16
- devtool: 'hidden-cheap-source-map',
17
- enableChunkHash: {
16
+ devtool: 'source-map',
17
+ statsLogConfig: null,
18
+ enableFileNameHashing: {
18
19
  value: false,
19
20
  cli: 'enable_hash'
20
21
  },
@@ -22,18 +23,6 @@ var _default = {
22
23
  value: false,
23
24
  cli: 'bundle_analyze'
24
25
  },
25
- devConsoleExclude: {
26
- value: false,
27
- cli: 'bundle_analyze'
28
- },
29
- separateCssModules: {
30
- value: false,
31
- cli: 'separate_css_modules'
32
- },
33
- enableFileNameHashing: {
34
- value: false,
35
- cli: 'separate_css_modules'
36
- },
37
26
  enableMockReplace: {
38
27
  value: false,
39
28
  cli: 'enable_mock_replace'
@@ -68,7 +57,7 @@ var _default = {
68
57
  cli: 'port'
69
58
  },
70
59
  domain: {
71
- value: 'tsi',
60
+ value: null,
72
61
  cli: 'domain'
73
62
  },
74
63
  disableContextURL: {
@@ -225,13 +214,35 @@ var _default = {
225
214
  },
226
215
  createSeparateSMap: {
227
216
  value: false,
228
- cli: 'source_map_enable'
217
+ cli: 'enable_smap'
229
218
  },
230
219
  babelCustomizations: {
231
220
  browserList: null,
232
221
  // NOTE: need to consider
233
222
  // presets: [],
234
- plugins: []
223
+ plugins: [],
224
+ removeAttribute: {
225
+ enable: false,
226
+ options: {
227
+ attributeNames: ['data-testid']
228
+ }
229
+ },
230
+ removePropTypes: {
231
+ enable: false,
232
+ options: {
233
+ mode: 'remove',
234
+ removeImport: true
235
+ }
236
+ },
237
+ devConsoleExclude: {
238
+ enable: {
239
+ value: false,
240
+ cli: 'console_exclude'
241
+ },
242
+ options: {
243
+ exclude: ['error']
244
+ }
245
+ }
235
246
  },
236
247
  webpackPlugins: [],
237
248
  vendorPatterns: [],
@@ -241,14 +252,17 @@ var _default = {
241
252
  patterns: ['*.css']
242
253
  }],
243
254
  cdnMapping: {
244
- isCdnEnabled: false,
255
+ isCdnEnabled: {
256
+ value: false,
257
+ cli: 'enable_cdn'
258
+ },
245
259
  variableName: '',
246
260
  cssTemplate: '',
247
261
  jsTemplate: '',
248
262
  i18nTemplate: ''
249
263
  },
250
264
  manifestJson: {
251
- enable: true
265
+ enable: false
252
266
  },
253
267
  changeRuntimeChunkChar: '~',
254
268
  serviceWorker: {
@@ -257,20 +271,42 @@ var _default = {
257
271
  outputFilePath: '/v1.js',
258
272
  replaceText: '//<!--AssetsFromBuild -->'
259
273
  },
260
- removeAttribute: {
261
- enable: true,
262
- attributeNames: ['data-testid']
263
- },
264
274
  customLoaders: [],
265
275
  resourceHints: {
266
276
  allowPrefetchingMultipleChunks: false
267
277
  },
268
- fileHashMappingToVariable: [{
269
- filePath: 'tp/crmplus/crmplusimpl.js',
270
- key: '__CRMPLUS_IMPL_HASH__',
271
- // fileNameTemplate: '[path]/[name]-[hash:15]_.[ext]',
272
- // fileName: 'crmplusimpl.js',
273
- hashLength: 20
274
- }]
278
+ devModeContentHashAllowedTypes: null,
279
+ devLikeHash: {
280
+ value: false,
281
+ cli: 'dev_like_hash'
282
+ },
283
+ disableReactDevWarning: {
284
+ value: false,
285
+ cli: 'disable_react_dev_warning'
286
+ },
287
+ preProcess: {
288
+ enable: {
289
+ value: false,
290
+ cli: 'enable_pre_process'
291
+ },
292
+ // This option is for tell the CBT to which is preprocessor js file path
293
+ runner: {
294
+ value: '',
295
+ cli: 'preprocessor'
296
+ },
297
+ // usually preprocessor run in nodemon for, start and docs , preprocessor
298
+ stopNodemon: {
299
+ value: false,
300
+ cli: 'stop_nodemon'
301
+ }
302
+ },
303
+ fileHashMappingToVariable: null,
304
+ customAttributes: {
305
+ enable: false,
306
+ attributes: null,
307
+ jsAttributes: null,
308
+ cssAttributes: null,
309
+ i18nAttributes: null
310
+ }
275
311
  };
276
312
  exports.default = _default;
@@ -11,7 +11,7 @@ var _os = require("os");
11
11
  var _default = {
12
12
  context: 'app',
13
13
  devtool: 'hidden-cheap-source-map',
14
- enableChunkHash: false,
14
+ enableFileNameHashing: false,
15
15
  bundleAnalyze: false,
16
16
  enableMockReplace: false,
17
17
  noPublicPath: false,
@@ -124,6 +124,25 @@ var _default = {
124
124
  createSeparateSMap: false,
125
125
  babelCustomizations: {
126
126
  browserList: null,
127
+ removeAttribute: {
128
+ enable: false,
129
+ options: {
130
+ attributeNames: ['data-testid']
131
+ }
132
+ },
133
+ removePropTypes: {
134
+ enable: false,
135
+ options: {
136
+ mode: 'remove',
137
+ removeImport: true
138
+ }
139
+ },
140
+ devConsoleExclude: {
141
+ enable: false,
142
+ options: {
143
+ exclude: ['error']
144
+ }
145
+ },
127
146
  // NOTE: need to consider
128
147
  // presets: [],
129
148
  plugins: []
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addDefaultPlugins = addDefaultPlugins;
7
+
8
+ function addDefaultPlugins(plugin, pluginName) {
9
+ if (plugin.enable) {
10
+ return [require.resolve(pluginName), plugin.options];
11
+ }
12
+
13
+ ;
14
+ return null;
15
+ }
@@ -9,7 +9,7 @@ var _helperCompilationTargets = _interopRequireDefault(require("@babel/helper-co
9
9
 
10
10
  var _logger = require("../../logger");
11
11
 
12
- var _defaultBabelPlugins = require("./defaultBabelPlugins");
12
+ var _getBabelPlugin = require("./getBabelPlugin");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
@@ -27,7 +27,7 @@ function babelWebConfig(options, mode) {
27
27
  } = options.babelCustomizations;
28
28
  return {
29
29
  presets: [getBabelPresetEnvConfig(browserList, mode), require.resolve('@babel/preset-react')],
30
- plugins: customBabelPlugins(babelPlugins).concat((0, _defaultBabelPlugins.defaultBabelPlugins)(options)).filter(Boolean)
30
+ plugins: customBabelPlugins(babelPlugins).concat((0, _getBabelPlugin.getBabelPlugin)(options)).filter(Boolean)
31
31
  };
32
32
  }
33
33
 
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getBabelPlugin = getBabelPlugin;
7
+
8
+ var _modeUtils = require("../bundler/webpack/common/modeUtils");
9
+
10
+ var _addDefaultPlugins = require("./addDefaultPlugins");
11
+
12
+ const babelPluginMapping = {
13
+ removeAttribute: './babel_plugins/removeAttributesPlugin',
14
+ removePropTypes: 'babel-plugin-transform-react-remove-prop-types',
15
+ devConsoleExclude: 'babel-plugin-transform-remove-console'
16
+ };
17
+ const babelPluginOrder = ['removeAttribute', 'removePropTypes', 'devConsoleExclude'];
18
+
19
+ function getBabelPlugin(options) {
20
+ const {
21
+ mode
22
+ } = options;
23
+ let customPlugins = [];
24
+ const {
25
+ babelCustomizations
26
+ } = options;
27
+
28
+ if ((0, _modeUtils.isProductionMode)(mode)) {
29
+ const configCreator = _addDefaultPlugins.addDefaultPlugins;
30
+ const plugins = babelPluginOrder.map(p => configCreator(babelCustomizations[p], babelPluginMapping[p]));
31
+ customPlugins = plugins;
32
+ }
33
+
34
+ return customPlugins.filter(Boolean);
35
+ }
36
+
37
+ ;
@@ -42,7 +42,7 @@ function createNameTemplate(name, useHash) {
42
42
  return useHash ? name[1] : name[0];
43
43
  }
44
44
 
45
- const devModeContentHashAllowedTypes = {
45
+ const defaultDevModeContentHashAllowedTypes = {
46
46
  image: true,
47
47
  font: true,
48
48
  svg: true,
@@ -52,22 +52,45 @@ const devModeContentHashAllowedTypes = {
52
52
 
53
53
  function nameTemplates(type, options) {
54
54
  const {
55
- enableChunkHash,
56
- mode
55
+ enableFileNameHashing,
56
+ mode,
57
+ devLikeHash
57
58
  } = options;
59
+ let {
60
+ devModeContentHashAllowedTypes
61
+ } = options;
62
+ devModeContentHashAllowedTypes = devModeContentHashAllowedTypes || defaultDevModeContentHashAllowedTypes;
58
63
  const templateName = templates[type];
59
64
 
60
65
  if (!templateName) {
61
66
  throw Error(`specified type not valid Type: ${type}`);
62
- }
67
+ } // eslint-disable-next-line no-use-before-define
68
+
69
+
70
+ const useHash = checkCanWeAllowHash({
71
+ enableFileNameHashing,
72
+ devLikeHash: devLikeHash || (0, _modeUtils.isDevelopmentMode)(mode),
73
+ type,
74
+ devModeContentHashAllowedTypes
75
+ });
76
+ return createNameTemplate(templateName, useHash);
77
+ }
63
78
 
64
- let useHash = enableChunkHash;
79
+ function checkCanWeAllowHash({
80
+ enableFileNameHashing,
81
+ devLikeHash,
82
+ type,
83
+ devModeContentHashAllowedTypes
84
+ }) {
85
+ if (!enableFileNameHashing) {
86
+ return false;
87
+ }
65
88
 
66
- if ((0, _modeUtils.isDevelopmentMode)(mode) && enableChunkHash && !devModeContentHashAllowedTypes[type]) {
67
- useHash = false;
89
+ if (devLikeHash) {
90
+ return devModeContentHashAllowedTypes[type];
68
91
  }
69
92
 
70
- return createNameTemplate(templateName, useHash);
93
+ return true;
71
94
  } // export function cssDirNameTemplate(dir, options) {
72
95
  // return nameTemplates('cssdir', options).replace(/\[dir\]/g, dir);
73
96
  // }
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.configCustomLoaders = configCustomLoaders;
7
7
 
8
8
  function configCustomLoaders(options) {
9
- return options.customLoaders;
9
+ return options.customLoaders || [];
10
10
  }
@@ -23,6 +23,8 @@ var _I18nFilesEmitPlugin = require("./I18nFilesEmitPlugin");
23
23
 
24
24
  var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
25
25
 
26
+ var _logger = require("../../../../../logger");
27
+
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
29
 
28
30
  const {
@@ -63,7 +65,7 @@ class I18nRuntimeDealerPlugin {
63
65
  mainChunkName
64
66
  } = this.options; // const dummyContent = '// dummy comment';
65
67
 
66
- const dummyContentHash = 'qwertyuiopasdfghjkl';
68
+ const dummyContentHash = 'dummy0content0hashes';
67
69
  const entryPoint = compilation.entrypoints.get(mainChunkName);
68
70
  const initialChunks = Array.from(entryPoint.chunks).filter(c => c.canBeInitial() && c.id !== c.runtime);
69
71
  const initialI18nAssets = initialChunks.filter(c => i18nStore.isChunkHasI18n(c)).map(c => {
@@ -172,10 +174,28 @@ class I18nRuntimeDealerPlugin {
172
174
  runtimeFileName,
173
175
  runtimeFileSourceStr,
174
176
  i18nChunks
175
- })); // NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html
177
+ })); // NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html and efc
176
178
  // compilation.deleteAsset(runtimeFileName);
177
179
  }
178
180
  });
181
+ compilation.hooks.processAssets.tap({
182
+ name: pluginName,
183
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE // additionalAssets: true
184
+
185
+ }, () => {
186
+ // eslint-disable-next-line no-underscore-dangle
187
+ const entries = compilation._getChunkGraphEntries(); // eslint-disable-next-line no-restricted-syntax
188
+
189
+
190
+ for (const entryChunk of entries) {
191
+ const runtimeFileName = [...entryChunk.files][0] || '';
192
+
193
+ if (runtimeFileName.includes('runtime') && runtimeFileName.includes('[local]')) {
194
+ (0, _logger.verboseLogger)('deleteAsset', runtimeFileName);
195
+ compilation.deleteAsset(runtimeFileName);
196
+ }
197
+ }
198
+ });
179
199
  }
180
200
  }
181
201
 
@@ -9,6 +9,8 @@ var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
+ const pluginName = 'InitialHtmlPlugin';
13
+
12
14
  class InitialHtmlPlugin {
13
15
  constructor(options) {
14
16
  this.options = options;
@@ -30,8 +32,8 @@ class InitialHtmlPlugin {
30
32
  inject,
31
33
  scriptLoading: 'defer'
32
34
  }).apply(compiler);
33
- compiler.hooks.thisCompilation.tap('InitialHtmlPlugin', compilation => {
34
- _htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync('MyPlugin', (data, cb) => {
35
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
36
+ _htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, cb) => {
35
37
  const headTags = [];
36
38
  const bodyTags = [];
37
39
  data.headTags.forEach(tag => {
@@ -9,6 +9,8 @@ var _webpack = require("webpack");
9
9
 
10
10
  var _createManifestJson = require("./createManifestJson");
11
11
 
12
+ const pluginName = 'AddFileToManifestJson';
13
+
12
14
  class AddFileToManifestJson {
13
15
  constructor(options) {
14
16
  this.options = options;
@@ -18,9 +20,9 @@ class AddFileToManifestJson {
18
20
  const {
19
21
  RawSource
20
22
  } = compiler.webpack.sources;
21
- compiler.hooks.thisCompilation.tap('MyWebpackPlugin', compilation => {
23
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
22
24
  compilation.hooks.processAssets.tap({
23
- name: 'MyPlugin',
25
+ name: pluginName,
24
26
  stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
25
27
  }, assets => {
26
28
  const {
@@ -8,14 +8,16 @@ exports.SourceMapPlugin = void 0;
8
8
  var _webpack = require("webpack");
9
9
 
10
10
  /* eslint-disable class-methods-use-this */
11
+ const pluginName = 'SplitSourceMapPlugin';
12
+
11
13
  class SourceMapPlugin {
12
14
  apply(compiler) {
13
15
  const {
14
16
  RawSource
15
17
  } = compiler.webpack.sources;
16
- compiler.hooks.thisCompilation.tap('splitSourceMap', compilation => {
18
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
17
19
  compilation.hooks.processAssets.tap({
18
- name: 'splitSourceMap',
20
+ name: pluginName,
19
21
  stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
20
22
  }, assets => {
21
23
  Object.keys(assets).forEach(assetName => {
@@ -29,7 +29,7 @@ class TPHashMappingPlugin {
29
29
 
30
30
  getFiles() {
31
31
  const hashMapping = {};
32
- this.fileMappings.forEach(fileInfo => {
32
+ this.fileMappings.filter(f => f.enable).forEach(fileInfo => {
33
33
  const filePath = _path.default.join(this.tpFolder, fileInfo.filePath);
34
34
 
35
35
  if (_fs.default.existsSync(filePath)) {
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CustomAttributesPlugin = void 0;
7
+
8
+ var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-webpack-inject-attributes-plugin"));
9
+
10
+ var _webpack = require("webpack");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const pluginName = 'CustomAttributesPlugin';
15
+
16
+ function attributeSetTemplate(attributes, variableName) {
17
+ const str = [];
18
+ Object.keys(attributes).forEach(key => {
19
+ const val = attributes[key];
20
+ str.push(`${variableName}.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(val)});`);
21
+ });
22
+ return str;
23
+ }
24
+
25
+ function writeCss(attributes, code) {
26
+ const str = attributeSetTemplate(attributes, 'linkTag');
27
+ return code.replace('document.head.appendChild(linkTag);', `${str.join('')}document.head.appendChild(linkTag);`);
28
+ }
29
+
30
+ function writeI18nJs(attributes, code) {
31
+ const str = attributeSetTemplate(attributes, 'scripTag');
32
+ return code.replace('document.head.appendChild(scriptTag);', `{${str.join('')} document.head.appendChild(scriptTag)};`);
33
+ }
34
+
35
+ function writeJs(attributes, code) {
36
+ const str = attributeSetTemplate(attributes, 'script');
37
+ return code.replace('needAttach && document.head.appendChild(script);', `if(needAttach) {${str.join('')} document.head.appendChild(script)};`);
38
+ }
39
+
40
+ class CustomAttributesPlugin {
41
+ constructor(options) {
42
+ this.options = {
43
+ attributes: options.attributes,
44
+ jsAttributes: options.jsAttributes || options.attributes || {},
45
+ cssAttributes: options.cssAttributes || options.attributes || {},
46
+ i18nAttributes: options.i18nAttributes || options.attributes || {}
47
+ };
48
+ }
49
+
50
+ apply(compiler) {
51
+ const {
52
+ RawSource
53
+ } = compiler.webpack.sources; // NOTE: we not using this, Reason currently this option is only need for EFC,
54
+ // So it do not needed.
55
+
56
+ const {
57
+ attributes
58
+ } = this.options;
59
+ attributes && new _htmlWebpackInjectAttributesPlugin.default(attributes).apply(compiler);
60
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
61
+ compilation.hooks.processAssets.tap({
62
+ name: pluginName,
63
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED
64
+ }, assets => {
65
+ const asset = Object.keys(assets).filter(k => /runtime.*\.js$/g.test(k));
66
+ asset.forEach(e => {
67
+ const runtimeJS = assets[e];
68
+ let code = runtimeJS.source();
69
+ code = writeCss(this.options.cssAttributes, code);
70
+ code = writeI18nJs(this.options.i18nAttributes, code);
71
+ code = writeJs(this.options.jsAttributes, code);
72
+ compilation.updateAsset(e, new RawSource(code));
73
+ });
74
+ });
75
+ });
76
+ }
77
+
78
+ }
79
+
80
+ exports.CustomAttributesPlugin = CustomAttributesPlugin;
@@ -16,6 +16,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
16
  function getCSSLoaders(options) {
17
17
  const cssLoaderOptions = (0, _getCssLoaderOptions.getCssLoaderOptions)(options);
18
18
  return [{
19
+ loader: require.resolve('./loaders/miniCssFallBackLoader')
20
+ }, {
19
21
  loader: _miniCssExtractPlugin.default.loader,
20
22
  options: {
21
23
  publicPath: '../'
@@ -11,7 +11,6 @@ exports.configVideoLoader = configVideoLoader;
11
11
 
12
12
  var _nameTemplates = require("../common/nameTemplates");
13
13
 
14
- // function getLoaderOptionQueryString(params) {
15
14
  const ImageExtRegex = /\.jpe?g$|\.gif$|\.png|\.webp$/;
16
15
  const FontExtRegex = /\.woff2|\.woff$|\.ttf$|\.eot$/;
17
16
  const SVGExtRegex = /\.svg$/;
@@ -47,16 +46,6 @@ function createAssetLoader({
47
46
 
48
47
  return conf;
49
48
  }
50
- /**
51
- * @typedef {Object} LoaderConfig
52
- * @property {Number} enableChunkHash
53
- */
54
-
55
- /**
56
- * @param {LoaderConfig} options
57
- * @returns
58
- */
59
-
60
49
 
61
50
  function configImageLoader(options) {
62
51
  return createAssetLoader({
@@ -94,45 +83,4 @@ function configVideoLoader(options) {
94
83
  test: VideoExtRegex,
95
84
  nameTemplate: (0, _nameTemplates.nameTemplates)('video', options)
96
85
  });
97
- }
98
- /*
99
- export function createNameTemplate(enableChunkHash) {
100
- const ext = `${enableChunkHash ? ".[hash:20]" : ""}.[ext]`;
101
- return `[name]${ext}`;
102
- }
103
-
104
- export function createImageAndFontsAndSVGLoaders(enableChunkHash) {
105
- const nameTemplate = createNameTemplate(enableChunkHash);
106
- return [
107
- configImageLoader(nameTemplate),
108
- configFontLoader(nameTemplate),
109
- configSVGLoader(nameTemplate),
110
- configAudioLoader(nameTemplate)
111
- ];
112
- }
113
- */
114
-
115
- /*
116
- export function createLoaderOptionObject(
117
- loaderName,
118
- nameTemplate,
119
- fallback,
120
- limit = 1000
121
- ) {
122
- return {
123
- loader: loaderName,
124
- options: {
125
- limit,
126
- name: nameTemplate,
127
- fallback
128
- }
129
- };
130
- }
131
-
132
- function configLoaderObject(filter, loaderAndOptions) {
133
- return {
134
- test: filter,
135
- use: loaderAndOptions
136
- };
137
- }
138
- */
86
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ module.exports = function miniCssFallBackLoader(source) {
4
+ const replacedStr = source.replace('export default ', 'module.exports = '); // console.log('src/loaders/docsLoader.js', replacedStr);
5
+
6
+ return replacedStr;
7
+ };
@@ -16,13 +16,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
16
  function outputConfig(options) {
17
17
  const {
18
18
  output,
19
- publicPath
19
+ publicPath,
20
+ htmlTemplate,
21
+ context
20
22
  } = options;
21
- return {
23
+ const outputO = {
22
24
  filename: (0, _nameTemplates.nameTemplates)('js', options),
23
25
  chunkFilename: (0, _nameTemplates.nameTemplates)('chunkjs', options),
26
+ chunkLoadingGlobal: `${context}Jsonp`,
24
27
  publicPath,
25
28
  // clean: true,
26
29
  path: _path.default.resolve(_constants.appPath, output)
27
30
  };
31
+
32
+ if (htmlTemplate.crossorigin) {
33
+ outputO.crossOriginLoading = 'anonymous';
34
+ }
35
+
36
+ return outputO;
28
37
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configCustomAttributesPlugin = configCustomAttributesPlugin;
7
+
8
+ var _custom_attribute_plugin = require("../custom_plugins/custom_attribute_plugin");
9
+
10
+ function configCustomAttributesPlugin(options) {
11
+ const {
12
+ customAttributes
13
+ } = options;
14
+
15
+ if (customAttributes.enable) {
16
+ return new _custom_attribute_plugin.CustomAttributesPlugin(customAttributes);
17
+ }
18
+
19
+ return null;
20
+ }