Конфиг NextJS
next.config.js
Конфиг svgr/webpack + min chunk size:
npm i @svgr/webpack
webpack(config, options) {
config.plugins.push(
new options.webpack.optimize.MinChunkSizePlugin({
minChunkSize: 20000,
}),
);
config.module.rules.push({
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
use: {
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false,
},
],
},
},
},
});
return config;
}
Конфиг images:
images: {
// domains: [],
// domains is deprecated, use remotePatterns
remotePatterns: [
{
protocol: 'https',
hostname: 'domain' // example: 'sources-dev.azzet.com',
},
{
protocol: 'https',
hostname: 'domain' // example: 'sources.azzet.com',
},
]
}
Оптимизация и experimental:
{
swcMinify: true,
compiler: {
removeConsole: process.env.NODE_ENV === 'production'
},
experimental: {
optimizePackageImports: ['@mui/material', '@mui/icons-material'],
},
modularizeImports: {
'@mui/material': {
transform: '@mui/material/{{member}}',
},
'@mui/icons-material': {
transform: '@mui/icons-material/{{member}}',
},
},
poweredByHeader: false
}
Полный конфиг для примера
const conf = {
env: {
version: crypto.randomUUID(),
},
swcMinify: true,
reactStrictMode: false,
compiler: {
removeConsole: process.env.NODE_ENV === 'production',
},
experimental: {
optimizePackageImports: ['@mui/material', '@mui/icons-material'],
},
modularizeImports: {
'@mui/material': {
transform: '@mui/material/{{member}}',
},
'@mui/icons-material': {
transform: '@mui/icons-material/{{member}}',
},
},
poweredByHeader: false,
webpack(config, options) {
config.plugins.push(
new options.webpack.optimize.MinChunkSizePlugin({
minChunkSize: 20000,
}),
);
config.module.rules.push({
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
use: {
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false,
},
],
},
},
},
});
return config;
},
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Expect-CT',
value: 'enforce, max-age=86400',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'X-Download-Options',
value: 'noopen',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'X-Permitted-Cross-Domain-Policies',
value: 'none',
},
{
key: 'X-UA-Compatible',
value: 'IE=edge',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
],
},
{
source: '/(.*).(avif|jpg|jpeg|png|webp|gif|ico|woff2|svg|css|js)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536777, immutable',
},
],
},
];
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'sources-dev.azzet.com',
},
{
protocol: 'https',
hostname: 'sources.azzet.com',
},
],
},
};
module.exports = conf;