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

Allow custom postcss.config.js #316

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

ahmeij
Copy link
Contributor

@ahmeij ahmeij commented Jan 8, 2024

Allows loading a custom postcss.config.js if it exists in the config folder.

This allows for instance enabling nesting like so:

module.exports = {
  plugins: {
    'postcss-import': {},
    'tailwindcss/nesting': {},
    tailwindcss: {},
    autoprefixer: {},
  },
}

@ahmeij
Copy link
Contributor Author

ahmeij commented Jan 8, 2024

Sorry, this looks like a duplicate of #222, although the approach is a bit different. Please let me know if this is a viable change, I can add documentation if requested.

@ahmeij
Copy link
Contributor Author

ahmeij commented Jan 8, 2024

Added test coverage and updated README as was requested in the other PR.

ahmeij and others added 3 commits January 10, 2024 16:36
Updating test and README for custom postcss.config.js
following the convention used for assembling the overall command
@flavorjones flavorjones force-pushed the feature/allow_custom_postcss_config branch from 28d039e to a30ad61 Compare January 10, 2024 21:44
@flavorjones
Copy link
Member

@ahmeij Thank you for opening this up! It looks good, and I appreciate the test and the documentation.

I made a small change to how the command is assembled, but if this goes green I think we should merge it.

@flavorjones flavorjones mentioned this pull request Jan 10, 2024
@flavorjones flavorjones merged commit ff37f87 into rails:main Jan 10, 2024
23 checks passed
@ahmeij
Copy link
Contributor Author

ahmeij commented Jan 11, 2024

Great, thanks for the fixes and merging this change @flavorjones

@ahmeij ahmeij deleted the feature/allow_custom_postcss_config branch January 11, 2024 14:59
@muriloime
Copy link

nice work @ahmeij ! Is there a way to run it both ways (i.e. with and without postcss) in the same app? I had opened #222 because I need two css builds ( one for emails, without css variables, and another standard tailwindcss one). I was wondering if I can migrate to this cleaner version

many thanks

@ahmeij
Copy link
Contributor Author

ahmeij commented Jan 13, 2024

@muriloime the filenames can be made configurable, they are currently all hardcoded.

I'd suggest a change like this, which would enable running the rake tasks multiple times for multiple files to generate.

      def compile_command(debug: false, input_path: "app/assets/stylesheets/application.tailwind.css", output_path: "app/assets/builds/tailwind.css", config_path: "config/tailwind.config.js", postcss_config_path: "config/postcss.config.js", **kwargs)
        command = [
          executable(**kwargs),
          "-i", Rails.root.join(input_path).to_s,
          "-o", Rails.root.join(output_path).to_s,
          "-c", Rails.root.join(config_path).to_s,
        ]

        command << "--minify" unless (debug || rails_css_compressor?)

        postcss_path = Rails.root.join(postcss_config_path)

However I don't know if this is the direction @flavorjones wants to go with this. If this is ok I can make a PR like this with some tests. I would need to know how to handle the way to long list of kwargs, I think I like the following better:

      def compile_command(debug: false, input_path: nil, output_path: nil, config_path: nil, postcss_config_path: nil, **kwargs)
        command = [
          executable(**kwargs),
          "-i", Rails.root.join(input_path || "app/assets/stylesheets/application.tailwind.css").to_s,
          "-o", Rails.root.join(output_path || "app/assets/builds/tailwind.css").to_s,
          "-c", Rails.root.join(config_path || "config/tailwind.config.js").to_s,
        ]

        command << "--minify" unless (debug || rails_css_compressor?)

        postcss_path = Rails.root.join(postcss_config_path || "config/postcss.config.js")

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.

None yet

3 participants