weboptimizer 2.0.1416 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weboptimizer",
3
- "version": "2.0.1416",
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": {
package/type.d.ts CHANGED
@@ -255,12 +255,13 @@ export interface ResolvedConfiguration {
255
255
  contextType: string;
256
256
  debug: boolean;
257
257
  development: {
258
- server: WebpackOptionsNormalized['devServer'] & {
258
+ server: (WebpackOptionsNormalized['devServer'] & {
259
+ hot: boolean;
259
260
  host: string;
260
261
  https: boolean;
261
262
  liveReload: boolean;
262
263
  port: number;
263
- };
264
+ });
264
265
  tool: WebpackOptionsNormalized['devtool'];
265
266
  };
266
267
  document: PlainObject;
@@ -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,12 +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$cache2,
43
- _configuration$path$c2;
40
+ var _optionalRequire, _configuration$path$c, _configuration$cache$, _configuration$cache, _configuration$cache2, _configuration$cache3, _configuration$path$c2;
44
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; }
45
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; }
46
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; } } }; }
@@ -232,57 +229,68 @@ pluginInstances.push({
232
229
  .replace(/##-#-#-##/g, '%>')
233
230
  */
234
231
 
235
- 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({
236
- apply: function apply(compiler) {
237
- var publicPath = compiler.options.output.publicPath || '';
238
- if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
239
- compiler.hooks.compilation.tap('inPlaceHTMLAssets', function (compilation) {
240
- var hooks = plugins.HTML.getHooks(compilation);
241
- var inPlacedAssetNames = [];
242
- hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', function (assets) {
243
- var inPlace = function inPlace(type, tag) {
244
- var settings;
245
- var url = false;
246
- if (tag.tagName === 'script') {
247
- settings = configuration.inPlace.javaScript;
248
- url = tag.attributes.src;
249
- } else if (tag.tagName === 'style') {
250
- settings = configuration.inPlace.cascadingStyleSheet;
251
- url = tag.attributes.href;
252
- }
253
- if (!(url && typeof url === 'string')) return tag;
254
- var name = publicPath ? url.replace(publicPath, '') : url;
255
- if (compilation.assets[name] && settings[type] && [].concat(settings[type]).some(function (pattern) {
256
- return new RegExp(pattern).test(name);
257
- })) {
258
- var newAttributes = _objectSpread({}, tag.attributes);
259
- delete newAttributes.href;
260
- delete newAttributes.src;
261
- inPlacedAssetNames.push(name);
262
- return _objectSpread(_objectSpread({}, tag), {}, {
263
- attributes: newAttributes,
264
- innerHTML: compilation.assets[name].source(),
265
- tagName: 'script'
266
- });
267
- }
268
- return tag;
269
- };
270
- assets.headTags = assets.headTags.map(inPlace.bind(_this, 'head'));
271
- assets.bodyTags = assets.bodyTags.map(inPlace.bind(_this, 'body'));
272
- return assets;
273
- });
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
+ });
274
278
 
275
- // NOTE: Avoid if you still want to emit the runtime chunks:
276
- hooks.afterEmit.tap('inPlaceHTMLAssets', function (asset) {
277
- for (var _i6 = 0, _inPlacedAssetNames = inPlacedAssetNames; _i6 < _inPlacedAssetNames.length; _i6++) {
278
- var _name3 = _inPlacedAssetNames[_i6];
279
- delete compilation.assets[_name3];
280
- }
281
- return asset;
282
- });
283
- });
284
- }
285
- });
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
+ }
286
294
  ///// endregion
287
295
  ///// region mark empty javaScript modules as dummy
288
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');
@@ -417,93 +425,103 @@ if (configuration.injection.external.modules === '__implicit__')
417
425
  };
418
426
  ///// endregion
419
427
  //// endregion
