Browse Source

优化打包、编译速度

TDesign-Vue-Next-1.20.6
wanghanlin 3 weeks ago
parent
commit
ba933825d4
  1. 1
      .gitignore
  2. 1
      client/dist/chatbot-sdk.js
  3. 1
      client/dist/chatbot-sdk.js.map
  4. 1
      client/dist/chatbot-sdk.min.js
  5. 1
      client/dist/chatbot-sdk.min.js.map
  6. 3
      client/package.json
  7. 9
      client/rollup.config.js
  8. 3
      frontend/vite.config.ts
  9. 107
      pom.xml
  10. 7
      src/main/resources/static/sdk/chatbot-sdk.js
  11. 1
      src/main/resources/static/sdk/chatbot-sdk.js.map
  12. 1
      src/main/resources/static/sdk/chatbot-sdk.min.js
  13. 1
      src/main/resources/static/sdk/chatbot-sdk.min.js.map

1
.gitignore

@ -40,6 +40,7 @@ build/
/frontend/node_modules/ /frontend/node_modules/
/frontend/node/ /frontend/node/
/frontend/dist/ /frontend/dist/
/node/ # Maven frontend-maven-plugin 在根目录安装的共享 Node.js
/.claude/ /.claude/
/src/main/resources/static/assets/ /src/main/resources/static/assets/
/src/main/resources/static/index.html /src/main/resources/static/index.html

1
client/dist/chatbot-sdk.js

@ -5325,4 +5325,3 @@ var ChatbotSDK = (function () {
return ChatbotSDK; return ChatbotSDK;
})(); })();
//# sourceMappingURL=chatbot-sdk.js.map

1
client/dist/chatbot-sdk.js.map
File diff suppressed because it is too large
View File

1
client/dist/chatbot-sdk.min.js
File diff suppressed because it is too large
View File

1
client/dist/chatbot-sdk.min.js.map
File diff suppressed because it is too large
View File

3
client/package.json

@ -6,8 +6,9 @@
"types": "dist/types/index.d.ts", "types": "dist/types/index.d.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "rollup -c && npm run build:types",
"build": "rollup -c",
"build:types": "tsc --emitDeclarationOnly --outDir dist/types", "build:types": "tsc --emitDeclarationOnly --outDir dist/types",
"build:full": "rollup -c && npm run build:types",
"dev": "rollup -c -w", "dev": "rollup -c -w",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest" "test:watch": "vitest"

9
client/rollup.config.js

@ -9,16 +9,19 @@ export default {
file: 'dist/chatbot-sdk.js', file: 'dist/chatbot-sdk.js',
format: 'iife', format: 'iife',
name: 'ChatbotSDK', name: 'ChatbotSDK',
sourcemap: true,
// 生产构建不需要 sourcemap,开发模式用 npm run dev 单独生成
sourcemap: false,
}, },
{ {
file: 'dist/chatbot-sdk.min.js', file: 'dist/chatbot-sdk.min.js',
format: 'iife', format: 'iife',
name: 'ChatbotSDK', name: 'ChatbotSDK',
sourcemap: true,
// 生产环境不需要 sourcemap,加速构建
sourcemap: false,
plugins: [terser()], plugins: [terser()],
}, },
], ],
// 全局关闭 sourcemap 生成开关后,压缩版 output.sourcemap=false 才不会触发插件警告
plugins: [ plugins: [
image(), image(),
typescript({ typescript({
@ -26,6 +29,8 @@ export default {
// Rollup 构建不生成 .d.ts,由独立的 tsc --emitDeclarationOnly 负责 // Rollup 构建不生成 .d.ts,由独立的 tsc --emitDeclarationOnly 负责
declaration: false, declaration: false,
declarationDir: undefined, declarationDir: undefined,
// 生产构建不生成 sourcemap,避免插件警告并加速
sourceMap: false,
}), }),
], ],
}; };

3
frontend/vite.config.ts

