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

Should it really set NODE_ENV=production? #4

Open
henrik opened this issue Mar 10, 2020 · 1 comment
Open

Should it really set NODE_ENV=production? #4

henrik opened this issue Mar 10, 2020 · 1 comment

Comments

@henrik
Copy link

henrik commented Mar 10, 2020

Thank you so much for this project! Helped me out immensely.

I had some issues deploying to Netlify after adding a plugin, and realised it's because the plugin said to use --save-dev, but Eleventail sets NODE_ENV=production:

environment = { NODE_VERSION = "10.15.3", NODE_ENV = "production" }

It seems the Eleventy convention might be to use dev dependencies, relying on deploys to be NODE_ENV=development.

Just thought I'd

  1. check if there's any particular reason for NODE_ENV=production, to learn
  2. suggest changing it so other noobs like me might avoid problems, if not :)
@kaeside
Copy link

kaeside commented Sep 12, 2020

Hey @henrik ,

I'm new to this as well 😂

I think it is set to production for build purposes. In Eleventail, purging and css optimization is done only when you are running the command netlify build.

I've seen this in a few other 11ty based templates that use Netlify for deployments.

The Netlify toml file contains a production context that will point to the production environment when you are running any command that isn't netlify dev.

Running netlify dev sets the node_env to be development thus overriding the production context.

# netlify.toml

[build]
  command = "npm run build"
  publish = "dist"
  # functions = "./src/functions"

[context.production]
  environment = { NODE_VERSION = "10.15.3", NODE_ENV = "production" }


[dev]
  command = "npm run start"
  framework = "#custom"
  publish = "dist"
  port = 3000
  targetPort = 8181
  NODE_ENV = "development"
  # functionsPort = 34567

[[redirects]]
  from = "/post/*"
  to = "/blog/:splat"

This is done because in the postcss.config.json we're purging the css as well as applying optimizations using cssnano.

Optionally, you could remove the purgecss from the postcss.config.json and place it into tailwind.confg.json as tailwind has purgecss built in.

// postcss.config.json 
module.exports = {
  plugins: [
    require('tailwindcss'),
    require('autoprefixer'),
    ...process.env.NODE_ENV === 'production' ? [purgecss,  require('cssnano')] : []
  ]
};

See here: https://tailwindcss.com/docs/controlling-file-size

In our case the tailwind config would look something like this:

// tailwind.config.js
module.exports = {
  purge: [
    ./src/site/**/*.njk',
  ],
  theme: {},
  variants: {},
  plugins: [],
}

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

No branches or pull requests

2 participants