mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-07 08:39:56 +00:00
misc: Update config for latest next version
Signed-off-by: Avior <github@avior.me>
This commit is contained in:
parent
9351a54552
commit
c5d4ed166a
@ -1,57 +1,49 @@
|
|||||||
import { NextConfig, defaultConfig } from 'next/dist/server/config-shared'
|
import { NextConfig, defaultConfig } from 'next/dist/server/config-shared'
|
||||||
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
|
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
|
||||||
|
import { objectLoop } from '@dzeio/object-util'
|
||||||
// @ts-expect-error next-pre-css has no typing available
|
// @ts-expect-error next-pre-css has no typing available
|
||||||
import preCSS from 'next-pre-css'
|
import preCSS from 'next-pre-css'
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
/**
|
||||||
|
* Hold the lit of additionnal hosts the frontend might connect to
|
||||||
|
*/
|
||||||
|
hosts?: Partial<Record<
|
||||||
|
'style'| 'script' | 'prefetch' | 'img' | 'font',
|
||||||
|
Array<string>
|
||||||
|
>>
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a default NextJS hardened configuration with experimental features enabled and headers preset
|
* Return a default NextJS hardened configuration with experimental features enabled and headers preset
|
||||||
*/
|
*/
|
||||||
export const config = (additionnalHost: string): typeof defaultConfig & NextConfig => ({
|
export const config = (options?: Options): typeof defaultConfig & NextConfig => ({
|
||||||
// Experimentals
|
|
||||||
experimental: {
|
|
||||||
plugins: true,
|
|
||||||
profiling: process.env.NODE_ENV === 'developpment',
|
|
||||||
isrFlushToDisk: true,
|
|
||||||
|
|
||||||
// Bugged
|
|
||||||
// https://github.com/vercel/next.js/issues/18913
|
|
||||||
// reactRoot: true,
|
|
||||||
workerThreads: true,
|
|
||||||
|
|
||||||
pageEnv: true,
|
|
||||||
optimizeImages: true,
|
|
||||||
optimizeCss: true,
|
|
||||||
|
|
||||||
scrollRestoration: true,
|
|
||||||
|
|
||||||
stats: process.env.NODE_ENV === 'developpment',
|
|
||||||
externalDir: true,
|
|
||||||
conformance: true,
|
|
||||||
disableOptimizedLoading: false,
|
|
||||||
gzipSize: process.env.NODE_ENV === 'developpment',
|
|
||||||
craCompat: false,
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
excludeDefaultMomentLocales: true,
|
excludeDefaultMomentLocales: true,
|
||||||
trailingSlash: false,
|
trailingSlash: false,
|
||||||
cleanDistDir: true,
|
cleanDistDir: true,
|
||||||
generateEtags: true,
|
generateEtags: true,
|
||||||
compress: false,
|
compress: false,
|
||||||
// Non experimental config
|
|
||||||
// target: 'serverless',
|
|
||||||
poweredByHeader: false,
|
poweredByHeader: false,
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
|
|
||||||
// Futures
|
crossOrigin: 'anonymous',
|
||||||
future: {
|
swcMinify: true,
|
||||||
strictPostcssConfiguration: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Headers and rewrites
|
// Headers and rewrites
|
||||||
async headers() {
|
async headers() {
|
||||||
|
const hosts = options?.hosts ?? {}
|
||||||
|
|
||||||
|
|
||||||
|
let hostlist: Array<string> = []
|
||||||
|
|
||||||
|
objectLoop(hosts, (it) => {
|
||||||
|
hostlist.push(...it)
|
||||||
|
})
|
||||||
|
|
||||||
|
hostlist = hostlist.filter((it, index, arr) => arr.indexOf(it) === index)
|
||||||
|
|
||||||
// CSS no CSP, x-xss-protection
|
// CSS no CSP, x-xss-protection
|
||||||
const CSP = {
|
const CSP = {
|
||||||
key: 'Content-Security-Policy',
|
key: 'Content-Security-Policy',
|
||||||
@ -62,11 +54,11 @@ export const config = (additionnalHost: string): typeof defaultConfig & NextConf
|
|||||||
"form-action 'self'; " +
|
"form-action 'self'; " +
|
||||||
"manifest-src 'self'; " +
|
"manifest-src 'self'; " +
|
||||||
"prefetch-src 'self'; " +
|
"prefetch-src 'self'; " +
|
||||||
`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${additionnalHost}; ` +
|
`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${hosts?.script?.join(' ')}; ` +
|
||||||
"style-src 'self' 'unsafe-inline'; " +
|
`style-src 'self' 'unsafe-inline' ${hosts?.style?.join(' ')}; ` +
|
||||||
"img-src data: 'self'; " +
|
`img-src data: 'self' ${hosts?.img?.join(' ')}; ` +
|
||||||
"font-src 'self'; " +
|
`font-src 'self' ${hosts?.font?.join(' ')}; ` +
|
||||||
`connect-src 'self' ${additionnalHost}; ` +
|
`connect-src 'self' ${hostlist.join(' ')}; ` +
|
||||||
"base-uri 'self';"
|
"base-uri 'self';"
|
||||||
}
|
}
|
||||||
const XXssProtection = {
|
const XXssProtection = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dzeio/config",
|
"name": "@dzeio/config",
|
||||||
"version": "1.1.6",
|
"version": "1.1.7",
|
||||||
"description": "global configuration files for programming",
|
"description": "global configuration files for programming",
|
||||||
"author": "Avior",
|
"author": "Avior",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -16,7 +16,8 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@typescript-eslint/parser": ">=5.18.0",
|
"@typescript-eslint/parser": ">=5.18.0",
|
||||||
"next": ">=12.1.0",
|
"next": ">=12.1.0",
|
||||||
"next-pre-css": ">=1.0.0"
|
"next-pre-css": ">=1.0.0",
|
||||||
|
"@dzeio/object-util": ">=1.4.2"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"next": {
|
"next": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user