Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize CSS when running lektor server with NODE_ENV=production #5

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

dairiki
Copy link
Contributor

@dairiki dairiki commented Aug 9, 2023

Currently, the generated CSS is minimized when running lektor build, but not when running lektor server.

If one publishes their site using the "Publish" button in the Lektor GUI, one publishes un-minimized CSS.

This PR minimizes the CSS in lektor server mode if the $NODE_ENV environment variable is set to "production".


NOTE: This PR is stacked on PR #4. It should be merged after that one. (It may also require rebasing, depending on how #4 is merged.)

@frostming
Copy link
Owner

This PR minimizes the CSS in lektor server mode if the $NODE_ENV environment variable is set to "production".

When will that be set? Can it be set from any tool are must be set by user manually?

@dairiki dairiki force-pushed the feat.minimize-in-server branch from 4cb507d to 1e5a157 Compare November 14, 2023 18:03
@dairiki
Copy link
Contributor Author

dairiki commented Nov 14, 2023

This PR minimizes the CSS in lektor server mode if the $NODE_ENV environment variable is set to "production".

When will that be set? Can it be set from any tool are must be set by user manually?

For lack of better ideas, yes, I was envisioning it being set manually, or in some external way.

E.g. I now use pdm (thank you) to manage my Lektor projects' virtual environments. Configuring a pdm script to run lektor server makes it easy to configure per-script environment variables).


I'm open to alternative ideas for switch modes. Some ideas:

  • Lektor-tailwind could default to production-mode, minimizing the built CSS, unless, say, $LEKTOR_DEV is set. ($LEKTOR_DEV is an environment variable that, when set, turns on hot-reloading and verbose logging in the Lektor dev server.)

  • Instead of keying off an environment variable, we could Lektor's extra_flags (controlled by the --build-flag or -f command-line switch) to control behavior. E.g. lektor server -f production .

@dairiki dairiki marked this pull request as ready for review November 14, 2023 18:07
@frostming
Copy link
Owner

  • Instead of keying off an environment variable, we could Lektor's extra_flags (controlled by the --build-flag or -f command-line switch) to control behavior. E.g. lektor server -f production .

I prefer this method. Let's do it.

@dairiki
Copy link
Contributor Author

dairiki commented Nov 15, 2023

The more I think about this, the more I prefer using $NODE_ENV.
As far as I can tell, its used for exactly this purpose is common in JS-land.

Refs:

Various magics whereby JS transpilers treat NODE_ENV as a compile-type constant, thus removing debug code (upon minimization) from code transpiled with NODE_ENV="production":


Also, I think it would minimize confusion if lektor build and lektor server behaved the same.
So, I suggest:

  • lektor build and lektor server should default to the same behavior (with respect to CSS minimization)
  • lektor build and lektor server should both respond to the same flag or envvar (whatever is decided)

Note that Lektor flags can take an argument, so we could do something like

# minimize CSS
lektor server -f production:true
# or
lektor build -f production:true

# non-mimize CSS
lektor server -f production:false
# or
lektor build -f production:no

(and the default can be whatever we decide...)

@frostming
Copy link
Owner

frostming commented Nov 16, 2023

Also, I think it would minimize confusion if lektor build and lektor server behaved the same.

But it's also a common practice in JS world that commands for different purpose set NODE_ENV to different values. For example, vite dev implies NODE_ENV=development while vite build implies NODE_ENV=production.

lektor server is more a development command to me(starting a dev server like vite dev), so non-minify makes more sense to me.

@frostming frostming merged commit a586857 into frostming:main Nov 18, 2023
8 checks passed
@dairiki
Copy link
Contributor Author

dairiki commented Nov 18, 2023

@frostming Good enough! Thank you!

@dairiki dairiki deleted the feat.minimize-in-server branch November 18, 2023 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants