Skip to content

Commit

Permalink
fix: add compress
Browse files Browse the repository at this point in the history
  • Loading branch information
aboutmydreams committed Jun 29, 2024
1 parent 310f50c commit 82e2cfa
Show file tree
Hide file tree
Showing 3 changed files with 2,886 additions and 36 deletions.
33 changes: 28 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ const withNextra = require('nextra')({

module.exports = withNextra({
i18n: {
locales: ['en', 'zh', 'jp', 'pt', 'tr', 'es', 'it', 'fr', 'kr', 'ca', 'fi', 'ru','de', 'ar'],
locales: ['en', 'zh', 'jp', 'pt', 'tr', 'es', 'it', 'fr', 'kr', 'ca', 'fi', 'ru', 'de', 'ar'],
defaultLocale: 'zh',
},
webpack(config) {
compress: true, // 启用压缩
images: {
// domains: ['example.com'], // 替换为你的图片域名
// deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
// imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
formats: ['image/avif', 'image/webp'],
},
webpack(config, { dev, isServer }) {
const allowedSvgRegex = /components\/icons\/.+\.svg$/

const fileLoaderRule = config.module.rules.find(rule =>
Expand All @@ -21,6 +28,22 @@ module.exports = withNextra({
test: allowedSvgRegex,
use: ['@svgr/webpack']
})
return config
}
})

if (!dev && !isServer) {
// 开启 JavaScript 压缩
config.optimization.minimize = true;

// 添加 CSS 压缩插件
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
config.plugins.push(
new OptimizeCSSAssetsPlugin({})
);
}

return config;
},
// 移除仅在开发时需要的配置
devIndicators: {
buildActivity: false,
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"devDependencies": {
"@types/node": "18.11.10",
"optimize-css-assets-webpack-plugin": "^6.0.1",
"typescript": "^4.9.5"
}
}
Loading

0 comments on commit 82e2cfa

Please sign in to comment.