Skip to content

Commit 66dc4fd

Browse files
committed
LPD-52709 Hashify loader.js so that it can be infinitely cached
1 parent eb7d5ad commit 66dc4fd

File tree

1 file changed

+29
-2
lines changed
  • modules/apps/frontend-js/frontend-js-loader-modules-extender

1 file changed

+29
-2
lines changed

modules/apps/frontend-js/frontend-js-loader-modules-extender/build.gradle

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
import com.liferay.gradle.util.copy.StripPathSegmentsAction
1+
import com.liferay.gradle.util.hash.HashUtil
2+
3+
import org.gradle.api.file.RelativePath
24

35
task buildLiferayAMDLoader(type: Copy)
46

57
File jsDestinationDir = file("tmp/META-INF/resources")
68

79
buildLiferayAMDLoader {
810
dependsOn npmInstall
9-
eachFile new StripPathSegmentsAction(4)
1011
from npmInstall.nodeModulesDir
1112

1213
include "@liferay/amd-loader/build/loader/loader.js.map"
1314
include "@liferay/amd-loader/build/loader/loader.js"
1415

1516
includeEmptyDirs = false
1617
into jsDestinationDir
18+
19+
eachFile {
20+
details ->
21+
22+
def sourcePath = details.sourcePath
23+
24+
if (sourcePath.endsWith(".map")) {
25+
sourcePath = sourcePath[0..-5]
26+
}
27+
28+
def md5 = HashUtil.md5(
29+
new File("${npmInstall.nodeModulesDir}/${sourcePath}"))
30+
31+
def hash = md5.asCompactString()[0..11]
32+
33+
def segments = details.relativePath.segments
34+
35+
def fileName = segments[-1]
36+
37+
def i = fileName.indexOf(".")
38+
39+
segments[-1] = "${fileName[0..i]}(${hash})${fileName[i..-1]}"
40+
41+
details.relativePath = new RelativePath(
42+
true, segments[4..-1].toArray(new String[]{}))
43+
}
1744
}
1845

1946
classes {

0 commit comments

Comments
 (0)