weboptimizer 4.0.46 → 4.0.48

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.46",
3
+ "version": "4.0.48",
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.1480",
97
+ "clientnode": "4.0.1481",
98
98
  "core-js": "^3.49.0",
99
99
  "ejs": "^6.0.1",
100
100
  "exports-loader": "^5.0.0",
@@ -779,19 +779,29 @@ if (configuration.path.configuration.json) try {
779
779
  treats (and, when async, awaits) as a whole. Re-exporting via "export *"
780
780
  preserves the (named) exports of all bundled modules while guaranteeing
781
781
  each one is evaluated in the given order.
782
+
783
+ NOTE: The barrel and every module it bundles are additionally forced to
784
+ "sideEffects: true" (see the corresponding module rule below). Otherwise a
785
+ consuming package declaring "sideEffects": false (e.g. a test bundle whose
786
+ exports are never imported) would have its bundled modules tree-shaken away
787
+ completely - resulting for example in a test bundle without any registered
788
+ test.
782
789
  */
783
790
  const generatedBarrelModuleFilePaths = [];
791
+ const barrelledModuleFilePaths = [];
784
792
  const normalizedEntryInjection = {};
785
- for (const [chunkName, moduleIDs] of Object.entries(configuration.injection.entry.normalized)) if (Array.isArray(moduleIDs) && moduleIDs.length > 1) {
793
+ for (const [chunkName, moduleIDs] of Object.entries(configuration.injection.entry.normalized)) if (configuration.givenCommandLineArguments[2] === 'test' && Array.isArray(moduleIDs) && moduleIDs.length > 1) {
786
794
  const barrelModuleFilePath = resolve(configuration.path.context, `.__${convertToValidVariableName(chunkName)}__.barrel.mjs`);
787
795
  await writeFile(barrelModuleFilePath, moduleIDs.map(moduleID => {
788
796
  const specifier = stripLoader(moduleID);
789
- return `export * from ${JSON.stringify(specifier.startsWith('.') || specifier.startsWith('/') ? specifier : `./${specifier}`)}`;
797
+ const relativeOrAbsoluteSpecifier = specifier.startsWith('.') || specifier.startsWith('/') ? specifier : `./${specifier}`;
798
+ barrelledModuleFilePaths.push(resolve(configuration.path.context, relativeOrAbsoluteSpecifier));
799
+ return `export * from ${JSON.stringify(relativeOrAbsoluteSpecifier)}`;
790
800
  }).join('\n') + '\n', {
791
801
  encoding: configuration.encoding
792
802
  });
793
803
  generatedBarrelModuleFilePaths.push(barrelModuleFilePath);
794
- normalizedEntryInjection[chunkName] = [`./${relative(configuration.path.context, barrelModuleFilePath)}`];
804
+ normalizedEntryInjection[chunkName] = [barrelModuleFilePath];
795
805
  } else normalizedEntryInjection[chunkName] = moduleIDs;
796
806
  if (generatedBarrelModuleFilePaths.length) pluginInstances.push({
797
807
  apply: compiler => {
@@ -898,7 +908,17 @@ export let webpackConfiguration = extend(true, {
898
908
  // endregion
899
909
  mode: configuration.debug ? 'development' : 'production',
900
910
  module: {
901
- rules: module.additional.pre.map(evaluateAdditionalLoaderConfiguration).concat(loader.ejs, loader.script, loader.html.main, loader.html.ejs, loader.html.html, loader.style, loader.font.eot, loader.font.svg, loader.font.ttf, loader.font.woff, loader.image, loader.data, module.additional.post.map(evaluateAdditionalLoaderConfiguration))
911
+ rules:
912
+ /*
913
+ Force the generated barrel entry modules and every module
914
+ they bundle to be treated as side-effectful so a consuming
915
+ package declaring "sideEffects": false does not get them
916
+ tree-shaken away (which would empty e.g. a test bundle).
917
+ */
918
+ (generatedBarrelModuleFilePaths.length ? [{
919
+ include: generatedBarrelModuleFilePaths.concat(barrelledModuleFilePaths),
920
+ sideEffects: true
921
+ }] : []).concat(module.additional.pre.map(evaluateAdditionalLoaderConfiguration)).concat(loader.ejs, loader.script, loader.html.main, loader.html.ejs, loader.html.html, loader.style, loader.font.eot, loader.font.svg, loader.font.ttf, loader.font.woff, loader.image, loader.data, module.additional.post.map(evaluateAdditionalLoaderConfiguration))
902
922
  },
903
923
  node: configuration.nodeEnvironment,
904
924
  optimization: {