mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 10:58:14 +08:00
fix 前端打包取消 .map 文件,缩少发布包大小
This commit is contained in:
parent
42f7a4dd2b
commit
69aba47a33
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
1. 【server】优化 在线终端断开连接时提醒并支持重连
|
1. 【server】优化 在线终端断开连接时提醒并支持重连
|
||||||
2. 【server】修复 线程同步器,避免任务过多造成线程数不可控(节点分发相关功能)
|
2. 【server】修复 线程同步器,避免任务过多造成线程数不可控(节点分发相关功能)
|
||||||
|
3. 【server】优化 前端打包取消 .map 文件,缩少发布包大小
|
||||||
|
(感谢 [@金技](https://gitee.com/jinjiG) [Gitee issues I6AK0N](https://gitee.com/dromara/Jpom/issues/I6AK0N) )
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -21,31 +21,41 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.date.SystemClock;
|
import cn.hutool.core.date.SystemClock;
|
||||||
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.NioUtil;
|
||||||
import cn.hutool.core.io.unit.DataSize;
|
import cn.hutool.core.io.unit.DataSize;
|
||||||
|
import cn.hutool.core.util.HexUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.RuntimeUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||||
|
import cn.hutool.crypto.digest.Digester;
|
||||||
|
import io.jpom.util.FileUtils;
|
||||||
import io.jpom.util.StrictSyncFinisher;
|
import io.jpom.util.StrictSyncFinisher;
|
||||||
|
import lombok.Lombok;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.MappedByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.ArrayList;
|
import java.nio.file.Files;
|
||||||
import java.util.Collections;
|
import java.security.DigestOutputStream;
|
||||||
import java.util.List;
|
import java.security.MessageDigest;
|
||||||
import java.util.Queue;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://www.dandelioncloud.cn/article/details/1513013511700692994
|
* https://www.dandelioncloud.cn/article/details/1513013511700692994
|
||||||
|
* https://www.cnblogs.com/yjmyzz/p/how-to-split-a-large-file-into-small-files-fastly.html
|
||||||
*
|
*
|
||||||
* @author bwcx_jzy
|
* @author bwcx_jzy
|
||||||
* @since 2023/1/10
|
* @since 2023/1/10
|
||||||
@ -56,9 +66,16 @@ public class TestReadBigFile {
|
|||||||
|
|
||||||
private File file = new File("D:\\迅雷下载\\zh-cn_windows_11_business_editions_version_22h2_updated_sep_2022_x64_dvd_515a832b.iso");
|
private File file = new File("D:\\迅雷下载\\zh-cn_windows_11_business_editions_version_22h2_updated_sep_2022_x64_dvd_515a832b.iso");
|
||||||
|
|
||||||
|
private File partDir = new File("D:\\test\\part");
|
||||||
|
|
||||||
|
private File saveDir = new File("D:\\test\\");
|
||||||
|
|
||||||
|
private File testFile = new File("D:\\test\\zh-cn_windows_11_business_editions_version_22h2_updated_sep_2022_x64_dvd_515a832b.iso");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() throws IOException {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
FileUtil.del(partDir);
|
||||||
long length = file.length();
|
long length = file.length();
|
||||||
Assert.state(length > 0, "空文件不能上传");
|
Assert.state(length > 0, "空文件不能上传");
|
||||||
//如果小数点大于1,整数加一 例如4.1 =》5
|
//如果小数点大于1,整数加一 例如4.1 =》5
|
||||||
@ -96,12 +113,14 @@ public class TestReadBigFile {
|
|||||||
byte[] array = new byte[byteBuffer.remaining()];
|
byte[] array = new byte[byteBuffer.remaining()];
|
||||||
byteBuffer.get(array, 0, array.length);
|
byteBuffer.get(array, 0, array.length);
|
||||||
success.add(currentChunk);
|
success.add(currentChunk);
|
||||||
|
File partFile = FileUtil.file(partDir, file.getName() + "." + currentChunk);
|
||||||
|
FileUtil.mkParentDirs(partFile);
|
||||||
|
FileUtil.writeBytes(array, partFile);
|
||||||
long end = Math.min(length, ((success.size() - 1) * chunkSize) + chunkSize);
|
long end = Math.min(length, ((success.size() - 1) * chunkSize) + chunkSize);
|
||||||
// 保存线程安全顺序回调进度信息
|
// 保存线程安全顺序回调进度信息
|
||||||
atomicProgressSize.set(Math.max(end, atomicProgressSize.get()));
|
atomicProgressSize.set(Math.max(end, atomicProgressSize.get()));
|
||||||
long size = atomicProgressSize.get();
|
long size = atomicProgressSize.get();
|
||||||
int processorCount = RuntimeUtil.getProcessorCount();
|
log.info("{} {} {},读取文件 {} 内容花费:{}", total, fileSize, FileUtil.readableFileSize(size), NumberUtil.formatPercent(((double) size / length), 0), DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
log.info("{}-{} {} {},读取文件文件 {} 内容花费:{}", processorCount, total, fileSize, FileUtil.readableFileSize(size), NumberUtil.formatPercent(((double) size / length), 0), DateUtil.formatBetween(SystemClock.now() - start));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +135,144 @@ public class TestReadBigFile {
|
|||||||
}
|
}
|
||||||
syncFinisher.start();
|
syncFinisher.start();
|
||||||
}
|
}
|
||||||
log.info("读取文件文件内容花费:" + DateUtil.formatBetween(SystemClock.now() - start));
|
log.info("读取文件内容花费:" + DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMerge() throws IOException {
|
||||||
|
long start = SystemClock.now();
|
||||||
|
File[] files = partDir.listFiles();
|
||||||
|
|
||||||
|
long start2 = SystemClock.now();
|
||||||
|
String fileSumSha1 = SecureUtil.sha1(file);
|
||||||
|
log.info("解析文件耗时:{}", DateUtil.formatBetween(SystemClock.now() - start2));
|
||||||
|
assert files != null;
|
||||||
|
String name = files[0].getName();
|
||||||
|
name = StrUtil.subBefore(name, StrUtil.DOT, true);
|
||||||
|
File successFile = FileUtil.file(saveDir, name);
|
||||||
|
FileUtil.del(successFile);
|
||||||
|
try (FileOutputStream fileOutputStream = new FileOutputStream(successFile)) {
|
||||||
|
try (FileChannel channel = fileOutputStream.getChannel()) {
|
||||||
|
Arrays.stream(files).sorted((o1, o2) -> {
|
||||||
|
// 排序
|
||||||
|
Integer o1Int = Convert.toInt(FileUtil.extName(o1));
|
||||||
|
Integer o2Int = Convert.toInt(FileUtil.extName(o2));
|
||||||
|
return o1Int.compareTo(o2Int);
|
||||||
|
}).forEach(file12 -> {
|
||||||
|
try {
|
||||||
|
FileUtils.appendChannel(file12, channel);
|
||||||
|
log.info("合并 {} 文件花费:{}", file12.getName(), DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw Lombok.sneakyThrow(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 对比文件信息
|
||||||
|
start2 = SystemClock.now();
|
||||||
|
String newSha1 = SecureUtil.sha1(successFile);
|
||||||
|
log.info("解析文件耗时:{}", DateUtil.formatBetween(SystemClock.now() - start2));
|
||||||
|
Assert.state(StrUtil.equals(newSha1, fileSumSha1), () -> {
|
||||||
|
log.warn("文件合并异常 {}:{} -> {}", FileUtil.getAbsolutePath(successFile), newSha1, fileSumSha1);
|
||||||
|
return "文件合并后异常,文件不完成可能被损坏";
|
||||||
|
});
|
||||||
|
log.info("合并文件花费:" + DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMerge2() throws IOException {
|
||||||
|
long start = SystemClock.now();
|
||||||
|
File[] files = partDir.listFiles();
|
||||||
|
long start2 = SystemClock.now();
|
||||||
|
String fileSumSha1 = null;// SecureUtil.sha1(file);
|
||||||
|
log.info("解析文件耗时:{}", DateUtil.formatBetween(SystemClock.now() - start2));
|
||||||
|
assert files != null;
|
||||||
|
String name = files[0].getName();
|
||||||
|
name = StrUtil.subBefore(name, StrUtil.DOT, true);
|
||||||
|
File successFile = FileUtil.file(saveDir, name);
|
||||||
|
FileUtil.del(successFile);
|
||||||
|
Digester digester = SecureUtil.sha1();
|
||||||
|
try (OutputStream fileOutputStream = Files.newOutputStream(successFile.toPath())) {
|
||||||
|
|
||||||
|
try (DigestOutputStream digestOutputStream = new DigestOutputStream(fileOutputStream, digester.getDigest());) {
|
||||||
|
Arrays.stream(files).sorted((o1, o2) -> {
|
||||||
|
// 排序
|
||||||
|
Integer o1Int = Convert.toInt(FileUtil.extName(o1));
|
||||||
|
Integer o2Int = Convert.toInt(FileUtil.extName(o2));
|
||||||
|
return o1Int.compareTo(o2Int);
|
||||||
|
}).forEach(file12 -> {
|
||||||
|
try {
|
||||||
|
digestOutputStream.write(FileUtil.readBytes(file12));
|
||||||
|
log.info("合并 {} 文件花费:{}", file12.getName(), DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw Lombok.sneakyThrow(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 对比文件信息
|
||||||
|
start2 = SystemClock.now();
|
||||||
|
String newSha1 = HexUtil.encodeHexStr(digester.getDigest().digest());
|
||||||
|
//SecureUtil.sha1(successFile);
|
||||||
|
log.info("解析文件耗时:{}", DateUtil.formatBetween(SystemClock.now() - start2));
|
||||||
|
Assert.state(StrUtil.equals(newSha1, fileSumSha1), () -> {
|
||||||
|
log.warn("文件合并异常 {}:{} -> {}", FileUtil.getAbsolutePath(successFile), newSha1, fileSumSha1);
|
||||||
|
return "文件合并后异常,文件不完成可能被损坏";
|
||||||
|
});
|
||||||
|
log.info("合并文件花费:" + DateUtil.formatBetween(SystemClock.now() - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e0e4708889197545603b4631de1f4a90dbcb2435
|
||||||
|
*
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSha1() throws FileNotFoundException {
|
||||||
|
Digester digester = new Digester(DigestAlgorithm.SHA1);
|
||||||
|
String digestHex = digester.digestHex(new FileInputStream(file), NioUtil.DEFAULT_LARGE_BUFFER_SIZE);
|
||||||
|
System.out.println(digestHex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSha1_2() throws IOException, NoSuchAlgorithmException {
|
||||||
|
// Digester digester = new Digester(DigestAlgorithm.SHA1);
|
||||||
|
MessageDigest messagedigest = MessageDigest.getInstance("SHA-1");
|
||||||
|
FileInputStream in = new FileInputStream(file);
|
||||||
|
|
||||||
|
FileChannel ch = in.getChannel();
|
||||||
|
|
||||||
|
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
|
||||||
|
|
||||||
|
messagedigest.update(byteBuffer);
|
||||||
|
|
||||||
|
String hexStr = HexUtil.encodeHexStr(messagedigest.digest());
|
||||||
|
|
||||||
|
System.out.println(hexStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSha1_3() throws IOException {
|
||||||
|
String sha1 = SecureUtil.sha1(testFile);
|
||||||
|
System.out.println(sha1);
|
||||||
|
Digester digester = SecureUtil.sha1();
|
||||||
|
OutputStream is = Files.newOutputStream(testFile.toPath());
|
||||||
|
DigestOutputStream di = new DigestOutputStream(is, digester.getDigest());
|
||||||
|
MessageDigest messageDigest = di.getMessageDigest();
|
||||||
|
System.out.println(HexUtil.encodeHexStr(messageDigest.digest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compared_md5_sha1() {
|
||||||
|
TimeInterval timeInterval = new TimeInterval();
|
||||||
|
//
|
||||||
|
timeInterval.start("md5");
|
||||||
|
System.out.println(SecureUtil.md5(file));
|
||||||
|
System.out.println(timeInterval.intervalPretty("md5"));
|
||||||
|
//
|
||||||
|
timeInterval.start("sha1");
|
||||||
|
System.out.println(SecureUtil.sha1(file));
|
||||||
|
System.out.println(timeInterval.intervalPretty("sha1"));
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
//打包后是否让每个js文件都生成一个.map文件?true代表生成,false代表不生成。
|
||||||
|
productionSourceMap: false,
|
||||||
configureWebpack: {
|
configureWebpack: {
|
||||||
// name: name,
|
// name: name,
|
||||||
// 修改打包后的js文件名称
|
// 修改打包后的js文件名称
|
||||||
|
Loading…
Reference in New Issue
Block a user