瀏覽代碼

parameter for turning off nextJS compression (#1316)

Thomas Brandého 1 年之前
父節點
當前提交
c15839da40
共有 4 個文件被更改,包括 21 次插入2 次删除
  1. 1 0
      reflex/.templates/web/next.config.js
  2. 3 0
      reflex/config.py
  3. 2 0
      reflex/constants.py
  4. 15 2
      reflex/utils/prerequisites.py

+ 1 - 0
reflex/.templates/web/next.config.js

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

+ 3 - 0
reflex/config.py

@@ -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.
 

+ 2 - 0
reflex/constants.py

@@ -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.

+ 15 - 2
reflex/utils/prerequisites.py

@@ -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}