tailwindcss-rails 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99416d349fce684c991f63dc815098ceaa1db8c8b39b8e96433dddc4c24a8272
4
- data.tar.gz: 21e605c05506a77ac87d499d5c20d4e2beee1ff7782de1cc0ffec97927904452
3
+ metadata.gz: 701b64bd008b24b1c6ab9326bab2ee6969c146a7333c94cf42ddd5dbf97b921d
4
+ data.tar.gz: 10bda805262704aa1b5c636912b230a0b92fa3d36d3e7c3f576948394ca2a970
5
5
  SHA512:
6
- metadata.gz: 5f246a6972ccc630e858692dd4b93b57f57dff0d0d797c9955b058b8f107cbd0a73bde1498145187f7ffe366f14da93be51142a148b30ed4a3d4cd953c9654f3
7
- data.tar.gz: 06c58f56cd53d85309ccc1ef2d080c217d3a56a20af9b6bcaad761bc8dc352ec95765a223670c724f7f9d38ec1358e0e05dc43f12113f06fac269cdf7a9adac1
6
+ metadata.gz: 2607f40c055081e498850564e7651bb5cf5a59045aab9f5b1755ba67f84e54f9c801a47bcf9f989951d9ca622de69e47d98f1c05e4f9b26b47b70e829727e294
7
+ data.tar.gz: 8638603b509534a513367b755088cf19dbaf07493e39c52c9b45ea258b5d28142b82d16e012a649e5979371db7a064126fbe14fb775c3318459f09e230762fea
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [Tailwind CSS](https://tailwindcss.com) is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
4
4
 
5
- Tailwind CSS for Rails makes it easy to use this CSS framework with the asset pipeline. In development mode, the full 3mb+ Tailwind stylsheet is loaded, but in production, only the css classes used by files in `app/views` and `app/helpers` are included.
5
+ Tailwind CSS for Rails works with both the asset pipeline and Webpacker.
6
6
 
7
- This gem just gives access to the standard Tailwind CSS framework. If you need to customize Tailwind, you will need to install it the traditional way using [Webpacker](https://github.com/rails/webpacker) instead. This gem is purely intended for those who wish to use Tailwind CSS with the asset pipeline.
7
+ When use with the asset pipeline, production-mode purging of unused css class names is provided by a Sprockets compressor built into this gem. This compressor ensures that only the css classes used by files in `app/views` and `app/helpers` are included. In development mode, the full 3mb+ Tailwind stylsheet is loaded. In both cases, Tailwind CSS is configured for dark mode, forms, aspect-ratio, typography, and the Inter font. If you need more configuration than that, you'll need to use it with Webpacker.
8
8
 
9
- The version of Tailwind included in this gem has been configured for dark mode, forms, aspect-ratio, typography, and the Inter font.
9
+ When used with Webpacker, Tailwind CSS is installed as a postCSS processor. Refer to the [TailwindCSS documentation](https://tailwindcss.com/docs/installation#customizing-your-configuration) to customize your tailwind.config.js file.
10
10
 
11
11
 
12
12
  ## Installation
@@ -14,15 +14,18 @@ The version of Tailwind included in this gem has been configured for dark mode,
14
14
  1. Run `./bin/bundle add tailwindcss-rails`
15
15
  2. Run `./bin/rails tailwindcss:install` (on a fresh Rails application)
16
16
 
17
- The last option adds the purger compressor to `config/environments/production.rb`. This ensures that when `assets:precompile` is called during deployment that the unused class names are not included in the tailwind output css used by the app. It also adds a `stylesheet_link_tag "tailwind"` and `stylesheet_link_tag "inter-font"` to your `app/views/application.html.erb` file.
17
+ When run on an app using the just the asset pipeline, the last step adds the purger compressor to `config/environments/production.rb`. This ensures that when `assets:precompile` is called during deployment that the unused class names are not included in the tailwind output css used by the app. It also adds a `stylesheet_link_tag "tailwind"` and `stylesheet_link_tag "inter-font"` to your `app/views/application.html.erb` file.
18
18
 
19
19
  You can do these things yourself, if you've changed the default setup.
20
20
 
21
21
  Note: You should ensure to delete `app/assets/stylesheets/scaffold.scss` that Rails adds after running a scaffold command. This stylesheet will interfere with Tailwind's reset of base styles.
22
22
 
23
+ When run on an app using Webpacker, the last step adds the npm dependencies for Tailwind CSS, configures postCSS, and generates a app/javascript/stylesheets/application.scss file as the default for using Tailwind.
24
+
25
+
23
26
  ## Purging in production
24
27
 
25
- The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So this gem includes a Sprockets compressor that purges the tailwind file from all those unused classes.
28
+ The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So this gem includes a Sprockets compressor that purges the tailwind file from all those unused classes when Tailwind CSS for Rails is used with the asset pipeline.
26
29
 
27
30
  This compressor is currently not compatible with the default Sprockets cache system due to the fact its output depends on files outside of Sprockets (all the files observed for utility class name usage), so this cache is disabled in production. If you need to disable it in other deployed environments, add the following to that environment configuration file:
28
31
 
@@ -35,7 +38,7 @@ end
35
38
 
36
39
  ## Configuration
37
40
 
38
- If you need to customize what files are searched for class names, you need to replace the compressor line with something like:
41
+ If you need to customize what files are searched for class names when using the asset pipeline, you need to replace the compressor line with something like:
39
42
 
40
43
  ```ruby
41
44
  config.assets.css_compressor = Tailwindcss::Compressor.new(files_with_class_names: Rails.root.glob("app/somehere/**/*.*"))
@@ -52,4 +55,4 @@ By default, the CSS purger will only operate on the tailwind css file included w
52
55
 
53
56
  Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
54
57
  Tailwind CSS is released under the [MIT License](https://opensource.org/licenses/MIT).
55
- The Inter font is relased under the [SIL Open Font License, Version 1.1](https://github.com/rsms/inter/blob/master/LICENSE.txt).
58
+ The Inter font is relased under the [SIL Open Font License, Version 1.1](https://github.com/rsms/inter/blob/master/LICENSE.txt).
@@ -0,0 +1,3 @@
1
+ @import "tailwindcss/base";
2
+ @import "tailwindcss/components";
3
+ @import "tailwindcss/utilities";
@@ -0,0 +1,24 @@
1
+ LATEST_WEBPACKER = "\"@rails\/webpacker\": \"rails\/webpacker#b6c2180\","
2
+ WEBPACK_STYLESHEETS_PATH = "#{Webpacker.config.source_path}/stylesheets"
3
+ APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
4
+
5
+ # Current webpacker version relies on an older version of PostCSS
6
+ # which the latest TailwindCSS version is not compatible with
7
+ gsub_file("package.json", /\"@rails\/webpacker\".*/) { |matched_line| matched_line = LATEST_WEBPACKER }
8
+
9
+ say "Adding latest Tailwind CSS and postCSS"
10
+ run "yarn add tailwindcss@latest postcss@latest autoprefixer@latest"
11
+ insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "\nrequire(\"stylesheets/application.scss\")\n"
12
+
13
+ say "Adding minimal configuration for Tailwind CSS to work properly"
14
+ directory Pathname.new(__dir__).join("stylesheets"), Webpacker.config.source_path.join("stylesheets")
15
+
16
+ insert_into_file "postcss.config.js", "require('tailwindcss'),\n\t", before: "require('postcss-import')"
17
+
18
+ if APPLICATION_LAYOUT_PATH.exist?
19
+ say "Add Tailwindcss include tags in application layout"
20
+ insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, %(\n <%= stylesheet_pack_tag "application", "data-turbo-track": "reload" %>), before: /\s*<\/head>/
21
+ else
22
+ say "Default application.html.erb is missing!", :red
23
+ say %( Add <%= stylesheet_pack_tag "application", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Tailwindcss
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,18 +1,44 @@
1
1
  namespace :tailwindcss do
2
2
  desc "Install Tailwind CSS into the app"
3
3
  task :install do
4
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/tailwindcss.rb", __dir__)}"
4
+ if defined?(Webpacker::Engine)
5
+ Rake::Task["tailwindcss:install:webpacker"].invoke
6
+ else
7
+ Rake::Task["tailwindcss:install:asset_pipeline"].invoke
8
+ end
9
+ end
10
+
11
+ namespace :install do
12
+ desc "Install Tailwind CSS with the asset pipeline"
13
+ task :asset_pipeline do
14
+ run_install_template "tailwindcss_with_asset_pipeline"
15
+ end
16
+
17
+ desc "Install Tailwind CSS with webpacker"
18
+ task :webpacker do
19
+ run_install_template "tailwindcss_with_webpacker"
20
+ end
5
21
  end
6
22
 
7
23
  desc "Show the list of class names being kept in Tailwind CSS"
8
24
  task :keeping_class_names do
9
- puts Tailwindcss::Purger.extract_class_names_from(Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb"))
25
+ puts Tailwindcss::Purger.extract_class_names_from(default_files_with_class_names)
10
26
  end
11
27
 
12
28
  desc "Show Tailwind CSS styles that are left after purging unused class names"
13
29
  task :preview_purge do
14
- puts Tailwindcss::Purger.purge \
15
- Pathname.new(__FILE__).join("../../../app/assets/stylesheets/tailwind.css").read,
16
- keeping_class_names_from_files: Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb")
30
+ puts Tailwindcss::Purger.purge tailwind_css, keeping_class_names_from_files: default_files_with_class_names
17
31
  end
18
32
  end
33
+
34
+ def run_install_template(path)
35
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
36
+ end
37
+
38
+ def default_files_with_class_names
39
+ Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb")
40
+ end
41
+
42
+ def tailwind_css
43
+ Pathname.new(__FILE__).join("../../../app/assets/stylesheets/tailwind.css").read
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwindcss-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-18 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,7 +51,9 @@ files:
51
51
  - app/assets/fonts/Inter-roman.vietnamese.var.woff2
52
52
  - app/assets/stylesheets/inter-font.css.erb
53
53
  - app/assets/stylesheets/tailwind.css
54
- - lib/install/tailwindcss.rb
54
+ - lib/install/stylesheets/application.scss
55
+ - lib/install/tailwindcss_with_asset_pipeline.rb
56
+ - lib/install/tailwindcss_with_webpacker.rb
55
57
  - lib/tailwindcss-rails.rb
56
58
  - lib/tailwindcss/compressor.rb
57
59
  - lib/tailwindcss/engine.rb