420
- //// region apply final cascadingStyleSheet/dom/javaScript modifications/fixes
421
- if (htmlAvailable) pluginInstances.push({
422
- apply: function apply(compiler) {
423
- return compiler.hooks.compilation.tap('WebOptimizer', function (compilation) {
424
- plugins.HTML.getHooks(compilation).beforeEmit.tap('WebOptimizerPostProcessHTML', function (data) {
425
- /*
426
- NOTE: We have to prevent creating native "style" dom nodes
427
- to prevent jsdom from parsing the entire cascading style
428
- sheet. Which is error prune and very resource intensive.
429
- */
430
- var styleContents = [];
431
- data.html = data.html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style[^>]*>)/gi, function (match, startTag, content, endTag) {
432
- styleContents.push(content);
433
- return "".concat(startTag).concat(endTag);
434
- });
435
- var dom;
436
- try {
437
- /*
438
- NOTE: We have to translate template delimiter to html
439
- compatible sequences and translate it back later to
440
- avoid unexpected escape sequences in resulting html.
441
- */
442
- dom = new _jsdom.JSDOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
443
- } catch (error) {
444
- return data;
445
- }
446
- var linkables = {
447
- link: 'href',
448
- script: 'src'
449
- };
450
- for (var _i8 = 0, _Object$entries6 = Object.entries(linkables); _i8 < _Object$entries6.length; _i8++) {
451
- var _Object$entries6$_i = (0, _slicedToArray2["default"])(_Object$entries6[_i8], 2),
452
- tagName = _Object$entries6$_i[0],
453
- attributeName = _Object$entries6$_i[1];
454
- for (var _i9 = 0, _Array$from = Array.from(dom.window.document.querySelectorAll("".concat(tagName, "[").concat(attributeName, "*=\"?") + "".concat(configuration.hashAlgorithm, "=\"]"))); _i9 < _Array$from.length; _i9++) {
455
- 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) {
456
439
  /*
457
- NOTE: Removing symbols after a "&" in hash
458
- string is necessary to match the generated
459
- 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.
460
443
  */
461
- domNode.setAttribute(attributeName, domNode.getAttribute(attributeName).replace(new RegExp('(\\?' + "".concat(configuration.hashAlgorithm, "=") + '[^&]+).*$'), '$1'));
462
- }
463
- }
464
- /*
465
- NOTE: We have to restore template delimiter and style
466
- contents.
467
- */
468
- data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, function (match, startTag, endTag) {
469
- return "".concat(startTag).concat(styleContents.shift()) + endTag;
470
- });
471
- // region post compilation
472
- var _iterator7 = _createForOfIteratorHelper(configuration.files.html),
473
- _step7;
474
- try {
475
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
476
- var htmlFileSpecification = _step7.value;
477
- if (htmlFileSpecification.filename === data.plugin.options.filename) {
478
- var _iterator8 = _createForOfIteratorHelper([].concat(htmlFileSpecification.template.use)),
479
- _step8;
480
- try {
481
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
482
- var _loaderConfiguration$;
483
- var loaderConfiguration = _step8.value;
484
- if ((_loaderConfiguration$ = loaderConfiguration.options) !== null && _loaderConfiguration$ !== void 0 && _loaderConfiguration$.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = _ejsLoader["default"].bind({
485
- query: _clientnode["default"].extend(true, _clientnode["default"].copy(loaderConfiguration.options) || {}, htmlFileSpecification.template.postCompileOptions)
486
- })(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;
487
508
  }
488
- } catch (err) {
489
- _iterator8.e(err);
490
- } finally {
491
- _iterator8.f();
492
509
  }
493
- break;
510
+ // endregion
511
+ } catch (err) {
512
+ _iterator7.e(err);
513
+ } finally {
514
+ _iterator7.f();
494
515
  }
495
- }
496
- // endregion
497
- } catch (err) {
498
- _iterator7.e(err);
499
- } finally {
500
- _iterator7.f();
501
- }
502
- return data;
503
- });
504
- });
505
- }
506
- });
516
+ return data;
517
+ });
518
+ });
519
+ }
520
+ }]);
521
+ return HTMLTransformation;
522
+ }();
523
+ pluginInstances.push(new HTMLTransformation());
524
+ }
507
525
  //// endregion
508
526
  //// region context replacements
509
527
  var _iterator9 = _createForOfIteratorHelper(_module.replacements.context),
@@ -1076,7 +1094,7 @@ if (configuration.files.compose.cascadingStyleSheet && plugins.MiniCSSExtract) {
1076
1094
  So we inject live reload and hot module replacement manually.
1077
1095
  */
1078
1096
  if (htmlAvailable && configuration.debug && configuration.development.server.liveReload && !configuration.injection.entry.normalized.developmentHandler && ['serve', 'test:browser'].includes(configuration.givenCommandLineArguments[2])) {
1079
- configuration.injection.entry.normalized.developmentHandler = ['webpack-dev-server/client/index.js?live-reload=true&hot=' + "".concat(configuration.development.server.hot ? 'true' : 'false', "&http") + "".concat(configuration.development.server.https ? 's' : '', "://") + "".concat(configuration.development.server.host, ":") + "".concat(configuration.development.server.port)];
1097
+ configuration.injection.entry.normalized.developmentHandler = ['webpack-dev-server/client/index.js?' + 'live-reload=' + (configuration.development.server.liveReload ? 'true' : 'false') + "&hot=".concat(configuration.development.server.hot ? 'true' : 'false') + "&http".concat(configuration.development.server.https ? 's' : '', "://") + "".concat(configuration.development.server.host, ":") + "".concat(configuration.development.server.port)];
1080
1098
  if (configuration.development.server.hot) {
1081
1099
  configuration.injection.entry.normalized.developmentHandler.push('webpack/hot/dev-server.js');
1082
1100
  configuration.development.server.hot = false;
@@ -1153,7 +1171,7 @@ var webpackConfiguration = exports.webpackConfiguration = _clientnode["default"]
1153
1171
  mainFiles: configuration["package"].main.fileNames,
1154
1172
  modules: _helper["default"].normalizePaths(_module.directoryNames),
1155
1173
  symlinks: _module.resolveSymlinks,
1156
- unsafeCache: Boolean((_configuration$cache = configuration.cache) === null || _configuration$cache === void 0 ? void 0 : _configuration$cache.unsafe)
1174
+ unsafeCache: Boolean((_configuration$cache$ = (_configuration$cache = configuration.cache) === null || _configuration$cache === void 0 ? void 0 : _configuration$cache.unsafe) !== null && _configuration$cache$ !== void 0 ? _configuration$cache$ : (_configuration$cache2 = configuration.cache) === null || _configuration$cache2 === void 0 ? void 0 : _configuration$cache2.main)
1157
1175
  },
1158
1176
  resolveLoader: {
1159
1177
  alias: configuration.loader.aliases,
@@ -1229,7 +1247,7 @@ var webpackConfiguration = exports.webpackConfiguration = _clientnode["default"]
1229
1247
  }
1230
1248
  })),
1231
1249
  plugins: pluginInstances
1232
- }, (_configuration$cache2 = configuration.cache) !== null && _configuration$cache2 !== void 0 && _configuration$cache2.main ? {
1250
+ }, (_configuration$cache3 = configuration.cache) !== null && _configuration$cache3 !== void 0 && _configuration$cache3.main ? {
1233
1251
  cache: configuration.cache.main
1234
1252
  } : {}, configuration.webpack, customConfiguration);
1235
1253
  if (configuration.nodeENV !== null) webpackConfiguration.optimization.nodeEnv = configuration.nodeENV;