@ -35,6 +35,9 @@ export default defineConfig({
build: { build: {
outDir: 'dist', outDir: 'dist',
assetsDir: 'assets', assetsDir: 'assets',
sourcemap: false, // 生产环境不需要 sourcemap,加速构建
minify: 'esbuild', // esbuild 比 terser 快 20-40 倍
reportCompressedSize: false, // 跳过压缩体积报告,省 1~3s
rollupOptions: { rollupOptions: {
output: { output: {
// 拆出独立 chunk,浏览器可长期缓存 // 拆出独立 chunk,浏览器可长期缓存

107
pom.xml

@ -243,8 +243,8 @@
</configuration> </configuration>
</plugin> </plugin>
<!-- ==================== 前端 SDK 构建(client/ → static/sdk/) ==================== -->
<!-- 使用 frontend-maven-plugin 自动安装 Node.js 并编译前端 SDK -->
<!-- ==================== 前端构建 ==================== -->
<!-- 在项目根目录安装 Node.js(仅首次),然后通过 build-all.mjs 并行编译 client + frontend -->
<!-- 统一绑定到 prepare-package 阶段,mvn compile 不触发,mvn package/install 才构建 --> <!-- 统一绑定到 prepare-package 阶段,mvn compile 不触发,mvn package/install 才构建 -->
<!-- 跳过前端构建:mvn package -Dskip.frontend=true --> <!-- 跳过前端构建:mvn package -Dskip.frontend=true -->
<plugin> <plugin>
@ -252,11 +252,11 @@
<artifactId>frontend-maven-plugin</artifactId> <artifactId>frontend-maven-plugin</artifactId>
<version>1.15.1</version> <version>1.15.1</version>
<configuration> <configuration>
<workingDirectory>client</workingDirectory>
<workingDirectory>${project.basedir}</workingDirectory>
<skip>${skip.frontend}</skip> <skip>${skip.frontend}</skip>
</configuration> </configuration>
<executions> <executions>
<!-- 第一步:安装 Node.js(仅首次,后续复用 node_modules 缓存) -->
<!-- 安装 Node.js(仅首次下载,后续复用缓存) -->
<execution> <execution>
<id>install-node-and-npm</id> <id>install-node-and-npm</id>
<phase>prepare-package</phase> <phase>prepare-package</phase>
@ -267,32 +267,34 @@
<nodeVersion>v20.18.0</nodeVersion> <nodeVersion>v20.18.0</nodeVersion>
</configuration> </configuration>
</execution> </execution>
<!-- 第二步:npm install 安装依赖 -->
<execution>
<id>npm-install</id>
<phase>prepare-package</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- 第三步:npm run build 编译 SDK -->
</executions>
</plugin>
<!-- 调用 build-all.mjs 并行执行 client + frontend 的 npm install 和 build -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution> <execution>
<id>npm-build</id>
<id>build-frontend-all</id>
<phase>prepare-package</phase> <phase>prepare-package</phase>
<goals> <goals>
<goal>npm</goal>
<goal>exec</goal>
</goals> </goals>
<configuration> <configuration>
<arguments>run build</arguments>
<skip>${skip.frontend}</skip>
<executable>node</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<arguments>
<argument>${project.basedir}/build-all.mjs</argument>
</arguments>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- 复制 SDK 构建产物到 Spring Boot 静态资源目录 -->
<!-- 复制 SDK 构建产物到 Spring Boot 静态资源目录(frontend 产物已由 postbuild 脚本复制到 static/) -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
@ -319,76 +321,11 @@
<includes> <includes>
<include>chatbot-sdk.js</include> <include>chatbot-sdk.js</include>
<include>chatbot-sdk.min.js</include> <include>chatbot-sdk.min.js</include>
<include>chatbot-sdk.js.map</include>
<include>chatbot-sdk.min.js.map</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
</configuration> </configuration>
</execution> </execution>
<!-- 复制 Vite 构建产物到 Spring Boot 静态资源目录 -->
<execution>
<id>copy-vite-to-static</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/resources/static</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/frontend/dist</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- ==================== 前端管理后台构建(frontend/ → static/) ==================== -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.1</version>
<configuration>
<workingDirectory>frontend</workingDirectory>
<skip>${skip.frontend}</skip>
</configuration>
<executions>
<!-- 第一步:安装 Node.js(首次自动下载,后续复用缓存) -->
<execution>
<id>install-frontend-node</id>
<phase>prepare-package</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v20.18.0</nodeVersion>
</configuration>
</execution>
<!-- 第二步:npm install 安装依赖 -->
<execution>
<id>install-frontend-npm</id>
<phase>prepare-package</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- 第三步:npm run build(Vite 构建) -->
<execution>
<id>build-frontend-vite</id>
<phase>prepare-package</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions> </executions>
</plugin> </plugin>

7
src/main/resources/static/sdk/chatbot-sdk.js

@ -5060,12 +5060,6 @@ var ChatbotSDK = (function () {
function destroy() { function destroy() {
if (!isInitialized) if (!isInitialized)
return; return;
// 中断正在进行的流式请求,释放网络资源,避免浏览器窗口切换异常
if (abortController) {
abortController.abort();
abortController = null;
}
isSending = false;
if (teaserTimer) { if (teaserTimer) {
clearTimeout(teaserTimer); clearTimeout(teaserTimer);
teaserTimer = null; teaserTimer = null;
@ -5331,4 +5325,3 @@ var ChatbotSDK = (function () {
return ChatbotSDK; return ChatbotSDK;
})(); })();
//# sourceMappingURL=chatbot-sdk.js.map

1
src/main/resources/static/sdk/chatbot-sdk.js.map
File diff suppressed because it is too large
View File

1
src/main/resources/static/sdk/chatbot-sdk.min.js
File diff suppressed because it is too large
View File

1
src/main/resources/static/sdk/chatbot-sdk.min.js.map
File diff suppressed because it is too large
View File

Loading…
Cancel
Save