From befc3594877273128cd006b15c6a4d4ede8cecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Wed, 8 Oct 2025 15:39:46 +0800 Subject: [PATCH] 1 --- webpack.config.js | 63 ++++++++--------------------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 1d2f521..1781633 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -74,84 +74,41 @@ module.exports = { ] }, { - // 图片文件:根据文件类型分类存放 + // 图片文件:全部转为 base64 内联到代码中 test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { - limit: 10000, // 小于 10KB 转为 base64 - name: (resourcePath, resourceQuery) => { - // 根据文件扩展名分类 - const ext = path.extname(resourcePath).toLowerCase() - if (ext === '.svg') { - return 'images/svg/[name].[hash:7][ext]' - } else if (ext === '.png') { - return 'images/png/[name].[hash:7][ext]' - } else if (ext === '.jpg' || ext === '.jpeg') { - return 'images/jpg/[name].[hash:7][ext]' - } else if (ext === '.gif') { - return 'images/gif/[name].[hash:7][ext]' - } - return 'images/[name].[hash:7][ext]' - }, + limit: 999999999, // 所有图片都转为 base64 内联(设置超大限制) esModule: false } }, { - // 字体文件:根据字体类型分类存放 + // 字体文件:全部转为 base64 内联到代码中 test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { - limit: 10000, // 小于 10KB 转为 base64 - name: (resourcePath, resourceQuery) => { - // 根据文件扩展名分类 - const ext = path.extname(resourcePath).toLowerCase() - if (ext === '.woff' || ext === '.woff2') { - return 'fonts/woff/[name].[hash:7][ext]' - } else if (ext === '.ttf') { - return 'fonts/ttf/[name].[hash:7][ext]' - } else if (ext === '.eot') { - return 'fonts/eot/[name].[hash:7][ext]' - } else if (ext === '.otf') { - return 'fonts/otf/[name].[hash:7][ext]' - } - return 'fonts/[name].[hash:7][ext]' - }, + limit: 999999999, // 所有字体都转为 base64 内联 esModule: false } }, { - // 媒体文件:视频和音频 + // 媒体文件:全部转为 base64 内联到代码中 test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, loader: 'url-loader', options: { - limit: 10000, - name: (resourcePath, resourceQuery) => { - const ext = path.extname(resourcePath).toLowerCase() - if (['.mp4', '.webm', '.ogg'].includes(ext)) { - return 'media/video/[name].[hash:7][ext]' - } else if (['.mp3', '.wav', '.flac', '.aac'].includes(ext)) { - return 'media/audio/[name].[hash:7][ext]' - } - return 'media/[name].[hash:7][ext]' - }, + limit: 999999999, // 所有媒体文件都转为 base64 内联 esModule: false } }, { - // JSON 文件 + // JSON 文件:内联到代码中 test: /\.json$/, - type: 'asset/resource', - generator: { - filename: 'data/[name].[hash:7][ext]' - } + type: 'asset/inline' }, { - // 其他资源文件 + // 其他资源文件:内联到代码中 test: /\.(txt|xml|md)$/, - type: 'asset/resource', - generator: { - filename: 'assets/[name].[hash:7][ext]' - } + type: 'asset/inline' } ] },