weboptimizer 4.0.36 → 4.0.37

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": "4.0.36",
3
+ "version": "4.0.37",
4
4
  "description": "A generic web optimizer, (module) bundler and development environment.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -94,7 +94,7 @@
94
94
  "babel-loader": "^10.1.1",
95
95
  "babel-plugin-polyfill-corejs3": "^1.0.0",
96
96
  "babel-plugin-transform-rewrite-imports": "^1.5.4",
97
- "clientnode": "4.0.1467",
97
+ "clientnode": "4.0.1469",
98
98
  "core-js": "^3.49.0",
99
99
  "ejs": "^6.0.1",
100
100
  "exports-loader": "^5.0.0",
package/type.d.ts CHANGED
@@ -403,7 +403,8 @@ export interface WebpackConfiguration extends BaseWebpackConfiguration {
403
403
  devServer: Mapping<unknown>;
404
404
  replaceWebOptimizer: WebpackConfiguration;
405
405
  }
406
- export type RuleSet = Array<WebpackRuleSetUseItem>;
406
+ export type RuleSetItem = WebpackRuleSetUseItem;
407
+ export type RuleSet = Array<RuleSetItem>;
407
408
  export type RuleSetRule = WebpackRuleSetRule & {
408
409
  use: RuleSet;
409
410
  };
@@ -364,7 +364,7 @@ const scope = {
364
364
  isFilePathInDependencies,
365
365
  loader
366
366
  };
