2021-12-25 10:44:24 -05:00
/ *
2022-06-18 12:40:28 -04:00
* SPDX - FileCopyrightText : 2022 The HedgeDoc developers ( see AUTHORS file )
2021-12-25 10:44:24 -05:00
*
* SPDX - License - Identifier : AGPL - 3.0 - only
* /
2022-06-18 12:40:28 -04:00
//TODO: [mrdrogdrog] The following function and two constants already exist in typescript code.
// However, this file must be a js file and therefore can't access the ts function.
// I have no idea how to resolve this redundancy without extracting it into a node module.
const isPositiveAnswer = ( value ) => {
const lowerValue = value . toLowerCase ( )
return lowerValue === 'yes' || lowerValue === '1' || lowerValue === 'true'
}
const isTestMode = ! ! process . env . NEXT _PUBLIC _TEST _MODE && isPositiveAnswer ( process . env . NEXT _PUBLIC _TEST _MODE )
const isMockMode = ! ! process . env . NEXT _PUBLIC _USE _MOCK _API && isPositiveAnswer ( process . env . NEXT _PUBLIC _USE _MOCK _API )
2021-12-25 10:44:24 -05:00
console . log ( 'Node env is' , process . env . NODE _ENV )
2022-06-18 12:40:28 -04:00
if ( isMockMode ) {
2021-12-25 10:44:24 -05:00
console . log ( 'Uses mock API' )
} else if ( ! ! process . env . NEXT _PUBLIC _BACKEND _BASE _URL ) {
console . log ( 'Backend base url is' , process . env . NEXT _PUBLIC _BACKEND _BASE _URL )
} else {
console . error ( ` ==============
Neither NEXT _PUBLIC _USE _MOCK _API or NEXT _PUBLIC _BACKEND _BASE _URL is set .
If you want to create a production build we suggest that you set a backend url with NEXT _PUBLIC _BACKEND _BASE _URL .
If you want to create a build that uses the mock api then use build : mock instead or set NEXT _PUBLIC _USE _MOCK _API to "true" .
=== === === === == ` )
process . exit ( 1 )
}
2021-12-30 18:05:02 -05:00
if ( ! ! process . env . NEXT _PUBLIC _IGNORE _IFRAME _ORIGIN _CONFIG ) {
2022-06-18 12:40:28 -04:00
console . warn (
'You have set NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG. This flag is ONLY for testing purposes and will decrease the security of the editor if used in production!'
)
}
if ( isTestMode ) {
console . warn ( ` This build runs in test mode. This means:
- no sandboxed iframe
- Additional data - attributes for e2e tests added to DOM ` )
2021-12-30 18:05:02 -05:00
}
2022-06-18 12:40:28 -04:00
if ( ! ! isMockMode ) {
console . warn ( ` This build runs in mock mode. This means:
- No real data . All API responses are mocked
- No persistent data
- No realtime editing
` )
2021-12-25 10:44:24 -05:00
}
const path = require ( 'path' )
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
const withBundleAnalyzer = require ( '@next/bundle-analyzer' ) ( {
enabled : process . env . ANALYZE === 'true'
} )
/** @type {import('next').NextConfig} */
const rawNextConfig = {
webpack : ( config ) => {
config . module . rules . push ( {
test : /\.svg$/i ,
issuer : /\.[jt]sx?$/ ,
use : [
{
loader : '@svgr/webpack' ,
options : {
svgoConfig : {
plugins : [
{
name : 'preset-default' ,
params : {
overrides : {
removeViewBox : false
}
}
}
]
}
}
}
]
} )
2022-07-30 17:32:19 -04:00
const wasmModulePath = path . dirname ( require . resolve ( '@hpcc-js/wasm' ) )
const emojiPickerDataModulePath = path . dirname ( require . resolve ( 'emoji-picker-element-data/en/emojibase/data.json' ) )
2021-12-25 10:44:24 -05:00
config . plugins . push (
new CopyWebpackPlugin ( {
patterns : [
2022-07-30 17:32:19 -04:00
{ from : path . join ( wasmModulePath , 'graphvizlib.wasm' ) , to : 'static/js' } ,
{ from : path . join ( wasmModulePath , 'expatlib.wasm' ) , to : 'static/js' } ,
2021-12-25 10:44:24 -05:00
{
2022-07-30 17:32:19 -04:00
from : emojiPickerDataModulePath ,
2021-12-25 10:44:24 -05:00
to : 'static/js/emoji-data.json'
}
]
} )
)
return config
} ,
2022-05-09 13:12:47 -04:00
reactStrictMode : false ,
2021-12-25 10:44:24 -05:00
redirects : ( ) => {
return Promise . resolve ( [
{
source : '/' ,
destination : '/intro' ,
permanent : true
}
] )
2022-07-31 14:31:33 -04:00
} ,
output : 'standalone' ,
2021-12-25 10:44:24 -05:00
}
const completeNextConfig = withBundleAnalyzer ( rawNextConfig )
module . exports = completeNextConfig