Răsfoiți Sursa

HUE-9420 [ui] Limit webpack chunk name length

Johan Ahlen 5 ani în urmă
părinte
comite
8ede4cd9e9

+ 21 - 1
desktop/core/src/desktop/js/webpack/configUtils.js

@@ -57,7 +57,27 @@ const getPluginConfig = (name, withAnalyzer) => {
   return plugins;
 };
 
+const hashCode = str => {
+  let hash = 0;
+  for (let i = 0; i < str.length; i++) {
+    const chr = str.charCodeAt(i);
+    hash = (hash << 5) - hash + chr;
+    hash |= 0;
+  }
+  return hash;
+};
+
+const splitChunksName = (module, chunks, cacheGroupKey) => {
+  let fullName = cacheGroupKey !== 'default' ? cacheGroupKey + '~' : '';
+  fullName += chunks.map(item => item.name).join('~');
+  if (fullName.length > 80) {
+    return fullName.slice(0, 70).replace(/~[^~]*$/, '') + '~' + hashCode(fullName);
+  }
+  return fullName;
+};
+
 module.exports = {
   BUNDLES: BUNDLES,
-  getPluginConfig: getPluginConfig
+  getPluginConfig: getPluginConfig,
+  splitChunksName: splitChunksName
 };

+ 7 - 2
webpack.config.js

@@ -14,7 +14,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-const { BUNDLES, getPluginConfig } = require('./desktop/core/src/desktop/js/webpack/configUtils');
+const {
+  BUNDLES,
+  getPluginConfig,
+  splitChunksName
+} = require('./desktop/core/src/desktop/js/webpack/configUtils');
 
 module.exports = {
   devtool: false,
@@ -59,7 +63,8 @@ module.exports = {
     //minimize: true,
     minimize: false,
     splitChunks: {
-      chunks: 'all'
+      chunks: 'all',
+      name: splitChunksName
     },
     runtimeChunk: {
       name: 'hue'

+ 8 - 2
webpack.config.login.js

@@ -14,7 +14,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-const { BUNDLES, getPluginConfig } = require('./desktop/core/src/desktop/js/webpack/configUtils');
+const {
+  BUNDLES,
+  getPluginConfig,
+  splitChunksName
+} = require('./desktop/core/src/desktop/js/webpack/configUtils');
 const shared = require('./webpack.config');
 
 module.exports = {
@@ -27,7 +31,9 @@ module.exports = {
   performance: shared.performance,
   optimization: {
     minimize: true,
-    splitChunks: {}
+    splitChunks: {
+      name: splitChunksName
+    }
   },
   output: {
     path: __dirname + '/desktop/core/src/desktop/static/desktop/js/bundles/login',

+ 8 - 2
webpack.config.workers.js

@@ -14,7 +14,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-const { BUNDLES, getPluginConfig } = require('./desktop/core/src/desktop/js/webpack/configUtils');
+const {
+  BUNDLES,
+  getPluginConfig,
+  splitChunksName
+} = require('./desktop/core/src/desktop/js/webpack/configUtils');
 const shared = require('./webpack.config');
 
 module.exports = {
@@ -29,7 +33,9 @@ module.exports = {
   },
   optimization: {
     minimize: false,
-    splitChunks: {}
+    splitChunks: {
+      name: splitChunksName
+    }
   },
   output: {
     path: __dirname + '/desktop/core/src/desktop/static/desktop/js/bundles/workers',