weboptimizer 2.0.1417 → 2.0.1418

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 (2) hide show
  1. package/package.json +3 -3
  2. package/webpackConfigurator.js +156 -140
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weboptimizer",
3
- "version": "2.0.1417",
3
+ "version": "2.0.1418",
4
4
  "description": "A generic web optimizer, (module) bundler and development environment.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -560,7 +560,7 @@
560
560
  "directory": {
561
561
  "__evaluate__": "path.resolve(self.path.base, self.module.directoryNames[0])"
562
562
  },
563
- "watch": true
563
+ "watch": false
564
564
  }
565
565
  ],
566
566
  "watchFiles": {
@@ -887,7 +887,7 @@
887
887
  "node_modules"
888
888
  ],
889
889
  "enforceDeduplication": {
890
- "__evaluate__": "!self.module.resolveSymlinks"
890
+ "__evaluate__": "self.module.resolveSymlinks"
891
891
  },
892
892
  "html": {
893
893
  "additional": {
@@ -25,6 +25,8 @@ var _construct2 = _interopRequireDefault(require("@babel/runtime/helpers/constru
25
25
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
26
26
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
27
27
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
29
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
28
30
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
29
31
  var _clientnode = _interopRequireDefault(require("clientnode"));
30
32
  var _jsdom = require("jsdom");
@@ -35,14 +37,7 @@ var _webpackSources = require("webpack-sources");
35
37
  var _configurator = _interopRequireDefault(require("./configurator"));
36
38
  var _helper = _interopRequireDefault(require("./helper"));
37
39
  var _ejsLoader = _interopRequireDefault(require("./ejsLoader"));
38
- var _optionalRequire,
39
- _this = void 0,
40
- _configuration$path$c,
41
- _configuration$cache$,
42
- _configuration$cache,
43
- _configuration$cache2,
44
- _configuration$cache3,
45
- _configuration$path$c2;
40
+ var _optionalRequire, _configuration$path$c, _configuration$cache$, _configuration$cache, _configuration$cache2, _configuration$cache3, _configuration$path$c2;
46
41
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
47
42
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
48
43
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
@@ -234,57 +229,68 @@ pluginInstances.push({
234
229
  .replace(/##-#-#-##/g, '%>')
235
230
  */
236
231
 
237
- if (htmlAvailable && !['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2]) && configuration.inPlace.cascadingStyleSheet && Object.keys(configuration.inPlace.cascadingStyleSheet).length || configuration.inPlace.javaScript && Object.keys(configuration.inPlace.javaScript).length) pluginInstances.push({
238
- apply: function apply(compiler) {
239
- var publicPath = compiler.options.output.publicPath || '';
240
- if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
241
- compiler.hooks.compilation.tap('inPlaceHTMLAssets', function (compilation) {
242
- var hooks = plugins.HTML.getHooks(compilation);
243
- var inPlacedAssetNames = [];
244
- hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', function (assets) {
245
- var inPlace = function inPlace(type, tag) {
246
- var settings;
247
- var url = false;
248
- if (tag.tagName === 'script') {
249
- settings = configuration.inPlace.javaScript;
250
- url = tag.attributes.src;
251
- } else if (tag.tagName === 'style') {
252
- settings = configuration.inPlace.cascadingStyleSheet;
253
- url = tag.attributes.href;
254
- }
255
- if (!(url && typeof url === 'string')) return tag;
256
- var name = publicPath ? url.replace(publicPath, '') : url;
257
- if (compilation.assets[name] && settings[type] && [].concat(settings[type]).some(function (pattern) {
258
- return new RegExp(pattern).test(name);
259
- })) {
260
- var newAttributes = _objectSpread({}, tag.attributes);
261
- delete newAttributes.href;
262
- delete newAttributes.src;
263
- inPlacedAssetNames.push(name);
264
- return _objectSpread(_objectSpread({}, tag), {}, {
265
- attributes: newAttributes,
266
- innerHTML: compilation.assets[name].source(),
267
- tagName: 'script'
268
- });
269
- }
270
- return tag;
271
- };
272
- assets.headTags = assets.headTags.map(inPlace.bind(_this, 'head'));
273
- assets.bodyTags = assets.bodyTags.map(inPlace.bind(_this, 'body'));
274
- return assets;
275
- });
232
+ if (htmlAvailable && !['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2]) && configuration.inPlace.cascadingStyleSheet && Object.keys(configuration.inPlace.cascadingStyleSheet).length || configuration.inPlace.javaScript && Object.keys(configuration.inPlace.javaScript).length) {
233
+ var InPlaceAssetsIntoHTML = /*#__PURE__*/function () {
234
+ function InPlaceAssetsIntoHTML() {
235
+ (0, _classCallCheck2["default"])(this, InPlaceAssetsIntoHTML);
236
+ }
237
+ (0, _createClass2["default"])(InPlaceAssetsIntoHTML, [{
238
+ key: "apply",
239
+ value: function apply(compiler) {
240
+ var _this = this;
241
+ var publicPath = compiler.options.output.publicPath || '';
242
+ if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
243
+ compiler.hooks.compilation.tap('inPlaceHTMLAssets', function (compilation) {
244
+ var hooks = plugins.HTML.getHooks(compilation);
245
+ var inPlacedAssetNames = [];
246
+ hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', function (assets) {
247
+ var inPlace = function inPlace(type, tag) {
248
+ var settings;
249
+ var url = false;
250
+ if (tag.tagName === 'script') {
251
+ settings = configuration.inPlace.javaScript;
252
+ url = tag.attributes.src;
253
+ } else if (tag.tagName === 'style') {
254
+ settings = configuration.inPlace.cascadingStyleSheet;
255
+ url = tag.attributes.href;
256
+ }
257
+ if (!(url && typeof url === 'string')) return tag;
258
+ var name = publicPath ? url.replace(publicPath, '') : url;
259
+ if (compilation.assets[name] && settings[type] && [].concat(settings[type]).some(function (pattern) {
260
+ return new RegExp(pattern).test(name);
261
+ })) {
262
+ var newAttributes = _objectSpread({}, tag.attributes);
263
+ delete newAttributes.href;
264
+ delete newAttributes.src;
265
+ inPlacedAssetNames.push(name);
266
+ return _objectSpread(_objectSpread({}, tag), {}, {
267
+ attributes: newAttributes,
268
+ innerHTML: compilation.assets[name].source(),
269
+ tagName: 'script'
270
+ });
271
+ }
272
+ return tag;
273
+ };
274
+ assets.headTags = assets.headTags.map(inPlace.bind(_this, 'head'));
275
+ assets.bodyTags = assets.bodyTags.map(inPlace.bind(_this, 'body'));
276
+ return assets;
277
+ });
276
278
 
277
- // NOTE: Avoid if you still want to emit the runtime chunks:
278
- hooks.afterEmit.tap('inPlaceHTMLAssets', function (asset) {
279
- for (var _i6 = 0, _inPlacedAssetNames = inPlacedAssetNames; _i6 < _inPlacedAssetNames.length; _i6++) {
280
- var _name3 = _inPlacedAssetNames[_i6];
281
- delete compilation.assets[_name3];
282
- }
283
- return asset;
284
- });
285
- });
286
- }
287
- });
279
+ // NOTE: Avoid if you still want to emit the runtime chunks:
280
+ hooks.afterEmit.tap('inPlaceHTMLAssets', function (asset) {
281
+ for (var _i6 = 0, _inPlacedAssetNames = inPlacedAssetNames; _i6 < _inPlacedAssetNames.length; _i6++) {
282
+ var _name3 = _inPlacedAssetNames[_i6];
283
+ delete compilation.assets[_name3];
284
+ }
285
+ return asset;
286
+ });
287
+ });
288
+ }
289
+ }]);
290
+ return InPlaceAssetsIntoHTML;
291
+ }();
292
+ pluginInstances.push(new InPlaceAssetsIntoHTML());
293
+ }
288
294
  ///// endregion
289
295
  ///// region mark empty javaScript modules as dummy
290
296
  if (!(configuration.needed.javaScript || configuration.needed.javaScriptExtension || configuration.needed.typeScript || configuration.needed.typeScriptExtension)) configuration.files.compose.javaScript = (0, _path.resolve)(configuration.path.target.asset.javaScript, '.__dummy__.compiled.js');
@@ -419,93 +425,103 @@ if (configuration.injection.external.modules === '__implicit__')
419
425
  };
420
426
  ///// endregion
421
427
  //// endregion
422
- //// region apply final cascadingStyleSheet/dom/javaScript modifications/fixes
423
- if (htmlAvailable) pluginInstances.push({
424
- apply: function apply(compiler) {
425
- return compiler.hooks.compilation.tap('WebOptimizer', function (compilation) {
426
- plugins.HTML.getHooks(compilation).beforeEmit.tap('WebOptimizerPostProcessHTML', function (data) {
427
- /*
428
- NOTE: We have to prevent creating native "style" dom nodes
429
- to prevent jsdom from parsing the entire cascading style
430
- sheet. Which is error prune and very resource intensive.
431
- */
432
- var styleContents = [];
433
- data.html = data.html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style[^>]*>)/gi, function (match, startTag, content, endTag) {
434
- styleContents.push(content);
435
- return "".concat(startTag).concat(endTag);
436
- });
437
- var dom;
438
- try {
439
- /*
440
- NOTE: We have to translate template delimiter to html
441
- compatible sequences and translate it back later to
442
- avoid unexpected escape sequences in resulting html.
443
- */
444
- dom = new _jsdom.JSDOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
445
- } catch (error) {
446
- return data;
447
- }
448
- var linkables = {
449
- link: 'href',
450
- script: 'src'
451
- };
452
- for (var _i8 = 0, _Object$entries6 = Object.entries(linkables); _i8 < _Object$entries6.length; _i8++) {
453
- var _Object$entries6$_i = (0, _slicedToArray2["default"])(_Object$entries6[_i8], 2),
454
- tagName = _Object$entries6$_i[0],
455
- attributeName = _Object$entries6$_i[1];
456
- for (var _i9 = 0, _Array$from = Array.from(dom.window.document.querySelectorAll("".concat(tagName, "[").concat(attributeName, "*=\"?") + "".concat(configuration.hashAlgorithm, "=\"]"))); _i9 < _Array$from.length; _i9++) {
457
- var domNode = _Array$from[_i9];
428
+ //// region apply final html and inline cascadingStyleSheet/javaScript modifications/fixes
429
+ if (htmlAvailable) {
430
+ var HTMLTransformation = /*#__PURE__*/function () {
431
+ function HTMLTransformation() {
432
+ (0, _classCallCheck2["default"])(this, HTMLTransformation);
433
+ }
434
+ (0, _createClass2["default"])(HTMLTransformation, [{
435
+ key: "apply",
436
+ value: function apply(compiler) {
437
+ compiler.hooks.compilation.tap('WebOptimizer', function (compilation) {
438
+ plugins.HTML.getHooks(compilation).beforeEmit.tap('WebOptimizerPostProcessHTML', function (data) {
458
439
  /*
459
- NOTE: Removing symbols after a "&" in hash
460
- string is necessary to match the generated
461
- request strings in offline plugin.
440
+ NOTE: We have to prevent creating native "style" dom nodes
441
+ to prevent jsdom from parsing the entire cascading style
442
+ sheet. Which is error prune and very resource intensive.
462
443
  */
463
- domNode.setAttribute(attributeName, domNode.getAttribute(attributeName).replace(new RegExp('(\\?' + "".concat(configuration.hashAlgorithm, "=") + '[^&]+).*$'), '$1'));
464
- }
465
- }
466
- /*
467
- NOTE: We have to restore template delimiter and style
468
- contents.
469
- */
470
- data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, function (match, startTag, endTag) {
471
- return "".concat(startTag).concat(styleContents.shift()) + endTag;
472
- });
473
- // region post compilation
474
- var _iterator7 = _createForOfIteratorHelper(configuration.files.html),
475
- _step7;
476
- try {
477
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
478
- var htmlFileSpecification = _step7.value;
479
- if (htmlFileSpecification.filename === data.plugin.options.filename) {
480
- var _iterator8 = _createForOfIteratorHelper([].concat(htmlFileSpecification.template.use)),
481
- _step8;
482
- try {
483
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
484
- var _loaderConfiguration$;
485
- var loaderConfiguration = _step8.value;
486
- if ((_loaderConfiguration$ = loaderConfiguration.options) !== null && _loaderConfiguration$ !== void 0 && _loaderConfiguration$.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = _ejsLoader["default"].bind({
487
- query: _clientnode["default"].extend(true, _clientnode["default"].copy(loaderConfiguration.options) || {}, htmlFileSpecification.template.postCompileOptions)
488
- })(data.html);
444
+ var styleContents = [];
445
+ data.html = data.html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style[^>]*>)/gi, function (match, startTag, content, endTag) {
446
+ styleContents.push(content);
447
+ return "".concat(startTag).concat(endTag);
448
+ });
449
+ var dom;
450
+ try {
451
+ /*
452
+ NOTE: We have to translate template delimiter to html
453
+ compatible sequences and translate it back later to
454
+ avoid unexpected escape sequences in resulting html.
455
+ */
456
+ dom = new _jsdom.JSDOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
457
+ } catch (error) {
458
+ return data;
459
+ }
460
+ var linkables = {
461
+ link: 'href',
462
+ script: 'src'
463
+ };
464
+ for (var _i8 = 0, _Object$entries6 = Object.entries(linkables); _i8 < _Object$entries6.length; _i8++) {
465
+ var _Object$entries6$_i = (0, _slicedToArray2["default"])(_Object$entries6[_i8], 2),
466
+ tagName = _Object$entries6$_i[0],
467
+ attributeName = _Object$entries6$_i[1];
468
+ for (var _i9 = 0, _Array$from = Array.from(dom.window.document.querySelectorAll("".concat(tagName, "[").concat(attributeName, "*=\"?") + "".concat(configuration.hashAlgorithm, "=\"]"))); _i9 < _Array$from.length; _i9++) {
469
+ var domNode = _Array$from[_i9];
470
+ /*
471
+ NOTE: Removing symbols after a "&" in hash
472
+ string is necessary to match the generated
473
+ request strings in offline plugin.
474
+ */
475
+ domNode.setAttribute(attributeName, domNode.getAttribute(attributeName).replace(new RegExp('(\\?' + "".concat(configuration.hashAlgorithm, "=") + '[^&]+).*$'), '$1'));
476
+ }
477
+ }
478
+ /*
479
+ NOTE: We have to restore template delimiter and style
480
+ contents.
481
+ */
482
+ data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, function (match, startTag, endTag) {
483
+ return "".concat(startTag).concat(styleContents.shift()) + endTag;
484
+ });
485
+ // region post compilation
486
+ var _iterator7 = _createForOfIteratorHelper(configuration.files.html),
487
+ _step7;
488
+ try {
489
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
490
+ var htmlFileSpecification = _step7.value;
491
+ if (htmlFileSpecification.filename === data.plugin.options.filename) {
492
+ var _iterator8 = _createForOfIteratorHelper([].concat(htmlFileSpecification.template.use)),
493
+ _step8;
494
+ try {
495
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
496
+ var _loaderConfiguration$;
497
+ var loaderConfiguration = _step8.value;
498
+ if ((_loaderConfiguration$ = loaderConfiguration.options) !== null && _loaderConfiguration$ !== void 0 && _loaderConfiguration$.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = _ejsLoader["default"].bind({
499
+ query: _clientnode["default"].extend(true, _clientnode["default"].copy(loaderConfiguration.options) || {}, htmlFileSpecification.template.postCompileOptions)
500
+ })(data.html);
501
+ }
502
+ } catch (err) {
503
+ _iterator8.e(err);
504
+ } finally {
505
+ _iterator8.f();
506
+ }
507
+ break;
489
508
  }
490
- } catch (err) {
491
- _iterator8.e(err);
492
- } finally {
493
- _iterator8.f();
494
509
  }
495
- break;
510
+ // endregion
511
+ } catch (err) {
512
+ _iterator7.e(err);
513
+ } finally {
514
+ _iterator7.f();
496
515
  }
497
- }
498
- // endregion
499
- } catch (err) {
500
- _iterator7.e(err);
501
- } finally {
502
- _iterator7.f();
503
- }
504
- return data;
505
- });
506
- });
507
- }
508
- });
516
+ return data;
517
+ });
518
+ });
519
+ }
520
+ }]);
521
+ return HTMLTransformation;
522
+ }();
523
+ pluginInstances.push(new HTMLTransformation());
524
+ }
509
525
  //// endregion
510
526
  //// region context replacements
511
527
  var _iterator9 = _createForOfIteratorHelper(_module.replacements.context),