367
- const evaluateAndThrow = (object, givenOptions = {}) => {
367
+ const evaluateOrThrowOnError = (object, givenOptions = {}) => {
368
368
  const options = {
369
369
  filePath: configuration.path.context,
370
370
  ...givenOptions
@@ -380,23 +380,23 @@ const evaluateAndThrow = (object, givenOptions = {}) => {
380
380
  }
381
381
  return object;
382
382
  };
383
- const createEvaluateMapper = type => value => evaluateAndThrow(value, {
383
+ const createEvaluateMapper = type => value => evaluateOrThrowOnError(value, {
384
384
  type
385
385
  });
386
386
  const evaluateAdditionalLoaderConfiguration = loaderConfiguration => ({
387
- exclude: filePath => evaluateAndThrow(loaderConfiguration.exclude, {
387
+ exclude: filePath => evaluateOrThrowOnError(loaderConfiguration.exclude, {
388
388
  filePath
389
389
  }),
390
- include: loaderConfiguration.include && evaluateAndThrow(loaderConfiguration.include) || configuration.path.source.base,
391
- test: new RegExp(evaluateAndThrow(loaderConfiguration.test)),
392
- use: evaluateAndThrow(loaderConfiguration.use)
390
+ include: loaderConfiguration.include && evaluateOrThrowOnError(loaderConfiguration.include) || configuration.path.source.base,
391
+ test: new RegExp(evaluateOrThrowOnError(loaderConfiguration.test)),
392
+ use: evaluateOrThrowOnError(loaderConfiguration.use)
393
393
  });
394
394
  const getIncludingPaths = path => normalizePaths([path].concat(module.locations.directoryPaths));
395
395
  const postCSSResolver = (name, _context) => {
396
396
  for (const [source, target] of Object.entries(configuration.module.aliases)) if (source.startsWith(name)) return target;
397
397
  return name;
398
398
  };
399
- const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(createEvaluateMapper('css')).concat({
399
+ const cssUse = (await Promise.all(module.preprocessor.cascadingStyleSheet.additional.pre.map(createEvaluateMapper('css')))).concat({
400
400
  loader: module.style.loader,
401
401
  options: module.style.options || {}
402
402
  }, {
@@ -414,7 +414,7 @@ const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(create
414
414
  plugins: [].concat(postcssImport ? postcssImport({
415
415
  root: configuration.path.context,
416
416
  resolve: postCSSResolver
417
- }) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.pre.map(createEvaluateMapper('css.postcss')),
417
+ }) : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.plugins.pre.map(createEvaluateMapper('css.postcss'))),
418
418
  /*
419
419
  NOTE: Checking path doesn't work if fonts
420
420
  are referenced in libraries provided in
@@ -454,37 +454,37 @@ const cssUse = module.preprocessor.cascadingStyleSheet.additional.pre.map(create
454
454
  stylesheetPath: configuration.path.source.asset.cascadingStyleSheet,
455
455
  spritePath: configuration.path.source.asset.image,
456
456
  ...configuration.imageSprite
457
- }) : [], module.preprocessor.cascadingStyleSheet.additional.plugins.post.map(createEvaluateMapper('css.postcss')), module.optimizer.cssnano && postcssCSSnano ? postcssCSSnano(module.optimizer.cssnano) : [])
457
+ }) : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.plugins.post.map(createEvaluateMapper('css.postcss'))), module.optimizer.cssnano && postcssCSSnano ? postcssCSSnano(module.optimizer.cssnano) : [])
458
458
  }
459
459
  } : {}, module.preprocessor.cascadingStyleSheet.options || {})
460
- } : [], module.preprocessor.cascadingStyleSheet.additional.post.map(createEvaluateMapper('css')));
460
+ } : [], await Promise.all(module.preprocessor.cascadingStyleSheet.additional.post.map(createEvaluateMapper('css'))));
461
461
  const genericLoader = {
462
462
  // Convert to compatible native web types.
463
463
  // region generic template
464
464
  ejs: {
465
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || module.preprocessor.ejs.exclude === null ? false : evaluateAndThrow(module.preprocessor.ejs.exclude, {
465
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || module.preprocessor.ejs.exclude === null ? false : evaluateOrThrowOnError(module.preprocessor.ejs.exclude, {
466
466
  filePath
467
467
  }),
468
468
  include: getIncludingPaths(configuration.path.source.asset.template),
469
469
  test: /^(?!.+\.html\.ejs$).+\.ejs$/i,
470
- use: module.preprocessor.ejs.additional.pre.map(createEvaluateMapper('ejs')).concat({
470
+ use: (await Promise.all(module.preprocessor.ejs.additional.pre.map(createEvaluateMapper('ejs')))).concat({
471
471
  loader: module.preprocessor.ejs.loader,
472
472
  options: extend(true, module.preprocessor.ejs.options || {}, {
473
473
  compress: {
474
474
  html: false
475
475
  }
476
476
  })
477
- }, module.preprocessor.ejs.additional.post.map(createEvaluateMapper('ejs')))
477
+ }, await Promise.all(module.preprocessor.ejs.additional.post.map(createEvaluateMapper('ejs'))))
478
478
  },
479
479
  // endregion
480
480
  // region script
481
481
  script: {
482
- exclude: filePath => evaluateAndThrow(module.preprocessor.javaScript.exclude, {
482
+ exclude: filePath => evaluateOrThrowOnError(module.preprocessor.javaScript.exclude, {
483
483
  filePath,
484
484
  type: 'script'
485
485
  }),
486
486
  include: filePath => {
487
- const result = evaluateAndThrow(module.preprocessor.javaScript.include, {
487
+ const result = evaluateOrThrowOnError(module.preprocessor.javaScript.include, {
488
488
  filePath,
489
489
  type: 'script'
490
490
  });
@@ -495,10 +495,10 @@ const genericLoader = {
495
495
  return Boolean(result);
496
496
  },
497
497
  test: new RegExp(module.preprocessor.javaScript.regularExpression, 'i'),
498
- use: module.preprocessor.javaScript.additional.pre.map(createEvaluateMapper('script')).concat({
498
+ use: (await Promise.all(module.preprocessor.javaScript.additional.pre.map(createEvaluateMapper('script')))).concat({
499
499
  loader: module.preprocessor.javaScript.loader,
500
500
  options: module.preprocessor.javaScript.options || {}
501
- }, module.preprocessor.javaScript.additional.post.map(createEvaluateMapper('script')))
501
+ }, await Promise.all(module.preprocessor.javaScript.additional.post.map(createEvaluateMapper('script'))))
502
502
  },
503
503
  // endregion
504
504
  // region HTML template
@@ -509,16 +509,16 @@ const genericLoader = {
509
509
  use: configuration.files.defaultHTML.template.use
510
510
  },
511
511
  ejs: {
512
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.preprocessor.html.exclude === null ? false : evaluateAndThrow(module.preprocessor.html.exclude, {
512
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.preprocessor.html.exclude === null ? false : evaluateOrThrowOnError(module.preprocessor.html.exclude, {
513
513
  filePath,
514
514
  type: 'html.ejs'
515
515
  })),
516
516
  include: configuration.path.source.asset.template,
517
517
  test: /\.html\.ejs(?:\?.*)?$/i,
518
- use: module.preprocessor.html.additional.pre.map(createEvaluateMapper('html.ejs')).concat(
518
+ use: (await Promise.all(module.preprocessor.html.additional.pre.map(createEvaluateMapper('html.ejs')))).concat(
519
519
  /*
520
520
  We might need to evaluate ejs before we are able to
521
- parse html beforhand. If not we parse it as html
521
+ parse html beforehand. If not we parse it as html
522
522
  directly.
523
523
  */
524
524
 
@@ -532,35 +532,35 @@ const genericLoader = {
532
532
  }], {
533
533
  loader: module.preprocessor.html.loader,
534
534
  options: module.preprocessor.html.options || {}
535
- }, module.preprocessor.html.additional.post.map(createEvaluateMapper('html.ejs')))
535
+ }, await Promise.all(module.preprocessor.html.additional.post.map(createEvaluateMapper('html.ejs'))))
536
536
  },
537
537
  html: {
538
- exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.html.exclude === null ? true : evaluateAndThrow(module.html.exclude, {
538
+ exclude: filePath => normalizePaths(configuration.files.html.concat(configuration.files.defaultHTML).map(htmlConfiguration => htmlConfiguration.template.filePath)).includes(filePath) || (module.html.exclude === null ? true : evaluateOrThrowOnError(module.html.exclude, {
539
539
  filePath,
540
540
  type: 'html'
541
541
  })),
542
542
  include: configuration.path.source.asset.template,
543
543
  test: /\.html(?:\?.*)?$/i,
544
- use: module.html.additional.pre.map(createEvaluateMapper('html')).concat({
544
+ use: (await Promise.all(module.html.additional.pre.map(createEvaluateMapper('html')))).concat({
545
545
  loader: 'file?name=' + join(relative(configuration.path.target.base, configuration.path.target.asset.template), `[name][ext]?${configuration.hashAlgorithm}=` + '[contenthash]')
546
546
  }, {
547
547
  loader: 'extract'
548
548
  }, {
549
549
  loader: module.html.loader,
550
550
  options: module.html.options || {}
551
- }, module.html.additional.post.map(createEvaluateMapper('html')))
551
+ }, await Promise.all(module.html.additional.post.map(createEvaluateMapper('html'))))
552
552
  }
553
553
  },
554
554
  // endregion
555
555
  // Load dependencies.
556
556
  // region style
557
557
  style: {
558
- exclude: filePath => module.cascadingStyleSheet.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.cascadingStyleSheet.exclude, {
558
+ exclude: filePath => module.cascadingStyleSheet.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.cascadingStyleSheet.exclude, {
559
559
  filePath,
560
560
  type: 'style'
561
561
  }),
562
562
  include: filePath => {
563
- const result = evaluateAndThrow(module.cascadingStyleSheet.include, {
563
+ const result = evaluateOrThrowOnError(module.cascadingStyleSheet.include, {
564
564
  filePath,
565
565
  type: 'style'
566
566
  });
@@ -578,7 +578,7 @@ const genericLoader = {
578
578
  // region font
579
579
  font: {
580
580
  eot: {
581
- exclude: filePath => module.optimizer.font.eot.exclude === null ? false : evaluateAndThrow(module.optimizer.font.eot.exclude, {
581
+ exclude: filePath => module.optimizer.font.eot.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.eot.exclude, {
582
582
  filePath,
583
583
  type: 'font.eot'
584
584
  }),
@@ -592,10 +592,10 @@ const genericLoader = {
592
592
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
593
593
  }
594
594
  },
595
- use: module.optimizer.font.eot.loader.map(createEvaluateMapper('font.eot'))
595
+ use: await Promise.all(module.optimizer.font.eot.loader.map(createEvaluateMapper('font.eot')))
596
596
  },
597
597
  svg: {
598
- exclude: filePath => module.optimizer.font.svg.exclude === null ? false : evaluateAndThrow(module.optimizer.font.svg.exclude, {
598
+ exclude: filePath => module.optimizer.font.svg.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.svg.exclude, {
599
599
  filePath,
600
600
  type: 'svg'
601
601
  }),
@@ -611,10 +611,10 @@ const genericLoader = {
611
611
  },
612
612
  test: /\.svg(?: \?.*)?$/i,
613
613
  type: 'asset/resource',
614
- use: module.optimizer.font.svg.loader.map(createEvaluateMapper('font.svg'))
614
+ use: await Promise.all(module.optimizer.font.svg.loader.map(createEvaluateMapper('font.svg')))
615
615
  },
616
616
  ttf: {
617
- exclude: filePath => module.optimizer.font.ttf.exclude === null ? false : evaluateAndThrow(module.optimizer.font.ttf.exclude, {
617
+ exclude: filePath => module.optimizer.font.ttf.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.ttf.exclude, {
618
618
  filePath,
619
619
  type: 'ttf'
620
620
  }),
@@ -629,10 +629,10 @@ const genericLoader = {
629
629
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
630
630
  }
631
631
  },
632
- use: module.optimizer.font.ttf.loader.map(createEvaluateMapper('font.ttf'))
632
+ use: await Promise.all(module.optimizer.font.ttf.loader.map(createEvaluateMapper('font.ttf')))
633
633
  },
634
634
  woff: {
635
- exclude: filePath => module.optimizer.font.woff.exclude === null ? false : evaluateAndThrow(module.optimizer.font.woff.exclude, {
635
+ exclude: filePath => module.optimizer.font.woff.exclude === null ? false : evaluateOrThrowOnError(module.optimizer.font.woff.exclude, {
636
636
  filePath,
637
637
  type: 'woff'
638
638
  }),
@@ -646,13 +646,13 @@ const genericLoader = {
646
646
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
647
647
  }
648
648
  },
649
- use: module.optimizer.font.woff.loader.map(createEvaluateMapper('font.woff'))
649
+ use: await Promise.all(module.optimizer.font.woff.loader.map(createEvaluateMapper('font.woff')))
650
650
  }
651
651
  },
652
652
  // endregion
653
653
  // region image
654
654
  image: {
655
- exclude: filePath => module.optimizer.image.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.optimizer.image.exclude, {
655
+ exclude: filePath => module.optimizer.image.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.optimizer.image.exclude, {
656
656
  filePath,
657
657
  type: 'image'
658
658
  }),
@@ -667,14 +667,14 @@ const genericLoader = {
667
667
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
668
668
  }
669
669
  },
670
- use: module.optimizer.image.loader.map(createEvaluateMapper('image'))
670
+ use: await Promise.all(module.optimizer.image.loader.map(createEvaluateMapper('image')))
671
671
  },
672
672
  // endregion
673
673
  // region data
674
674
  data: {
675
675
  exclude: filePath => {
676
676
  if (typeof filePath !== 'string') return false;
677
- return configuration.extensions.file.internal.includes(extname(stripLoader(filePath))) || (module.optimizer.data.exclude === null ? isFilePathInDependencies(filePath) : evaluateAndThrow(module.optimizer.data.exclude, {
677
+ return configuration.extensions.file.internal.includes(extname(stripLoader(filePath))) || (module.optimizer.data.exclude === null ? isFilePathInDependencies(filePath) : evaluateOrThrowOnError(module.optimizer.data.exclude, {
678
678
  filePath,
679
679
  type: 'data'
680
680
  }));
@@ -689,7 +689,7 @@ const genericLoader = {
689
689
  maxSize: configuration.inPlace.otherMaximumFileSizeLimitInByte
690
690
  }
691
691
  },
692
- use: module.optimizer.data.loader.map(createEvaluateMapper('data'))
692
+ use: await Promise.all(module.optimizer.data.loader.map(createEvaluateMapper('data')))
693
693
  }
694
694
  // endregion
695
695
  };