parameter for turning off nextJS compression (#1316)

This commit is contained in:
Thomas Brandého 2023-07-14 00:33:01 +02:00 committed by GitHub
parent bb6be16963
commit c15839da40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 2 deletions

View File

@ -1,3 +1,4 @@
module.exports = {
reactStrictMode: true,
compress: true,
};

View File

@ -203,6 +203,9 @@ class Config(Base):
# Timeout when launching the gunicorn server.
timeout: int = constants.TIMEOUT
# Whether to enable or disable nextJS gzip compression.
next_compression: bool = True
def __init__(self, *args, **kwargs):
"""Initialize the config values.

View File

@ -85,6 +85,8 @@ WEB_ASSETS_DIR = os.path.join(WEB_DIR, "public")
TAILWIND_CONFIG = os.path.join(WEB_DIR, "tailwind.config.js")
# Default Tailwind content paths
TAILWIND_CONTENT = ["./pages/**/*.{js,ts,jsx,tsx}"]
# The NextJS config file
NEXT_CONFIG_FILE = "next.config.js"
# The sitemap config file.
SITEMAP_CONFIG_FILE = os.path.join(WEB_DIR, "next-sitemap.config.js")
# The node modules directory.

View File

@ -207,11 +207,24 @@ def initialize_app_directory(app_name: str, template: constants.Template):
def initialize_web_directory():
"""Initialize the web directory on reflex init."""
console.log("Initializing the web directory.")
path_ops.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.NODE_MODULES))
path_ops.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.PACKAGE_LOCK))
path_ops.cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR)
path_ops.mkdir(constants.WEB_ASSETS_DIR)
# update nextJS config based on rxConfig
next_config_file = os.path.join(constants.WEB_DIR, constants.NEXT_CONFIG_FILE)
with open(next_config_file, "r") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if "compress:" in line:
new_line = line.replace(
"true", "true" if get_config().next_compression else "false"
)
lines[i] = new_line
with open(next_config_file, "w") as file:
file.writelines(lines)
# Write the current version of distributed reflex package to a REFLEX_JSON."""
with open(constants.REFLEX_JSON, "w") as f:
reflex_json = {"version": constants.VERSION}