enonic / lib-react4xp

React for XP: handling and rendering of pre-built React components in Enonic XP
Apache License 2.0
2 stars 2 forks source link

WP5: how to content-hash chunks but not entries? #240

Closed espen42 closed 3 years ago

espen42 commented 3 years ago

Looking for a workaround for this webpack5 bug, specifically how to get chunkFilename to work as before with [contenthash:9] or at least [contenthash]. Or some other way to name the built chunks uniquely and content-dependently, without also hashing the entries (which in turn would cause jsxPaths to be unpredictable and harder to handle).

Example from webpack config for the build-components step:

...,
output": {
    ...,
    "filename": "[name].js",
    "chunkFilename": "[name].[contenthash].js",
    "libraryTarget": "var",
    "library": [
      "React4xp",
      "[name]"
    ]
  },
...

In addition to weakening the automatic cache(busting) behaviour, this presents a problem if there is an entry in one of the entryDirs with the same name (without extension, and case-insensitive) as a chunkDir, for example the entry src/main/resources/react4xp//Movie.js while at the same time src/main/resources/react4xp/movie is a chunkDir. Builds if there's no such name collision, but should be fixed anyway.

espen42 commented 3 years ago

Replace filename and chunkFilename with a function:

      filename: (pathdata) => ((pathdata.chunk || {}).chunkReason) ? chunkFileName : "[name].js",